Question: please do problem 2 Trace the behavior of SortB on the input list 3, 2, 5, 6, 4, 1 by filling in the following table.

 please do problem 2 Trace the behavior of SortB on the

please do problem 2

Trace the behavior of SortB on the input list 3, 2, 5, 6, 4, 1 by filling in the following table. Each row corresponds to the completion of one iteration of the outermost loop. When listing the comparisons done in each iteration, say which two elements are being compared in each comparison (example: 3 vs. 5). The same loop invariant can be used to prove the correctness of both SortA and SortB. State, but do not prove, this invariant. Loop Invariant: After the t^th iteration of the outer loop... Suppose your above loop invariant is true for all values of t greaterthanorequalto 0 (you do not need to include the proof). How can you show SortA is correct based on this loop invariant being true? How can you show SortB is correct based on this loop invariant being true? Consider the following algorithm procedure Loops(n: a positive integer) for i:= 1 to n for j:= i to n for k:= 1 to j print (i, j, k) Write what the algorithm prints when n = 3. How many times does the print routine get called when n = 3? Describe (in words) a rule to decide, if (i_1, j_1, k_1) and (i_2, j_2, k_2) have both been printed for some n, which triplet was printed first. In this problem, we are given a sequence a_1, a_2, .. ., a_n of integers and we want to return a list of all terms in the sequence that are greater than the sum of all previous terms of the sequence. For example, on an input sequence of 1, 4, 6, 3, 2, 20, the output should be the list 1, 4, 6, 20. The following algorithm solves this problem. procedure PartialSums(a_1, a_2, .. ., a_n: a sequence of integers with n greaterthanorequalto 1) total:= 0 Initialize an empty list L

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!