



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concepts of induction and recursion, two closely related strategies used in mathematics and computer science. Induction is a mathematical method for proving statements about natural numbers, while recursion is a programming strategy for solving problems by reducing them to simpler instances. Defining functions, the sum of squares, finding closed-form expressions, and proving the equality of recursive and closed-form functions using mathematical induction.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




1
Lecture 5 CS2110 – Summer 2008
2
A programming strategy that solves a problem by reducing it to simpler or smaller instance(s) of the same problem
A mathematical strategy for proving statements about natural numbers 0,1,2,... (or more generally, about inductively defined objects)
3
y It is often useful to describe a function in different ways
Let S : int → int be the function where S(n) is the sum of the integers from 0 to n. For example, S(0) = 0 S(3) = 0+1+2+3 = 6
Definition: iterative form S(n) = 0+1+ …+ n = Σ i
Recursive definition S(0) = 0 S(n) = n + S(n-1) for n > 0
Another characterization: closed form S(n) = n(n+1)/
n i=
4
Let SQ : int → int be the function that gives the sum of the squares of integers from 0 to n:
Idea: Use any 4 values of n to generate 4 linear equations, and then solve
SQ(0) = 0 = a·0 + b·0 + c·0 +d SQ(1) = 1 = a·1 + b·1 + c·1 + d SQ(2) = 5 = a·8 + b·4 + c·2 + d SQ(3) = 14 = a·27 + b·9 + c·3 +d
Solve these 4 equations to get a = 1/3 b = 1/2 c = 1/6 d = 0
7
Remember, we only used n = 0,1,2,3 to determine these coefficients We do not know that the closed-form expression is valid for other values of n
8
Try n = 5: SQ(n) = 0+1+4+9+16+25 = 55 Closed-form expression: 5·6·11/6 = 55 Works!
9
SQ(n) = 0^2 + 1^2 + … + (n-1)^2 + n^2 The part in the box is just SQ(n-1)
SQ(n) = SQ(n-1) + n^2 , n > 0
Base Case
Recursive Case
10
Basis: Show that P(0) is true Induction Step: Assuming that P(k) is true for an unspecified integer k, show that P(k+1) is true
y Assume equally spaced dominos, and assume that spacing between dominos is less than domino length y How would you argue that all dominos would fall? y Dumb argument: Domino 0 falls because we push it over Domino 0 hits domino 1, therefore domino 1 falls Domino 1 hits domino 2, therefore domino 2 falls Domino 2 hits domino 3, therefore domino 3 falls ... y Is there a more compact argument we can make?
19
20
y A chessboard has one square cut out of it y Can the remaining board be tiled using tiles of the shape shown in the picture (rotation allowed)? y Not obvious that we can use induction!
21
Our chessboard (8 x 8) is a special case of this argument We will have proven the 8 x 8 special case by solving a more general problem!
22
y The 2 x 2 board can be tiled regardless of which one of the four pieces has been omitted
y Divide the 4 x 4 board into four 2 x 2 sub-boards
y One of the four sub-boards has the missing piece By the I.H., that sub-board can be tiled since it is a 2 x 2 board with a missing piece
y Tile the center squares of the three remaining sub-boards as shown This leaves three 2 x 2 boards, each with a missing piece We know these can be tiled by the Induction Hypothesis
y Divide board into four sub-boards and tile the center squares of the three complete sub-boards y The remaining portions of the sub-boards can be tiled by the I.H. (which assumes we can tile 2k^ x 2k^ boards)
25
It may just mean that the particular inductive strategy you are using is the wrong choice
26
Any n x n board with one missing square can be tiled
A 3 x 3 board with one missing square has 8 remaining squares, but our tile has 3 squares; tiling is impossible
27
y A chessboard has opposite corners cut out of it. Can the remaining board be tiled using tiles of the shape shown in the picture (rotation allowed)?
y Induction fails here. Why? (Well…for one thing, this board can’t be tiled with dominos.)
28
P(0): Show that property P is true for 0 P(k) ⇒ P(k+1): Show that if property P is true for k, it is true for k+ Conclude that P(n) holds for all n
P(0): Show that property P is true for 0 P(0) and P(1) and … and P(k) ⇒ P(k+1): show that if P is true for numbers less than or equal to k, it is true for k+ Conclude that P(n) holds for all n
We can use induction to prove correctness and complexity results about recursive programs