Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the two algorithms for finding the kth smallest integer in a set of integers using only one array that contains all the integers. Test

Implement the two algorithms for finding the kth smallest integer in a set of integers using only one array that contains all the integers. Test your programs and compute the CPU time for different sets of integers generated by a random number generator.

Java preferred.

Algorithm 1:

Procedure SELECT( k,S)

{ if ISI =1 then return the single element in S

else { choose an element a randomly from S;

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);

}

}

Algorithm 2:

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the purpose of forming an advisory board?

Answered: 1 week ago

Question

What roles have these individuals played in your life?

Answered: 1 week ago

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago