Question: Given an array of positive ints a[0..N-1], the pseudocode below will return a list of all of the terms in the sequence that are greater

 Given an array of positive ints a[0..N-1], the pseudocode below will

Given an array of positive ints a[0..N-1], the pseudocode below will return a list of all of the terms in the sequence that are greater than the sum of all preceding terms of the sequence. Nis the length of the array. For example if a = [1,4,6,3,2,201, the returned list is [1,4,6,20] // precondition: a is not null && Na.length total = 0 = [] // L is an empty list while i total append a[i] to L total = total a[i] return L // postcondition: total-a[0] + a[N-1]&& // That is, total is the sum of all array elements and // L contains all the elements in the array that are greater than // the sum of all previous terms of the array Write a loop invariant for the while loop. Show that the loop invariant holds before entering the loop the first time, i.e. show the base case. Use computation induction to prove that the loop invariant holds after each iteration. What is an appropriate decrement function? Show that it decreases at each step. Show that when the decrement function reaches a minimum, the loop is exited

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!