Question: Coru;iderthefunctionMinMaxiCint a [ ] , int i , int n , int &min, int &max ) which returns the locations ( in the variables min

Coru;iderthefunctionMinMaxiCint a[], int i, int n, int &min, int &max)
which returns the locations (in the variables min and max) of the smallest element
and the largest element in the array a[i: i+n-i]. Assume that n >1 is a power of
2. Also assume that all elements in a[] are distinct.
MinMaxi(int a[], int i, int n, int &min, int &max){
min=max=i;
for (j=i; j a[j]) min j;
else if (a[max]< a[j]) max j;
}
What are the best-case and the worst-case numbers of element-element comparisoru;
that are executed by MinMaxi?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!