A. Consider a problem to find the student who had the highest GPA for the 2020/2021 academic year.
i. Explain your choice of either a search or a sorting algorithm to solve this problem.
ii. Write the algorithm for your implementation.
B. Consider the analogy of a pile of books on a table. Using a diagram, explain the basic operations involved in adding a book to the pile and removing a book from the pile.
i) We will use searching technique to find the highest scoring student, the searching technique will perform better with respect to the sorting in the linear search with respect to time.
ii) Program implementation.
int sort=0;
int index=-1;
for(int i=0;i<total_record.length;i++)
{
if(sort>total_record[i])
{
sort=total_record[i];
index=i;
}
}
//the last element of the sorted data will be the maximum record.
B)
For the pile of the table, there will two basic operation-
i) push operation ( to add into the pile)
ii) pop operation (to take out from the pile)
Comments
Leave a comment