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;
PayPal Gateway not configured
PayPal Gateway not configured