in Algorithms retagged by
876 views
0 votes
0 votes

Which algorithm has same average, worst case and best case time ?

  1. Binary search
  2. Maximum of n number
  3. Quick sort
  4. Fibonacci search
in Algorithms retagged by
876 views

1 comment

Binary search has the same worst and average case complexity that is logn
0
0

1 Answer

0 votes
0 votes
The answer should be B because all other methods have different time complexities if we consider their average, best, and worst case.

But in case of finding the maximum of n numbers- (Numbers are stored in an array at random order)

Worst Case: Maximum number is present at the end,

in this case, we have to go through all the elements in the array, so the time taken is to be $O(n)$

Average Case: Maximum number is in the middle,

here in this case too we need to go through all the elements in the array, even though it is in the middle but we do not know about it, so the time taken is to be $O(n)$

Best Case: The maximum number is at the first index.

in this case, too the total time taken is to be $O(n)$.

So the correct answer is  $B$.
edited by
by