Time Complexity
Time Complexity
1. O Notation
2. Ω Notation
3. θ Notation
Big oh Notation , O
The systematic way to express the upper limit of an
algorithm's running time is to use the Big-O notation O(n). it
calculate the worst-case time complexity, or the maximum
time an algorithm will take to complete execution.
3. Analyze Loops:
-> Single Loop: A loop running from 1 to n has a time
complexity of O(n).
->Nested Loops: If one loop runs n times, and inside it,
another loop runs n times, the total time complexity is O(n^2).
4.Analyze Recursion:
-> Recurrence relations can help in determining
time complexity for recursive algorithms.
-> Example: A function that calls itself twice
for each value of n has a complexity of O(2^n).
Time Complexity: O(n^2) because the outer loop runs n times, and
for each iteration of the outer loop, the inner loop runs n times.
Space complexity
Examples:
-> Space needed for storing constants like numbers or fixed-size
arrays.
Examples:
-> Space needed for dynamic data structures like linked lists,
trees, or graphs, which grow with the input size.
-> Memory used for the recursion stack during recursive function
calls.