Question: Implement the two algorithms we discussed in class for solving the problem of finding the three/k largest numbers in an input array of integers. The

Implement the two algorithms we discussed in class for solving the 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..k1] a[0..k1]; // You may use a loop to do this for(int i=k; 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!