CSC236H5 Lecture Notes - Lecture 20: If And Only If

14 views2 pages
School
Course
Professor

Document Summary

I"m going to ask you about it. def bin_search(a, x): Pre: a is a list sorted in non-decreasing order. We want to prove that bin_search is correct. Path 1: a has no elements, so x cannot be in a. The correct return value is true if that element equals x, and false otherwise. For path 3 and path 4, we use len(a) as the size of a recursive call. Path 3: to get into this path, we have that len(a) >= 2. Also for this path, x <= a[m]; as a is sorted, x is in a iff x is in a[0m]. Path 4: to get into this path, we have that len(a) >= 2. For m, we have 0 <= m <= len(a) - 1, and so a[m] is a valid access and the recursive call is on a smaller list.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions