📊 “How Do You See Time Complexity?”
How do you personally understand and visualize time complexities like O(n), O(n²), or O(log n) when solving problems? Any analogies or examples that really clicked for you?
56 Views

How do you personally understand and visualize time complexities like O(n), O(n²), or O(log n) when solving problems? Any analogies or examples that really clicked for you?
Dry running and looking at the program from the loops point of view helps too.
In most cases( not all), the number of nested for loops can tell you how the complexity is going to be, if it's a single for loop it will be O(n), a single nested for loop, O(n²) and so on.
Also, what you want your program to do?
This question helps too, say you wanted it to search for an element in an array, that would mean that it would have to look at each element once, just checking it with the required element, so you know clearly that you want your program to go through each element once, thus 1 loop, thus worst case complexity would be O(n) where n is basically number of elements in the array