Advanced Induction. Drawing hands by Escher. Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1

Similar documents
Strategies for Proofs

CS 220: Discrete Structures and their Applications. Recursive objects and structural induction in zybooks

10/9/17. Using recursion to define objects. CS 220: Discrete Structures and their Applications

COT 3100 Spring 2010 Midterm 2

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

MIDTERM EXAM (HONORS SECTION)

AVL Trees. See Section 19.4of the text, p

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Q1 Q2 Q3 Q4 Q5 Q6 Total

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

Data Structures in Java

15 150: Principles of Functional Programming Sorting Integer Lists

CS70 - Lecture 6. Graphs: Coloring; Special Graphs. 1. Review of L5 2. Planar Five Color Theorem 3. Special Graphs:

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

CSC 1052 Algorithms & Data Structures II: Recursion

Prelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Section 1.4 Proving Conjectures: Deductive Reasoning

Solutions to the Second Midterm Exam

Midterm solutions. n f 3 (n) = 3

(a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are rational they can be written as the ratio of integers a 1

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

ECE 250 Algorithms and Data Structures

Recall our recursive multiply algorithm:

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

by the evening of Tuesday, Feb 6

Solutions to Exam Data structures (X and NV)

COMP Analysis of Algorithms & Data Structures

Problem Set 5 Due: Friday, November 2

ECE 250 Algorithms and Data Structures

MIDTERM EXAMINATION Douglas Wilhelm Harder EIT 4018 x T09:30:00P1H20M Rooms: RCH-103 and RCH-302

CSE 332, Spring 2010, Midterm Examination 30 April 2010

II (Sorting and) Order Statistics

Note that this is a rep invariant! The type system doesn t enforce this but you need it to be true. Should use repok to check in debug version.

Priority Queues Heaps Heapsort

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

Chapter Summary. Mathematical Induction Recursive Definitions Structural Induction Recursive Algorithms

Motivation Computer Information Systems Storage Retrieval Updates. Binary Search Trees. OrderedStructures. Binary Search Tree

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

COMP Analysis of Algorithms & Data Structures

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

CS1800 Discrete Structures Fall 2017 October 25, CS1800 Discrete Structures Midterm Version B

Second Examination Solution

CSC236 Week 5. Larry Zhang

Lamé s Theorem. Strings. Recursively Defined Sets and Structures. Recursively Defined Sets and Structures

To illustrate what is intended the following are three write ups by students. Diagonalization

Mathematical Induction

Final: CSS 342 SAMPLE. Data Structures, Algorithms, and Discrete Mathematics I

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

Analysis of Algorithms

CS61B Lecture #21: Tree Searching. Last modified: Wed Oct 12 19:23: CS61B: Lecture #21 1

Recursive Definitions Structural Induction Recursive Algorithms

CS 315 Data Structures mid-term 2

Multiple-choice (35 pt.)

INSTITUTE OF AERONAUTICAL ENGINEERING

Chapter 6. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

CS 315 Data Structures Spring 2012 Final examination Total Points: 80

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Section 1: True / False (2 points each, 30 pts total)

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CS 310: Tree Rotations and AVL Trees

CSE 214 Computer Science II Searching

Week 5 Tutorial Structural Induction

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

COMP Analysis of Algorithms & Data Structures

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

CS171 Midterm Exam. October 29, Name:

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

BT, BST, AVL. Web Resources page on textbook website:

CSE332 Summer 2010: Midterm Exam Sample Solutions

Reading 8 : Recursion

ECE 250 Data Structures and Algorithms MID-TERM EXAMINATION B /13:30-14:50 MC-4021/RCH-211

Prelim One Solution. CS211 Fall Name. NetID

CSC148 Week 7. Larry Zhang

8/5/10 TODAY'S OUTLINE. Recursion COMP 10 EXPLORING COMPUTER SCIENCE. Revisit search and sorting using recursion. Recursion WHAT DOES THIS CODE DO?

Recursion I and II. Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Midterm 1

CS 380 ALGORITHM DESIGN AND ANALYSIS

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

DIT960 Datastrukturer

Project 1. due date Sunday July 8, 2018, 12:00 noon

Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F].

CS1800 Discrete Structures Fall 2017 October 25, CS1800 Discrete Structures Midterm Version B

Figure 4.1: The evolution of a rooted tree.

ECE G205 Fundamentals of Computer Engineering Fall Exercises in Preparation to the Midterm

Complexity, Induction, and Recurrence Relations. CSE 373 Help Session 4/7/2016

Exam Data structures DAT036/DAT037/DIT960

Sorting Algorithms. CSE21 Winter 2017, Day 2 (B00), Day 1-2 (A00) January 11, 2017

