Self-Reference - Induction Cmput 115 - Lecture 7 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this lecture is.

Slides:



Advertisements
Similar presentations
Sorting - Selection Sort Cmput Lecture 10 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is.
Advertisements

Doubly-Linked Lists Cmput Lecture 16 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based.
Ordered Containers Cmput Lecture 21 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based.
Fall 2007CS 2251 Proof by Induction. Fall 2007CS 2252 Proof by Induction There are two forms of induction Standard Induction –Prove the theorem is true.
Container Traversal Cmput Lecture 20 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based.
Proof Techniques and Recursion. Proof Techniques Proof by induction –Step 1: Prove the base case –Step 2: Inductive hypothesis, assume theorem is true.
Stacks Cmput Lecture 18 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based on code from.
Circularly-Linked Lists Cmput Lecture 17 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based.
Sorting - Merge Sort Cmput Lecture 12 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based.
Self-Reference - Recursion Cmput Lecture 6 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this lecture is.
Object (Data and Algorithm) Analysis Cmput Lecture 5 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this.
Recursive Algorithms Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Sorting - Insertion Sort Cmput Lecture 11 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is.
Quick Sort Cmput Lecture 13 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based on code.
Code Clarity - Comments, Preconditions and Postconditions Cmput Lecture 2 Department of Computing Science University of Alberta ©Duane Szafron 1999.
Cmput Lecture 15 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based on code from the book:
Queues Cmput Lecture 19 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based on code from.
The List Interface Cmput Lecture 14 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based.
Discrete Structures Chapter 5: Sequences, Mathematical Induction, and Recursion 5.2 Mathematical Induction I [Mathematical induction is] the standard proof.
CS2420: Lecture 2 Vladimir Kulyukin Computer Science Department Utah State University.
Mathematical Induction Readings on induction. (a) Weiss, Sec. 7.2, page 233 (b) Course slides for lecture and notes recitation. Every criticism from a.
Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.
Algorithm Design and Analysis (ADA)
ICS 253 Presents Mathematical Induction Sultan Almuhammadi muhamadi
MATH 224 – Discrete Mathematics
Reading and Writing Mathematical Proofs
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
CSE373: Data Structures and Algorithms Lecture 2b: Proof by Induction and Powers of Two Nicki Dell Spring 2014.
Copyright © Peter Cappello Mathematical Induction Goals Explain & illustrate construction of proofs of a variety of theorems using mathematical induction.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 4 (Part 3): Mathematical Reasoning, Induction.
Chapter 7 Recursion 1CSCI 3333 Data Structures. 2 Recurrent Sequence A recursively defined sequence – First, certain initial values are specified  c.f.,
CSC201 Analysis and Design of Algorithms Asst.Proof.Dr.Surasak Mungsing Oct-151 Lecture 2: Definition of algorithm and Mathematical.
Methods of Proofs PREDICATE LOGIC The “Quantifiers” and are known as predicate quantifiers. " means for all and means there exists. Example 1: If we.
Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.
Computer Science School of Computing Clemson University Discrete Math and Reasoning about Software Correctness Joseph E. Hollingsworth
Ordered Containers CMPUT Lecture 19 Department of Computing Science University of Alberta ©Duane Szafron 2003 Some code in this lecture is based.
9.4 Mathematical Induction
Mathematical Induction I Lecture 4: Sep 16. This Lecture Last time we have discussed different proof techniques. This time we will focus on probably the.
Recursion. What is recursion? Rules of recursion Mathematical induction The Fibonacci sequence Summary Outline.
Lecture 4,5 Mathematical Induction and Fibonacci Sequences.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
1 CompSci 105 SS 2005 Principles of Computer Science Lecture 6: Recursion Lecturer: Santokh Singh Assignment 1 due tomorrow. Should have started working.
October 3, 2001CSE 373, Autumn Mathematical Background Exponents X A X B = X A+B X A / X B = X A-B (X A ) B = X AB X N +X N = 2X N 2 N +2 N = 2 N+1.
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction Linda Shapiro Winter 2015.
Slide Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Types of Proof Lecture 4 Sections 0.4 Wed, Aug 29, 2007.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
1 2/21/2016 MATH 224 – Discrete Mathematics Sequences and Sums A sequence of the form ar 0, ar 1, ar 2, ar 3, ar 4, …, ar n, is called a geometric sequence.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Mathematical Induction I Lecture 5: Sep 20 (chapter of the textbook and chapter of the course notes)
Mathematical Induction Thinking Skill: Develop Confidence in Reason Warm Up: Find the k+1 term (P k+1 ) 1) 2)
Section 2.3 Mathematical Induction. First Example Investigate the sum of the first n positive odd integers. 1= ____ 1 + 3= ____ = ____
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Mathematical Induction Prudence Wong
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
INDUCTION David Kauchak CS52 – Spring to-1 multiplexer control control_negate and_out1 input0 input1 and_out2 output.
11.7 – Proof by Mathematical Induction
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
Use mathematical induction to prove that the formula is true for all natural numbers m. {image} Choose the first step of the proof from the following:
CS 3343: Analysis of Algorithms
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction
Applied Discrete Mathematics Week 9: Integer Properties
Mathematical Induction
This Lecture Substitution model
Mathematical Induction
Lecture 3.1: Mathematical Induction
Mathematical Induction II
Introduction to Proofs
11.4 Mathematical Induction
Presentation transcript:

