Python list time complexity
Every data structure performs various operations when implementing an algorithm. Some of the key and general operations include iterating over a collection, inserting an item at a point in the collection, deleting, updating or creating a copy of an item or the entire collection. In programming, the choice of the data structure is very important as it affects the performance of the application. This is because the operations of the data structures have different time and space complexities. Space ComplexitySpace Complexity is generally used to refer to the measure of how much space an algorithm takes. It includes both auxiliary space and space used by input. Time ComplexityTime Complexity is the the measure of how long it takes for the algorithm to compute the required operation. Time complexity is measured using the Big-O notation. Run-time Complexity Types (BIG-O Notation Types)
for value in data:
print(value)
Enter fullscreen mode Exit fullscreen mode Example of such operations would be linear search hence the iteration over the list is O(n).
for x in data:
for y in data:
print(x, y)
Enter fullscreen mode Exit fullscreen mode
Big-O notation Summary GraphBest, Average and Worst Cases
Time Complexities of Python Data structures
|