Chapter 12 Supplement: Recursion with Java 1.5. Mr. Dave Clausen La Cañada High School

Binary Search Trees, etc.

Recursively Defined Functions

Computer Science Foundation Exam

Week 2. TA Lab Consulting - See schedule (cs400 home pages) Peer Mentoring available - Friday 8am-12pm, 12:15-1:30pm in 1289CS

Greedy Algorithms Part Three

CISC 320 Midterm Exam

CS 163 Practice Final Exam Winter 2012

Transcription:

Advanced Induction Drawing hands by Escher Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1

Logistics Midterm is done grading but entering into Moodle/tallying/analysis will take longer. You should be able to see your exam tomorrow in discussion sections, but probably won t be able to take it away. Watch for Piazza posts on status/statistics/etc. 2

This class More induction Induction on data structures Lists, trees, graphs, etc. manipulated by algorithms Structural induction Strengthening the hypothesis 3

Strengthenining inductive hypothesis << Problem 3 in HW 7 already illustrates this>> Prove that for any n > 0, 1 + 1/4 + 1/9 +... +1/n 2 < 2 4

5

Another example For all n > 1, prove that the sum of the first n odd numbers is a perfect square. 6

7

Correctness of merge 8

Proving properties of recursive algorithms Think of the program as a recursive definition. Do induction using the recursive definition to prove algorithm correct. Works for any recursive definition (not just algorithms) Structural induction 9

Simple example Let S be the smallest set of integers such that: 3 is in S If x is in S, then x+6 and x 3 both belong to S. Prove that all elements of S are divisible by 3. 10

Lists Recursive definition of lists containing elements in A: <> is a lists(a) If x is in A and L is in lists(a), then x::l is in lists(a). Now consider the following function: Size: Lists(A) N Size(<>) = 0 Size(x::L) = 2+Size(L). Prove that Size(L) is even for any list in L(A). 11

Key idea prove properties about lists using its recursive definition structural induction similar to proving properties by induction over length of lists, heights of trees, etc. but more general as you can do this for any recursively defined structure (trees, doubly linked lists, bst, avl, etc.) recursive algorithms recursive definitions 12

Trees Binary trees over alphabet A as follows: <> is in BT(A) If L, R are in BT(A) and x is in A, then <L, x, R> is in BT(A). Example trees: < < <> a <> > b <<> c <> > > We can prove properties about trees using the above inductive definition. 13

Inserting into a sorted list Recursive algorithm: insert (x,l) { if L=<> then return x::<>; else y:= cons(l); L = cdr(l); if (x <= y) return x::y::l ; else return y::x::l; } Recursive function: insert(x,<>) = x::<>; insert(x,y::l)= x::y::l if x<=y y::x::l otherwise Think of a recursive algorithm as a recursive definition! Apply structural induction to prove properties of the algorithm. Example: if L is sorted then insert(x,l) is sorted. 14

Proof of insert on lists To prove: if L is sorted then insert(x,l) is sorted. Try induction: 15

Proof of insert on lists Strengthen the inductive hypothesis: If L is sorted, then insert(x,l) is sorted and is a keys stored in it is keys(l) U {x}. 16

17

Recap Recursive algms Recursive definitions Prove properties of algorithm by induction using the structure of the recursive definition. However, in practice: writing down the recursive defn explicitly is hard hard for programs that have state however, your proof of the algorithm can follow the recursive style, nevertheless. 18

Correctness of merge Prove correctness of merge using induction! Induction is on number of times merge calls itself. What decreases with each call? Length of L1? Length of L2? 19

20

Correctness of merge-sort 21

22

Correctness of binary search Searching a sorted array A[1..n] binary_search(int A[], int key, int imin, int imax){ if (imax < imin) return 1; else { int imid = midpoint(imin, imax); if (A[imid] > key) return binsearch(a, key, imin, mid 1); elseif (A[imid] < key) binsearch(a, key, imid+1, imax); else return imid; } } 23

24

Searching for a key in a bin search tree Binary search tree: datastructure used to search for elements fast in an ordered set. works best if tree is almost balanced. Key property: For any node n: keys(n.left) key(n) keys(n.right) 25

Searching for a key in a bin search tree find (k, T) { if T=nil return false; else if key(root(t))=k return true; else if k<key(root(t)) return find(k, T.left); else return find(k, T.right); } Prove inductively that find(k,t) return true iff k is stored in T. 26

27

Take away Inductive arguments often require strengthening Properties of recursively defined sets/functions can be proved using induction that follows the structure of the definition. Recursive algorithms can be seen as recursive definitions/functions. Learn how to see that in a recursive algorithm. Prove properties about recursive algorithms using structural induction that implicitly looks at the structure of the recursion in the algorithm. 28