Question: Implement the algorithm into java for finding the kth smallest integer using only one array that contains all the integers. Procedure SELECT(k,S) { if ISI
Implement the algorithm into java for finding the kth smallest integer using only one array that contains all the integers.
Procedure SELECT(k,S)
{ if ISI<50 then { sort S; return the kth smallest element;}
else
{ divide S into ISI/5 sequences of 5 elements each with up
to four leftover elements;
sort each 5-element sequence;
let M be the sequence of the medians of the 5-element sets;
let m= SELECT( M/2, M); // where M/2 indicates the //smallest integer greater than M/2
let S1,S2,and S3 be he sequences of elements in S
less than, equal to, and greater than m, respectively;
if IS1I >=k then return SELECT(k,S1)
else
if (IS1I + IS2I >=k then return m
else return SELECT(k-IS1I-IS2I , S3); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
