Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions