Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2) In parts a and b, for full credit, your algorithm must be as efficient as pos

ID: 3530583 • Letter: 2

Question

2) In parts a and b, for full credit, your algorithm must be as efficient as possible. You may use already known algorithms as subroutines in your algorithm.----- a)Write a program (C, C++, pseudocode etc.) that will take as input an array of size n of unsorted numbers and print out the k largest numbers in the array in sorted order.---- b) Same question but now imagine that the n numbers of question (a) are given to you one at a time and you do not have space to store them all. There is only O(k) space available altogether. Design an efficient algorithm to solve this modified problem. What is the running time of your algorithm?---

Explanation / Answer

#include <iostream>


using namespace std;


int main()

{

int array[500];

int temp = 0;

int n;

cout<<"enter n";

cin>>n;

cout<<"enter numbers"<<endl;

for(i=0;i<n;i++)

cin>>array[i];

for(int i=0;i<n;i++)

{

if(array[i]>temp)

temp=array[i];

}

cout << "The biggest number is: " << temp << endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote