Data Structures & Algorithms
Space Time Complexity¶
Aim of space time complexity theory is to measure or quantify how much time and space a program or an algorithm takes in execution.
- Given a list has
nelements, - Question : How many comparisons are needed in the worst case to find if a number
xis in a list - Solution we would apply to solve this Query: Go one by one and check each element in the list and compare
- In the worst case we would not have that element in the list and we would transverse the complete list
- Hence we would have to perform
ncomparisons.
Time Complexity for above problem is directly proportional to the length of the list