Mathematical Induction II

Slides:



Advertisements
Similar presentations
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Advertisements

Induction and recursion
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 4 Comparison-based sorting Why sorting? Formal analysis of Quick-Sort Comparison.
1 Intro to Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
Induction and recursion
Discrete Mathematics, 1st Edition Kevin Ferland
Mathematical Induction. F(1) = 1; F(n+1) = F(n) + (2n+1) for n≥ F(n) n F(n) =n 2 for all n ≥ 1 Prove it!
1 Introduction to Abstract Mathematics Chapter 4: Sequences and Mathematical Induction Instructor: Hayk Melikya 4.1- Sequences. 4.2,
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
CompSci 102 Discrete Math for Computer Science March 1, 2012 Prof. Rodger Slides modified from Rosen.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
1 INFO 2950 Prof. Carla Gomes Module Induction Rosen, Chapter 4.
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.
Inductive Proofs and Inductive Definitions Jim Skon.
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
Mathematical Induction
Chapter 5. Section 5.1 Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach a particular.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Mathematical Induction I Lecture 19 Section 4.2 Mon, Feb 14, 2005.
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
1 Mathematical Induction An inductive proof has three parts: –Basis case –Inductive hypothesis –Inductive step Related to recursive programming.
Hubert Chan (Chapters 1.6, 1.7, 4.1)
(Proof By) Induction Recursion
Chapter 4: Induction and Recursion
Decision Trees DEFINITION: DECISION TREE A decision tree is a tree in which the internal nodes represent actions, the arcs represent outcomes of an action,
CSE15 Discrete Mathematics 03/22/17
CPSC 121: Models of Computation 2008/9 Winter Term 2
Modeling with Recurrence Relations
Prüfer code algorithm Algorithm (Prüfer code)
Binary Search Trees A binary search tree is a binary tree
CS2210:0001Discrete Structures Induction and Recursion
Induction and recursion
Induction and Recursion
Lecture 18. Basics and types of Trees
Hubert Chan (Chapters 1.6, 1.7, 4.1)
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:
Discrete Structures for Computer Science
Chapter 5 Induction and Recursion
Trees 4 The B-Tree Section 4.7
Orthogonal Range Searching and Kd-Trees
Proofs, Recursion and Analysis of Algorithms
COUNTING AND PROBABILITY
Discrete Mathematics for Computer Science
Computational Geometry Capter:1-2.1
Notes 9.5 – Mathematical Induction
Induction and recursion
Counting I: One-To-One Correspondence and Choice Trees
Data Structures Review Session
Lectures on Graph Algorithms: searching, testing and sorting
Mathematical Induction I
Applied Discrete Mathematics Week 9: Integer Properties
Lecture 18 Section 4.1 Thu, Feb 10, 2005
Mathematical Induction
1A Recursively Defined Functions
Chapter 7 Quicksort.
Induction Chapter
Advanced Analysis of Algorithms
Chapter 11: Further Topics in Algebra
Copyright © Cengage Learning. All rights reserved.
Mathematical Induction
Discrete Mathematics for Computer Science
Mathematical Induction
2-1 Use Inductive Reasoning
Mathematical Induction II
Copyright © Cengage Learning. All rights reserved.
Presentation transcript:

Mathematical Induction II Lecture 21 Section 4.3 Thu, Feb 17, 2005

Example: Binary Search Trees In a complete binary search tree of depth n - 1, (n rows) what is the average number of comparisons required to locate an element? (Assuming all positions are equally likely.) Analysis Elements in row 1 require 1 comparison. Elements in row 2 require 2 comparisons. Elements in row 3 require 3 comparisons. In general, elements in row k require k comparisons.

Example: Binary Search Trees Further analysis Row 1 contains 1 element. Row 2 contains 2 elements. Row 3 contains 4 elements. In general, row k contains 2k - 1 elements. Fact The average number of comparisons is the total number of comparisons required for all elements divided by the number of elements.

Example: Binary Search Trees The total number of elements is 1 + 2 + 4 + 8 + … + 2n – 1. The total number of comparisons is 11 + 22 + 34 + 48 + … + n2n – 1. Therefore, the average is (11 + 22 + … + n2n – 1)/(1 + 2 + … + 2n – 1) Yuck!

