






















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
Examples of inductive definitions, such as the set of multiples of 3 and well-formed formulas, and the inductive definition of the length and reversal of strings. It also includes algorithms, such as max and bubble, and their complexity analysis. The document also discusses the binary search algorithm and its running time.
Typology: Slides
1 / 30
This page cannot be seen from the preview
Don't miss anything!























Recursive Cases
Base Case
Give an inductive definition of S = {x: x is a multiple of 3}
“I LOVE my definition. It’s perfect!” “Oh yeah? Prove it!” Docsity.com
Assume 3k, -3k ∈ S, show that 3(k+1), -3(k+1) ∈ S.
Assume 3k, -3k ∈ S, show that 3(k+1), -3(k+1) ∈ S.
3k ∈ S by inductive hypothesis. 3 ∈ S by rule 1. 3k + 3 = 3(k+1) ∈ S by rule 2.
0 ∈ S by base case. 0 - 3(k+1) = -3(k+1) ∈ S by rule 3.
Base Case (k=1): If x ∈ S by 1 rule application, then it must be rule 1 and x = 3, which is clearly a multiple of 3.
Assume any number described by k or fewer applications of the rules in S is a multiple of 3 and prove that any number described by (k+1) applications of the rules is also a multiple of 3.
Suppose the (k+1)st rule applied is rule 3, and it results in value x = a + b. Then a and b are multiples of 3 by inductive hypothesis, and thus x is a multiple of 3. (^) The argument is the same if rule 2 is last instead.
Countably infinite
Example: Let Σ = {a, b, c}. Then Σ* = {λ, a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, aab,…}
How big is Σ*?
Are there any infinite strings in Σ*? No.
Is there a largest string in Σ*? No.
I point this out because the length of strings is something we might like to use for an inductive argument.
FruitLoopsR LoopsR^ Fruit R spooLtiurF
This is an example of how an inductive defn can be used in a proof. The thm itself isn’t compelling. Proof (by induction on |y|):
Base Case (|y| = 0): If |y| = 0, y = λ, then (xy)R^ = (xλ)R^ = xR^ = λxR^ = yR^ xR^.
IH: If |y| ≤ n, then ∀x ∈ Σ*, (xy)R^ = yR^ xR^.
Prove: If |y| = n+1, then ∀x ∈ Σ*, (xy)R^ = yR^ xR^.
If |y| = n+1, then ∃a ∈ Σ, u ∈ Σ*, so that y = ua, and |u| = n. Then, (xy)R^ = (x(ua))R^ by substitution = ((xu)a)R^ by assoc. of concatenation = a(xu)R^ by inductive defn of reversal = auR^ xR^ by IH = (ua)R^ xR^ by inductive defn of reversal = yR^ xR^ by substitution
Algorithm weird Input: x integer Output: y integer
5 → 16,8,4,2, 3 → 10,5,16,8,4,2, 6 → 3,10,5,16,8,4,2,
7 → 22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,
It halts on input x ≤ billions
An iterative algorithm is one that repeats the same sequence of steps a number of times.
for loops while loops repeat loops goto??
The running time of an iterative algorithm depends on the number of times the loop is invoked.
But different machines run at different speeds!
So we give running times in terms of big-oh, since different machines affect run times by constant factors.
Complexity is O(mn)
Complexity is O(n)
vars x 1 x 2 x 3 x (^4) input 3 2 4 1 j = 1 3 2 4 1 j = 2 2 3 4 1 j = 3 2 3 4 1 final 2 3 1 4