Question

Modify the algorithm to solve the problem of finding the k-th largest number in array A


Modify the algorithm to solve the problem of finding the k-th largest number in array A, 1≤k≤n, without sorting the entire array. Partsof the algorithm are given below. Fill in the blanks.

                 Select-k-th-largest(A: Array [1..n] of numbers)

                 1               for _____________________

                 2                                 ________________

                 3                                 for _____________________

                 4                                                   if _______________ then ___________

                 5                                 if position ≠ i then

                 6                                                   temp=A[i]

                 7                                                   A[i]=A[position]

                 8                                                   A[position]=temp

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer -

for (i=0;i

for (j=0;j

if position = i then

  temp = A[i];

if position ≠ i then

temp=A[i]

A[i]=A[position]

A[position]=temp

Kindly rate an upvote!!! Thankyou.

Know the answer?
Add Answer to:
Modify the algorithm to solve the problem of finding the k-th largest number in array A
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT