Question: Prove that the following program is correct with respect to its given specification. # Pre: w is a nonempty sequence of positive integers; It
Prove that the following program is correct with respect to its given specification. # Pre: w is a nonempty sequence of positive integers; It is a positive integer. # Post: Return True if w has a subsequence v such that sum(v)=t; Return False otherwise. SubseqSum(w, t): == t: 1. if w[0] return True 2. if len(w) == 1: return False 3. y = w[1:] #y is w with its first element removed 4. if SubseqSum(y, t): return True 5. if w[0] > t: return False 6. else: return SubseqSum(y, t - w[0])
Step by Step Solution
3.40 Rating (156 Votes )
There are 3 Steps involved in it
To prove the correctness of the given program lets analyze the provided function SubseqSum and verify that it meets its specification The specificatio... View full answer
Get step-by-step solutions from verified subject matter experts