Self-Reference - Induction Cmput Lecture 7 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this lecture is based on code from the book: Java Structures by Duane A. Bailey or the companion structure package Revised 1/3/00

©Duane Szafron About This Lecture In this lecture we will learn about a kind of self-reference called mathematical induction. We will use it to prove analytic formulas and to prove that segments of programs are correct. Cmput 272 covers this topic in much more depth.

©Duane Szafron Outline Mathematical induction A template for induction proofs An inductive proof of a formula An inductive proof of method correctness

©Duane Szafron Mathematical Induction Self-reference occurs when the proof of a theorem relies on the application of the same theorem to a simpler case. This situation is called mathematical induction. For example, we could use mathematical induction to prove that:  n i=0 i = n(n+1)/2 We used this result in the average case complexity analysis of a linear search.

©Duane Szafron A Template for Induction Proofs Begin the proof with: “We will prove this result using induction on the problem size, n.” This informs the reader of your approach. Directly prove the necessary base cases. Keep the number of cases small and the proofs simple. State the assumption that the result holds for all values from the base case, up to but not including the n th case. Prove the n th case from simpler cases. State that by mathematical induction on n, the result is true for all n larger than or equal to the base cases. template from Bailey ch. 4

©Duane Szafron An Inductive Proof Prove that: ∑ n i=0 2 i = 2 n for all n >= 0. We will prove this result using induction on the problem size, n. Basis Step: If n = 0 then [lhs]  n i=0 2 i =  0 i=0 2 i = 2 0 = 1. However, in this case, [rhs] 2 n = = = = 1 as well, so the base case holds for n = 0.

©Duane Szafron An Inductive Proof Assume that the result holds for all values from the base case, n = 0, up to but not including the n th case. Inductive Step: The n th case holds since:  n i=0 2 i = (  n-1 i=0 2 i ) + 2 n = 2 (n-1) n = 2 n n = 2 n + 2 n - 1 = 2* 2 n - 1 = 2 n By mathematical induction on n, the result is true for all n larger than or equal to the base case, n = 0.

©Duane Szafron An Inductive Proof Assume that the result holds for all values from the base case, n = 0, up to and including the n th case. Inductive Step: The n+1 th case holds since:  n+1 i=0 2 i = (  n =0 2 i ) + 2 n+1 = 2 n n+1 = 2*2 n = 2 n By mathematical induction on n, the result is true for all n larger than or equal to the base case, n = 0.

©Duane Szafron Proving Program Correctness Mathematical induction can also be used to prove that a program segment is correct. For example, we can use induction to prove that this recursive method is correct: public static int sum(int n) // post: return the sum of ints from 1 to the given value if (n < 1) return 0;// 1 else return// 2 sum(// 3 n - 1// 4 ) + n;// 5 } code from Bailey pg. 66

©Duane Szafron A Program Correctness Proof We will prove this result using induction on the problem size, n. Basis: If n = 0 then the condition in the if statement of line 1 is true so the method returns 0 which is correct. Assume that the method is correct for all values from the base case 0, up to but not including the n th case. proof from Bailey ch. 4

©Duane Szafron A Program Correctness Proof Inductive Step: Consider a method call for n > 0. The condition in the if statement of line 1 is false so the else clause starting at line 2 is run. Line 4 constructs the argument n-1 which is less than n. Therefore, our assumption says that the method call on line 3 returns the correct answer: the sum of values from 0 to n- 1. Line 5 adds the value n to this result which gives the correct answer. proof from Bailey ch. 4

©Duane Szafron A Program Correctness Proof Therefore, by induction on n, the method computes the correct answer for all n larger than or equal to the base case, 0. proof from Bailey ch. 4