Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Induction and Recursion: Proofs and Applications, Lecture notes of Computer Science

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

2012/2013

Uploaded on 04/23/2013

ashwini
ashwini 🇮🇳

4.5

(16)

183 documents

1 / 34

Toggle sidebar

Related documents


Partial preview of the text

Download Induction and Recursion: Proofs and Applications and more Lecture notes Computer Science in PDF only on Docsity! 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 Induction Page 1 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 Induction Page 2 Docsity.com Sum of sequences Number of subsets Some "famous" inductive proofs you should know Monday, October 11, 2010 1:35 PM Induction Page 5 Docsity.com Theorem: 1+2+…+n = n(n+1)/2 Proof by induction: Basis: n=1, 1=1(1+1)/2. Sum of integers Sunday, October 10, 2010 11:17 AM Induction Page 6 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(n2). Application: testing pairs Monday, October 11, 2010 10:32 AM Induction Page 7 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 Induction Page 10 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 Induction Page 11 Docsity.com Theorem: any price >= 50 cents and divisible by 5 can be created with some combination of quarters and dimes. Let n be the number of nickels. 50 cents is 2 quarters (n=10). 55 cents is 1 quarter, 3 dimes (n=11). 60 cents is 2 quarters, one dime(n=12). Basis step: Let n>12. Assume true for prices between 50=10*5 and n*5. Consider the price (n+1)*5. By the inductive hypothesis, n>=n-1>10, so (n-1)*5 can be represented as a sum 25q+10d, so (n+1)*5 = (n-1)*5 + 10 = 25q+10(d+1) (one more dime). Inductive step: Another example of strong induction Sunday, October 10, 2010 12:11 PM Induction Page 12 Docsity.com } Definition shows what something is. Method defines how to recognize it. Close relationship between recursive definition and recursive method. Induction Page 15 Docsity.com both are λ (empty), or s1=w1x for w1 ϵ∑* and x ϵ∑, s2=w2y for w2 ϵ∑* and y ϵ∑, x=y, and w1=w2. (recursive step) Two strings s1, s2 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 Induction Page 16 Docsity.com ∑ U { '(', ')', '*', '|' } 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 Induction Page 17 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 Induction Page 20 Docsity.com (abc)* matches λ, abc, abcabc, abcabcabc… (de) matches de (also written sometimes as (f)?) (f|λ) matches f or λ Each regular expression defines a subset of ∑* that it "matches" abcabcde def de abcabcabcdef (abc)*(de)(f|λ) matches abcabc (no de) abcdeff (too many f's) but not Regular expression patterns Sunday, October 10, 2010 1:45 PM Induction Page 21 Docsity.com As human beings, we have an easy time with pattern matcing. Computers don’t have it so easy. They need a precise description of what "matches". The human mind versus the computer Monday, October 11, 2010 12:47 PM Induction Page 22 Docsity.com the program starts in a start state. input is read one character at a time. transitions are made between states based upon characters received. the program completes successfully only if it reaches an end state. A state machine is a very simple kind of computer program in which State machines Monday, October 11, 2010 1:53 PM Induction Page 25 Docsity.com Examples of state machines Monday, October 11, 2010 1:54 PM Induction Page 26 Docsity.com A state machine is non-deterministic if it can make a transition based upon the empty string. A deterministic state machine is called a discrete finite automaton (DFA), while a non-deterministic one is called a non-deterministic discrete finite automaton (NDFA). The difference: NDFA's have edges labeled with λ (the empty string). Non-determinism Monday, October 11, 2010 2:07 PM Induction Page 27 Docsity.com the NDFA! Induction Page 30 Docsity.com Inside the lemma 1 proof Monday, October 11, 2010 2:15 PM Induction Page 31 Docsity.com Inside the lemma 2 proof Monday, October 11, 2010 2:20 PM Induction Page 32 Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved