home / study / engineering / computer science / computer science questions and a
ID: 3882839 • Letter: H
Question
home / study / engineering / computer science / computer science questions and answers / modify the algorithm to solve the problem of finding the k-th largest number in array a, 1kn, ...
Your question has been answered
Let us know if you got a helpful answer. Rate this answer
Question: Modify the algorithm to solve the problem of finding the k-th largest number in array A, 1k...
Modify the algorithm to solve the problem of finding the k-th largest number in array A, 1kn, 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
Explanation / Answer
Here is the answer -
for (i=0;i<a.length;i++)
for (j=0;j<a.length;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.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.