Analysis of Algorithm
Analysis of Algorithm
Topperworld.in
Analysis of Algorithm
©Topperworld
Design and Analysis of Algorithm
Now suppose, the number you are searching for is present at the very
beginning index of the array. In that case, your algorithm will take O(1) time
to find the number in the best case. So, the best case complexity for this
algorithm becomes O(1), and you will get your output in a constant time.
©Topperworld
Design and Analysis of Algorithm
• In simple words, it states that any program will need maximum that
time (less than or equal to) to run.
For example, suppose we have an algorithm that has the worst-case time
complexity is O(N ^2), then we can say that the program will take a maximum
of O(N ^2 ) time to run, for an input of size N it can never take more time than
that to run.
The worst-case time or space complexity is often represented in terms of the
Big Oh (O) notation.
In this example, the target element is 10, which is located at the end of the
array. The linear search function has to iterate through the entire array before
finding the target at the last index. This scenario represents the worst-case
time complexity of a linear search algorithm, which is O(n), where n is the
length of the array.
©Topperworld
Design and Analysis of Algorithm
©Topperworld
Design and Analysis of Algorithm
©Topperworld