Question: Given the following algorithm for finding the two largest integers in an array A[1..n] of n distinct positive integers. Base on the number of

Given the following algorithm for finding the two largest integers in an

 

Given the following algorithm for finding the two largest integers in an array A[1..n] of n distinct positive integers. Base on the number of comparisons between elements in A, compute T(n) and Tw(n). You must justify your answer and show your work clearly for credit. if A[1] > A[2] then largest = A[1]; s_largest = A[2] // Initialization else largest = A[2]; s_largest = A[1] endif; for i=3 to n do if A[i]s largest then if A[i]>largest // Checking A[3], ..., [n] // A[i] is one of the two largest integers // A[i] is the current largest integer then s largest = largest; largest = A[i] else s_largest = A[i] endif endif endfor;

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 Programming Questions!