'worst case of time complexity

WHY WE ALWAYS CONSIDER THE WORST CASE SCENARIO IN TIME COMPLEXITY FOR EXAMPLE TIME COMPLEXITY OF LINEAR SEARCH IS N AND FOR THE BINARY SEARCH IS log(n). SO THESE ARE THE WORST CASE SCENARIO.... SO WHY WE CONSIDER THIS WHY NOT BEST OR AVERAGE CASE SCENARIO



Solution 1:[1]

The reason we consider the worst case scenario is to rate the efficiency of the algorithm, think of it like the maximum cost you will incur when you run it on different inputs, In large scale applications where the performance is very important with varying inputs the maximum time taken will be determined only by worst case as we can never be sure if the user input is a best case or average case, but we can be sure that it won't be worse than the worst case.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman