Question: The following algorithm adds all the entries in a square n n array A. Analyze this algorithm where the work unit is the addition operation.

The following algorithm adds all the entries in a square n n array A. Analyze this algorithm where the work unit is the addition operation. sum = 0 for i = 1 to n do for j = 1 to n do sum = sum + A[i, j] end for end for write (Total of all array elements is, sum)

5. Analyze the following algorithm where the work unit is the output statement. Assume that n = 2m for some positive integer m. integer j, k for k = 1 to n do j = n; while j 2 do write j j = j/2 end while end for

5. In one part of algorithm SelectionSort, the index of the maximum item in a list must be found. This requires comparisons between list elements. In an n-element (unsorted) list, how many such comparisons are needed in the worst case to find the maximum element? How many such comparisons are needed in the average case?

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!