Answer to Question #260073 in Algorithms for anju

Question #260073

Write algorithm to find maximum element from array and find its best and worst case time complexity.


1
Expert's answer
2021-11-02T14:43:26-0400

Algorithm to find maximum element -

start
arr[]
for (int i = 1; i < n; ++i) {
    if (arr[0] < arr[i]) {
      arr[0] = arr[i];
    }
  }

If the first element will be the largest element, then also loop will run till end of the array to verify.

and if the last element is the largest then also for loop will be executed till the end of the for loop.

So, the worst and best case both will be same that is "O(n)"


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS