Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We have studied the linear time selection algorithm applied on n elements. Assume that all n elements are different. In the algorithm we have studied,
We have studied the linear time selection algorithm applied on n elements.
Assume that all n elements are different.
In the algorithm we have studied, we used group size of
We proved that the number of elements that are guaranteed to be
larger than the median of medians is lower bounded by
Gnn
Similarly, the number of elements that are guaranteed to be
smaller than the median of medians is also lower bounded by Gn
Therefore, the number of elements on either side of the median of medians
after the partition is upper bounded by Un n Gnn
We concluded that the time complexity Tn of the algorithm satisfy the relation
Tn Tn Tn Thetan
This leads to Tn Thetan
Suppose that we use group size instead of what is Gn
Suppose that we use group size instead of what is Un
Suppose that we use group size instead of what is the recurrence relation for Tn
Suppose that we use group size instead of what is the corresponding worstcase running time of the algorithm?
Suppose that we use group size instead of what is Gn
Suppose that we use group size instead of what is Un
Suppose that we use group size instead of what is the recurrence relation for Tn
Suppose that we use group size instead of what is the corresponding worstcase running time of the algorithm?
Analysis of the Algorithm:
For simplicity, assume all n elements in A are distinct.
At least half of the medians found in Step are x
At least half of the n groups except groups, ie the group that has fewer than elements and the group that contains x itself contribute at least elements that are x
Therefore, the number of elements that are greater than x is at least nn
Similarly, the number of elements that are x is at least n
SELECT is called recursively on at most nie n n elements in Step
WorstCase Running Time of SELECTA p r i:
Steps and : On time.
Step consists of On calls of insertion sort on sets with elements each
Tn worstcase running time of SELECT on an array with n elements.
Step: Tn time
Step : Tn time follows from previous considerations
Thus TnTnTnbn
We can ignore the ceiling function and the constant in our analysis.
Tnbn On
SELECT A p r i for finding the ipth smallest element in Apr which is the ipth smallest element of an input array AN Denote npr
Step : Divide the n elements of Apr into n groups of elements each and at most one group made up of the remaining n mod elements.
Step : Find the median of each of the n groups by insertion sorting the at most elements of each group and taking its middle element if the group has an even # of elements, take the lower of the two medians
Step : Use SELECT recursively to find the median x of the n medians found in Step;
Step : Partition Apr around the medianofthemedians x using a modified version of quicksorts PARTITION that takes x as a parameter and uses x as the pivot element. Let q be the index of the median x and kqp
Step : If ik return x Otherwise, use SELECTA p q i to find the ih smallest element on the low side, if ik
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