Question: Problem 3 ( Finding Max & 2 nd - Max using D&C ) . In this problem, you are given a partial pseudocode for the
Problem Finding Max & ndMax using D&C
In this problem, you are given a partial pseudocode for the problem of finding the maximum and
secondmaximum in an array of distinct integers. Note that the naive algorithm solves this in
comparisons. We will assume that is a power of dots Your goal is to fill
in the blanks so that the code works correctly, and then answer questions regarding the number of
comparisons it makes. We are only interested in comparisons between array elements; so checking
if length is is not a comparison we are counting.
procedure MAXANDNDMAX :
Returns tuple with first entry max and second entry nd max of
Assumes the list has distinct integers for some integer
if len then:
return
else:
Pair the elements and so on
For every element einA, dictionary partner returns the element is paired with.
Blarr empty list.
Compare and partner for every einA, and append the larger element to
You count the epartner comparison only once. For instance, is s partner
and viceversa. But you don't compare their comparison twice.
:
MAXANDNDMAX
return
a Fill the blanks in Line and in Line points
b Fill the blanks in Line and Line such that the algorithm works correctly. points
Let be the number of comparisons made when the above algorithm is passed a list of
distinct numbers. Note, all other operations are immaterial for
Clearly write the recurrence inequality governing Write the base case and be exact: do not
use the bigOh notation. Using the kitty method, solve the recurrence exactly for for some
positive integer We are interested in the exact answer as a function of so express care.
points
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
