779 views

2 Answers

2 votes
2 votes
Take 3 temporary elements ...

Max1 , max2, max3

Now make 0th element  as max1 check with all elements when when max1 changes put previous value of max1 into max2 ...

Now second time max1 changes that means new greater element has been found...

Puprevious max1 into max 2 and previous max2 value into max3...

Now this process repeated till the end of array...

Which take O(n) time...
0 votes
0 votes
Answer will be C)

The list is not sorted.

So to get max. of any 3 numbers we need 2 comparison.

Now, to get max. of n numbers we need 2n/3 comparison.

So, total maximum comparison O(n)
edited by

No related questions found