Question: Hi, im learning program correctness and I just wanted to double check my answer. For pre condition: A is list containing integers and can't be

 Hi, im learning program correctness and I just wanted to double

Hi, im learning program correctness and I just wanted to double check my answer. For pre condition: A is list containing integers and can't be empty set. Post condition: returns the smallest number in A.

For program correctenss,

path 1: terminates at line 3. If len(a) is 1, then there is only 1 element in A and therefore it is the smallest number. Post holds.

Path 2: terminates at line 8. To get to this path, len(a) >=1. So, m is a number and holds. For the 2 recurrences, the size of the list is len(a)//2 so each recursive call decreases. pre conditions are satisfied because the lists are not empty and contain numbers. So when call completes it returns the smallest number from the two lists.

Exercises 1. Here is some code that recursively determines the smallest element of a list. Give pre- and postconditions for this function, then prove it is correct according to your specifications. 1 def recmin(A) 2 if len(A)1: 3 return AIe 4 else: 5len(A)2 7 min2 recmin (A[m..len (A)-11) return min(minl, min2) Exercises 1. Here is some code that recursively determines the smallest element of a list. Give pre- and postconditions for this function, then prove it is correct according to your specifications. 1 def recmin(A) 2 if len(A)1: 3 return AIe 4 else: 5len(A)2 7 min2 recmin (A[m..len (A)-11) return min(minl, min2)

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!