Question: ( 4 % ) Coru;iderthefunctionMinMaxiCint a [ ] , int i , int n , int &min, int &max ) which returns the locations (
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 ai: ini Assume that n is a power of
Also assume that all elements in a are distinct.
MinMaxiint a int i int n int &min, int &max
minmaxi;
for ji; j aj min j;
else if amax aj max j;
What are the bestcase and the worstcase numbers of elementelement comparisoru;
that are executed by MinMaxi?
b
Consider another function MinMax below:
int i int n int &min, int &max MinMaxint a
min; int mini,
int maxi, max;
int mid;
if n i
min max i;
else if n
if ai aii
min i; max i;
else
min i; max i;
else
MinMaxa i n mini, maxi;
MinMaxa in n min max;
if a mini a min
min mini;
else
min min;
if a maxi a max
max maxi;
else
max max;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
