


























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
A collection of notes on induction and recursion, including proofs, examples, and applications. Topics covered include the theorem that 1+2+...+n = n(n+1)/2, the number of subsets of a finite set, and the theorem that any integer greater than 1 can be expressed as the product of primes. The document also discusses the relationship between recursive definition and induction, and provides examples of regular expressions and their use in pattern matching.
Typology: Lecture notes
1 / 34
This page cannot be seen from the preview
Don't miss anything!



























In general, in exercises, "show" means "show from the definitions and theorems in the chapter"…. Thus it is not quite enough to say why you believe something; must trace it back to the definitions. What constitutes showing is based upon the chapter. So showing something is a matter of going back to logic. In sets chapter, we derived sets from logic. So showing something means using everything in previous chapters:) In this chapter, we have the sets chapter to use Solutions to odd numbered problems are in the back of the book. These demonstrate what "showing" actually is! Two well-kept public secrets "Show" Monday, October 11, 2010 2:58 PM Docsity.com
P(n) for all integers n>=1. If P(1) and P(k)→P(k+1), then Induction: To do problem of size n, do a problem of size n-1 (or perhaps two problems of size n/2). Recursion: How are these related? Induction and Recursion Friday, October 08, 2010 1:39 PM Docsity.com
The proof of correctness for a recursive program is inductive! In other words Friday, October 08, 2010 4:48 PM Docsity.com
Sum of sequences Number of subsets Some "famous" inductive proofs you should know Monday, October 11, 2010 1:35 PM Docsity.com
Application: what is the order of the runtime for $pairs++ if $a[$i] == $a[$j]; for ($j=$i; $j<@a; $j++) { } for ($i=0; $i<@a-1; $i++) { } Answer: O(1+2+3+…+n-1) = O(n(n-1)/2) = O(n 2 ). Application: testing pairs Monday, October 11, 2010 10:32 AM Docsity.com
Theorem: The number of subsets of a finite set S of |S|=n elements is 2n. Proof by induction: Basis: n=0, S=φ, number of subsets is 1 = 2^0. Number of subsets Sunday, October 10, 2010 11:30 AM Docsity.com
(P(1) ^ P(k)→P(k+1)) → Regular induction: Strong induction: (P(1) ^ If P(1) is true, and the fact that all of P(1)…P(k) are true implies that P(k+1) is true, then P(k) is true for all integers >= 1 Strong Induction Sunday, October 10, 2010 11:36 AM Docsity.com
Theorem: any integer n>1 can be expressed as the product of primes Basis: 1 is the product of one prime, namely, 1. If n+1 is prime, we're done. Else it is the product of two numbers n+1=pq, p<=n, q<=n. By the inductive hypothesis, p and q are products of primes. Thus n+1=pq is a product of primes. Inductive step: assume true for 1…n. Consider n+1. Example of strong induction Sunday, October 10, 2010 11:39 AM Docsity.com
Another use of recursive definition and induction: Define the set of strings recursively. Define their operations recursively. strings and string matching. Strings and string matching Monday, October 11, 2010 1:01 PM Docsity.com
Let ∑ represent an alphabet. Let ∑* represent the set of strings over ∑. λ ϵ∑: λ represents the empty string if wϵ∑ and xϵ∑ then wx ϵ∑. Definition of ∑: Is something a string? w ϵ∑* if w = λ or w=xy for x ϵ∑* and y ϵ ∑ λ is a string, so λx = x is a string, so xy is a string, so xyz is a string…. If xyz is a string, then xy is in ∑ x is in Pseudo-code for determining if something is a string function isString(s) { if s==λ return TRUE; Split s into xy where y is the last character. if y ϵ∑ and isString(x) return TRUE; else return FALSE; } TRUE, so xyz is a string. Definition of a string Sunday, October 10, 2010 1:12 PM Docsity.com
both are λ (empty), or s 1 =w 1 x for w 1 ϵ∑* and x ϵ∑, s 2 =w 2 y for w 2 ϵ∑* and y ϵ∑, x=y, and w 1 =w 2. (recursive step) Two strings s 1 , s 2 are equal if length(s)=0 if s=λ length(s)=length(w)+1 if s=wx, wϵ∑*, xϵ∑. The length of a string s is length(s) defined by Some more string definitions Monday, October 11, 2010 1:09 PM Docsity.com
A regular expression pattern is a character string made from the alphabet (x) in the pattern means one copy of x should appear in the matching string. (x|y) in the pattern means either x or y appears. (x)* in the pattern means zero or more copies of x. where for x ϵ∑, Example: (abc)(def) matches any string starting with abc and ending with any number of copies of def, including 0 copies! Example: (abc|def) matches either the string abc or the string def. Regular expressions Sunday, October 10, 2010 1:21 PM Docsity.com
((ab)|de) is an RE iff (ab) is an RE and de is an RE iff ab is an RE and de is an RE and both are strings, so they are REs. Docsity.com
expression regular? why? abc yes in ∑* (abc)* yes x=abc an RE, (x)* an RE (abc) no star on wrong side! abc) no parens don't balance (((abc)))* yes equivalent to (abc)* x** = x* Not everything is a regular expression Monday, October 11, 2010 10:56 AM Docsity.com