Example: Binary Search Trees Prove by mathematical induction that 1 + 2 + 4 + 8 + … + 2n – 1 = 2n – 1. 11 + 22 + 34 + 48 + … + n2n – 1 = (n – 1)2n + 1. Then, the average is [(n – 1)2n + 1]/(2n – 1). This is approximately equal to n – 1 (for large n).

Binary Search Trees In reality, it often requires two comparisons at each node. Is the value less than the node? If not, is the value greater than the node? If not, then the value equals the node. In other words, we must make a three-way decision at each node.

Binary Search Trees So, exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60

Binary Search Trees So, exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2 2

Binary Search Trees So, exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2 2 1 2 3

Binary Search Trees So, exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2 2 1 2 3 4 5

Binary Search Trees So, exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2 2 1 2 1 2 3 4 4 5

Binary Search Trees So, exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2 2 1 2 1 2 3 4 4 5 5 6

Binary Search Trees It takes an average of 1.5 comparisons to move down one level. Then it takes 2 comparisons to match a value at that level. Level 1: 2 comparisons. Level 2: 1.5 + 2 = 3.5 comparisons. Level 3: 2(1.5) + 2 = 5 comparisons. Level n: (n – 1)(1.5) + 2 = 1.5n + 0.5.

Binary Search Trees To find the average, we must compute 12 + 23.5 + 45 + … + 2n – 1(1.5n + 0.5). We could work this our from scratch… Or use what we have already worked out:  2n – 1(1.5n + 0.5) = (1.5  2n – 1n) + (0.5  2n – 1) = (1.5((n – 1)2n + 1)) + (0.5(2n – 1)) = (1.5n – 1)2n + 1.

Binary Search Trees Therefore, the average is ((1.5n – 1)2n + 1)/(2n – 1). For large n, this is approximately 1.5n – 1.

Binary Search Trees What if we changed the order in which we did the comparisons at each node? Is the value equal to the node? If not, is the value less than the node? If not, then the value is greater than the node. Will that be more or less efficient than the previous order?

Binary Search Trees Exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60

Binary Search Trees Exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2

Binary Search Trees Exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2 3

Binary Search Trees Exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2 5 3

Binary Search Trees Exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2 5 3

Binary Search Trees Exactly how many comparisons does it take to locate an element? 40 20 70 50 30 10 60 1 2 5 3

Binary Search Trees To find the average, we must compute 11 + 23 + 45 + … + 2n – 1(2n – 1). Again, we can use what we have already worked out:  2n – 1(2n – 1) = (2  2n – 1n) – ( 2n – 1) = (2((n – 1)2n + 1)) – (2n – 1) = (2n – 3)2n + 3

Binary Search Trees Therefore, the average is ((2n – 3)2n + 3)/(2n – 1). For large n, this is approximately 2n – 3. This is larger (worse) than 1.5n – 1. Therefore, it is better not to check for equality first when searching a binary tree.

Binary Search Trees Would it be more efficient to store all the data at the leaves, but store reference values at the nodes for navigating the tree? If value < node, move left, else move right. When we reach a leaf node, we should verify that we have a match.

Binary Search Trees At each node we would make only a two-way decision (more efficient), But the tree would be larger (less efficient). On balance, would this scheme be more efficient or less efficient, in terms of the number of comparisons?

Binary Search Trees Consider the case of 7 values 10, 20, 30, 40, 50, 60, 70, in a balanced tree. 40 20 70 50 30 10 60

Binary Search Trees Consider such a tree with 7 values. 40 20 70 50 30 10 60

Binary Search Trees Consider such a tree with 7 values. 40 20 70 50 30 10 60 1

Binary Search Trees Consider such a tree with 7 values. 40 20 70 50 30 10 60 1

Binary Search Trees Consider such a tree with 7 values. 40 20 70 50 30 10 60 1

Binary Search Trees Consider such a tree with 7 values. 40 20 70 50 30 10 60 1 5 5 5 5 5 5 5

Binary Search Trees The depth of this tree is n + 1. For each value, n comparisons are needed to reach the leaf. Then 2 comparisons are needed to match. 1 to confirm that it is a leaf node. 1 to match the values.

