Course Solutions Uncategorized (Solved) : Implement Two Algorithms Discussed Class Solving Problem Finding Three K Largest Numbers I Q26570582 . . . .

(Solved) : Implement Two Algorithms Discussed Class Solving Problem Finding Three K Largest Numbers I Q26570582 . . . .

 

Implement the two algorithms we discussed in class for solvingthe problem of
finding the three/k largest numbers in an input array of integers.The pseudocode of the
two algorithms are given below. (Should be in C++)

int[] findkLargest(int[] a, int k){
n ← length[a];
if (k<0 or k> n)
output “Invalid k” and return;
if (k<=n)
return a;
int[] largest[0..k‐1] ← a[0..k‐1]; // You may use a loop to dothis
for(int i=k; i<n; i++){
j ← index of the minimal number in largest; // You may use a loopto do this
if (a[i] > largest[j])
largest[j] ← a[i];
}
return largest;
}
  

int[] find3Largest(int[] a){
n ← length[a];
if (n<=3)
return a;
sum ← a[0]+a[1]+a[2];
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
for(int k=j+1;

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

(Solved) : 41 Solve Recurrence Relation T N 2t N 2 Nlgn T N Ign B T N Ng Q35717978 . . . .(Solved) : 41 Solve Recurrence Relation T N 2t N 2 Nlgn T N Ign B T N Ng Q35717978 . . . .

<p dir="ltr"><img src="https://media.cheggcdn.com/media%2F9b3%2F9b32d476-b584-4dc5-a9e4-6835e7cdba15%2Fimage.png" alt="41. Solve the recurrence relation T(n 2T(n/2)+nlgn a) T(n) (Ign) b) T(n)-(ng)" aria-describedby="d3f"/></p><p dir="ltr"/>41. Solve the recurrence relation T(n 2T(n/2)+nlgn a) T(n) (Ign) b) T(n)-(ng') Show transcribed