***Welcome to ashrafedu.blogspot.com * * * This website is maintained by ASHRAF***

Wednesday 20 November 2019

Time complexity and Space complexity


Time complexity:

In computer science, the time complexity is the measure or estimate of time taken for running an algorithm.

Time complexity is commonly estimated by counting the number of elementary operations performed by the algorithm, supposing that an elementary operation takes a fixed amount of time to perform. Thus, the amount of time taken and the number of elementary operations performed by the algorithm differ by at most a constant factor.

An algorithm's running time may vary with different inputs of the same size, commonly the worst-case time complexity, is considered which is the maximum amount of time taken on inputs of a given size. 
The average-case complexity, which is the average of the time taken on inputs of a given size which is commonly considered..

Space complexity:


When an algorithm is designed to solve a problem, it needs computer memory to complete its execution .

For any algorithm memory is required for the following purpose
·         Memory required to store program instructions.
·         Memory required to store constant values.
·         Memory required to store variable values. And few other things.

Space complexity of an algorithm can be defined as follows

Total amount of computer memory required by an algorithm to complete its execution is called as space complexity of that algorithm


No comments:

Post a Comment