Binary Search Trees Therefore, for every value, the number of comparisons is n + 2. Therefore, the average is n + 2. Is this an improvement over the previous methods?

Example: Recursive Sequences Define a sequence a1 = 2, an = 2an – 1 – 1 for n  2. Find a non-recursive formula for an and prove that it is correct. Analysis {an} = {2, 3, 5, 9, 17, 33, …}. {an – 1} = {1, 2, 4, 8, 16, 32, …}. Conjecture that an = 2n – 1 + 1.

Example: Recursive Sequences Proof: Basic Step P(1) is true since a1 = 2 = 20 + 1. Inductive Step Suppose that ak = 2k – 1 + 1 for some k  1.

Example: Recursive Sequences Then ak + 1 = 2ak – 1 (by def.) = 2(2k – 1 + 1) – 1 (by ind. hyp.) = 2k + 2 – 1 = 2k + 1. Therefore, P(k + 1) is true. Therefore, an = 2n + 1 for all n  1.

Example: Contest Problem Let n be a positive integer. Suppose we have n red dots and n blue dots in the plane such that no three dots are collinear. Prove that it is possible to connect the red dots to the blue dots in distinct pairs such that none of the line segments intersect.

Example: Contest Problem

Example: Contest Problem

Example: Contest Problem Proof: Basic Step P(1) is obviously true since there is only one pair of dots and only one segment.

Example: Contest Problem Proof: Basic Step P(1) is obviously true since there is only one pair of dots and only one segment.

Example: Contest Problem Inductive Step Suppose P(1), …, P(k) are true for some k  1. Now suppose we have a collection of k + 1 red dots and k + 1 blue dots. Consider the convex hull of this set.

Example: Contest Problem There are two possibilities. Case 1: The dots on the convex hull are not all the same color. Case 2: The dots on the convex hull are all the same color.

Example: Contest Problem There are two possibilities. Case 1: The dots on the convex hull are not all the same color. Case 2: The dots on the convex hull are all the same color.

Example: Contest Problem Case 1: Suppose they are not all the same color. Choose two adjacent dots of different colors on the convex hull and connect them with a segment.

Example: Contest Problem

Example: Contest Problem

Example: Contest Problem

Example: Contest Problem By induction, the remaining collection of k red dots and k blue dots may be connected so that no two segments intersect. Nor will any of those segments intersect the first segment because it is on the convex hull and no three dots are collinear. Therefore, the entire set of dots may be connected with non-intersecting segments.

Example: Contest Problem

Example: Contest Problem

Example: Contest Problem Case 2: Suppose they are all the same color, say red. Choose a line that is not parallel to any segment connecting any two dots. Move the line across the set of dots, from right to left. Keep count of the number of red dots and the number of blue dots to the right of the line.

Example: Contest Problem 0 red dots, so far (r = 0). 0 blue dot, so far (b = 0).

Example: Contest Problem 1 red dots, so far (r = 1). 0 blue dot, so far (b = 0).

Example: Contest Problem 1 red dots, so far (r = 1). 1 blue dot, so far (b = 1).

Example: Contest Problem 2 red dots, so far (r = 2). 1 blue dot, so far (b = 1).

Example: Contest Problem 3 red dots, so far (r = 3). 1 blue dot, so far (b = 1).

Example: Contest Problem Initially, r – b = 0. At the end, r – b = 0. Just after passing the first dot, r – b = 1. Just before passing the last dot, r – b = –1. The line meets only one dot at a time. Therefore, somewhere in between, r – b must be 0.

Example: Contest Problem 3 red dots (r = 3). 1 blue dot (b = 1). r – b = 2.

Example: Contest Problem 3 red dots (r = 3). 2 blue dot (b = 2). r – b = 1.

Example: Contest Problem 3 red dots (r = 3). 3 blue dot (b = 3). r – b = 0.

Example: Contest Problem Apply the induction hypothesis. The dots on the right may be connected with non-intersecting segments. The dots on the left may be connected with non-intersecting segments. Therefore, the entire set of dots may be connected with non-intersecting segments.

Example: Contest Problem Therefore, P(n) is true for all n  1.

Example: Contest Problem Therefore, P(n) is true for all n  1.

Example: Contest Problem Therefore, P(n) is true for all n  1.