Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.
-
Upload
neal-allison -
Category
Documents
-
view
214 -
download
0
Transcript of Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.
![Page 1: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/1.jpg)
Mathematical Induction II
Lecture 21
Section 4.3
Mon, Feb 27, 2006
![Page 2: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/2.jpg)
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.
![Page 3: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/3.jpg)
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.
![Page 4: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/4.jpg)
Example: Binary Search Trees
The total number of elements is
1 + 2 + 4 + 8 + … + 2n – 1. The total number of comparisons is
11 + 22 + 34 + 48 + … + n2n – 1. Therefore, the average is
1
1
2421
2432211
n
nn
![Page 5: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/5.jpg)
Example: Binary Search Trees
Prove by mathematical induction that
1 + 2 + 4 + 8 + … + 2n – 1 = 2n – 1. Prove by mathematical induction that
11 + 22 + 34 + 48 + … + n2n – 1
= (n – 1)2n + 1. Then, the average is
This is approximately equal to n – 1 (for large n).
12
12)1(
n
nn
![Page 6: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/6.jpg)
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.
![Page 7: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/7.jpg)
Binary Search Trees
So, exactly how many comparisons does it take to locate an element?
40
20
70503010
60
![Page 8: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/8.jpg)
Binary Search Trees
So, exactly how many comparisons does it take to locate an element?
40
20
70503010
60
221
![Page 9: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/9.jpg)
Binary Search Trees
So, exactly how many comparisons does it take to locate an element?
40
20
70503010
60
221
1 23
![Page 10: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/10.jpg)
Binary Search Trees
So, exactly how many comparisons does it take to locate an element?
40
20
70503010
60
221
1 2
4
3
5
![Page 11: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/11.jpg)
Binary Search Trees
So, exactly how many comparisons does it take to locate an element?
40
20
70503010
60
221
11 2 2
4
3
5
4
![Page 12: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/12.jpg)
Binary Search Trees
So, exactly how many comparisons does it take to locate an element?
40
20
70503010
60
221
11 2 2
4
3
655
4
![Page 13: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/13.jpg)
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.
![Page 14: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/14.jpg)
Binary Search Trees
To find the average, we must compute
12 + 2(3.5) + 45 + … + 2n – 1(1.5n + 0.5). We could work this our from scratch… Or use what we have already worked out:
.1215.1
125.01215.1
25.025.15.05.121
1
1 1
11
n
nn
n
k
kn
k
n
k
kk
n
n
kk
![Page 15: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/15.jpg)
Binary Search Trees
Therefore, the average is
For large n, this is approximately 1.5n – 1.
.
12
1215.1
n
nn
![Page 16: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/16.jpg)
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?
![Page 17: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/17.jpg)
Binary Search Trees
Exactly how many comparisons does it take to locate an element?
40
20
70503010
60
![Page 18: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/18.jpg)
Binary Search Trees
Exactly how many comparisons does it take to locate an element?
40
20
70503010
60
122
![Page 19: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/19.jpg)
Binary Search Trees
Exactly how many comparisons does it take to locate an element?
40
20
70503010
60
122
2 23
![Page 20: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/20.jpg)
Binary Search Trees
Exactly how many comparisons does it take to locate an element?
40
20
70503010
60
122
2 2
5
3
5
![Page 21: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/21.jpg)
Binary Search Trees
Exactly how many comparisons does it take to locate an element?
40
20
70503010
60
122
22 2 2
5
3
5
3
![Page 22: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/22.jpg)
Binary Search Trees
Exactly how many comparisons does it take to locate an element?
40
20
70503010
60
122
22 2 2
5
3
555
3
![Page 23: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/23.jpg)
Binary Search Trees
To find the average, we must compute
11 + 23 + 45 + … + 2n – 1(2n – 1). Again, we can use what we have already
worked out:
.3232
121212
2221221
1
1
1
1
1
n
nn
n
k
kn
k
kn
k
k
n
n
kk
![Page 24: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/24.jpg)
Binary Search Trees
Therefore, the average is
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.
.
12
3232
n
nn
![Page 25: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/25.jpg)
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.
![Page 26: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/26.jpg)
Example: Recursive Sequences
Proof: Basic Step
P(1) is true since a1 = 2 = 20 + 1.
Inductive StepSuppose that ak = 2k – 1 + 1 for some k 1.
![Page 27: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/27.jpg)
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.
![Page 28: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/28.jpg)
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.
![Page 29: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/29.jpg)
Example: Contest Problem
![Page 30: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/30.jpg)
Example: Contest Problem
![Page 31: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/31.jpg)
Example: Contest Problem
Proof: Basic Step
P(1) is obviously true since there is only one pair of dots and only one segment.
![Page 32: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/32.jpg)
Example: Contest Problem
Proof: Basic Step
P(1) is obviously true since there is only one pair of dots and only one segment.
![Page 33: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/33.jpg)
Example: Contest Problem
Inductive StepSuppose 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.
![Page 34: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/34.jpg)
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.
![Page 35: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/35.jpg)
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.
![Page 36: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/36.jpg)
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.
![Page 37: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/37.jpg)
Example: Contest Problem
![Page 38: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/38.jpg)
Example: Contest Problem
![Page 39: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/39.jpg)
Example: Contest Problem
![Page 40: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/40.jpg)
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.
![Page 41: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/41.jpg)
Example: Contest Problem
![Page 42: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/42.jpg)
Example: Contest Problem
![Page 43: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/43.jpg)
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.
![Page 44: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/44.jpg)
Example: Contest Problem
0 red dots, so far (r = 0). 0 blue dot, so far (b = 0).
![Page 45: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/45.jpg)
Example: Contest Problem
1 red dots, so far (r = 1). 0 blue dot, so far (b = 0).
![Page 46: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/46.jpg)
Example: Contest Problem
1 red dots, so far (r = 1). 1 blue dot, so far (b = 1).
![Page 47: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/47.jpg)
Example: Contest Problem
2 red dots, so far (r = 2). 1 blue dot, so far (b = 1).
![Page 48: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/48.jpg)
Example: Contest Problem
3 red dots, so far (r = 3). 1 blue dot, so far (b = 1).
![Page 49: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/49.jpg)
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.
![Page 50: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/50.jpg)
Example: Contest Problem
3 red dots (r = 3). 1 blue dot (b = 1). r – b = 2.
![Page 51: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/51.jpg)
Example: Contest Problem
3 red dots (r = 3). 2 blue dot (b = 2). r – b = 1.
![Page 52: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/52.jpg)
Example: Contest Problem
3 red dots (r = 3). 3 blue dot (b = 3). r – b = 0.
![Page 53: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/53.jpg)
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.
![Page 54: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/54.jpg)
Example: Contest Problem
Therefore, P(n) is true for all n 1.
![Page 55: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/55.jpg)
Example: Contest Problem
Therefore, P(n) is true for all n 1.
![Page 56: Mathematical Induction II Lecture 21 Section 4.3 Mon, Feb 27, 2006.](https://reader036.fdocuments.net/reader036/viewer/2022062719/56649eda5503460f94be92ab/html5/thumbnails/56.jpg)
Example: Contest Problem
Therefore, P(n) is true for all n 1.