Notes
Notes
other?
It helps us analyze how efficient our code is, both in terms of how long it
grows.
Space Complexity measures the amount of memory an algorithm uses as
needed to store the input and any additional memory required during the
Both time and space complexities are crucial because they help us
Calculating Complexity
To calculate complexity, we typically use the following steps:
1. Identify the input size: Determine the parameter that affects
the algorithm's performance the most (e.g., array size, number
of nodes).
2. Count the operations: Calculate the number of operations
performed in terms of the input size.
3. Simplify the expression: Remove lower-order terms and ignore
constants.
The dominant term here is n^2, so we say that the algorithm has a
Thus, the time complexity is O(n), meaning it scales linearly with the
input size.
● The space used by the algorithm consists of the input array and
a few integer variables.
● The space for the input array is O(n).
● The space for the variables is O(1) (constant space).
Asymptotic Notation
Asymptotic notation provides a way to describe the complexity of an
algorithm in terms of its behavior as the input size grows. The three
array:
Since Big O focuses on the worst case, the time complexity of linear
search is O(n).
2. Omega Notation (Ω)
complexity. It provides both the upper and lower bounds, showing the
average-case scenario.
For linear search, if we consider the average case where the target is
Subscribe
Common Runtimes
The running time doubles with each additional element in the input,