1.6ANALYZING AN ALGORITHM
An algorithm can be analyzed by two factors: space and time. We should develop an algorithm that makes the best use of both these resources. Analyzing an algorithm measures the efficiency of the algorithm. The efficiency of the algorithm is measured in terms of the speed and time complexity. The complexity of an algorithm is a function that measures the space and time used by an algorithm in terms of input size.
Time Complexity–The time complexity of an algorithm is the amount of time taken by an algorithm to run the program completely. It is the runtime of the program. The time complexity of an algorithm depends upon the input size. The time complexity is commonly represented by using big O notation. For example, the time complexity of a linear search is O (n).
Space Complexity–The space complexity of an algorithm is the amount of memory space required to run the program completely. The space complexity of an algorithm depends upon the input...