327 views

1 Answer

1 votes
1 votes

The algorithm works as:

A[n] // Given an array of size n

Max = Min = A[0]

for i=2 to n

if A[i]>Max    Max=A[i]

else if A[i]<=Min  Min=A[i]

Best Case : If elements are sorted in increasing order  n-1 comparisons

Worst Case : If elements are sorted in decreasing order 2(n-1) comparisons

Average Case :  if half of array contains elements greater than max 1.5n-2 comparisons

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
2
Anuranjan asked Mar 17, 2019
243 views
How to improve cache hit rate in case of transfer of element from 2-D array to matrix.? (Consider the column major order in 2D array)
1 votes
1 votes
1 answer
3
DIYA BASU asked Feb 3, 2019
316 views
Main memory=512 words.block size=8 words.cache size =32 wordsThere is an array A[100] and each element is 4 words then what is the hit ratio for the following loop.for...
0 votes
0 votes
1 answer
4
bunty choudhary asked Dec 16, 2018
294 views
if array declared size is larger than values initialised. Then what value rest memory elements have , 0 or garbage?