Answered step by step
Verified Expert Solution
Question
1 Approved Answer
( 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started