CSE 311 Foundations of Computing I

Slides:



Advertisements
Similar presentations
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou.
Advertisements

Recursive Definitions and Structural Induction
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
CSE115/ENGR160 Discrete Mathematics 04/03/12 Ming-Hsuan Yang UC Merced 1.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
CSE 321 Discrete Structures Winter 2008 Lecture 12 Induction.
1 Regular Expressions/Languages Regular languages –Inductive definitions –Regular expressions syntax semantics Not covered in lecture.
Induction and recursion
Recursive Definitions and Structural Induction
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Chapter 2 Languages.
Induction and recursion
CSE 311 Foundations of Computing I Lecture 15 Recursive Definitions and Structural Induction Autumn 2011 CSE 3111.
CSE 311 Foundations of Computing I Lecture 16 Recursively Defined Sets and Structural Induction Spring
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction: Regular Expressions, Regular Languages Autumn 2011 CSE 3111.
Chapter 5 With Question/Answer Animations. Section 5.1.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction Spring
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
CSE 311 Foundations of Computing I Lecture 9 Proofs and Set Theory Autumn 2012 CSE
CSE 311 Foundations of Computing I Lecture 27 FSM Limits, Pattern Matching Autumn 2012 CSE
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of an FSA is easy for us to understand, but difficult.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1 Recursive Definitions and Structural Induction CS 202 Epp section ??? Aaron Bloomfield.
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
Classifications LanguageGrammarAutomaton Regular, right- linear Right-linear, left-linear DFA, NFA Context-free PDA Context- sensitive LBA Recursively.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
CSE 311 Foundations of Computing I Lecture 24 FSM Limits, Pattern Matching Autumn 2011 CSE 3111.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
CSE 311: Foundations of Computing Fall 2013 Lecture 18: Structural induction, regular expressions.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Spring
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Autumn 2012 CSE
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
CSE 311 Foundations of Computing I Lecture 18 Recursive Definitions: Context-Free Grammars and Languages Autumn 2011 CSE 3111.
CSE 311 Foundations of Computing I Lecture 20 Context-Free Grammars and Languages Autumn 2012 CSE
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
CSE 311 Foundations of Computing I Lecture 15 Strong Induction and Recursive Definitions Spring
Chapter 5 Recursion as a Problem-Solving Technique
CSE 105 theory of computation
CSE 311 Foundations of Computing I
CSE 311 Foundations of Computing I
CSE 105 theory of computation
Formal Language Theory
Discrete Structures for Computer Science
Discrete Structures for Computer Science
CSE 311: Foundations of Computing
CSE 311 Foundations of Computing I
CSE 311: Foundations of Computing
CSE 311: Foundations of Computing
CSE 321 Discrete Structures
CSE 321 Discrete Structures
CSE 321 Discrete Structures
CSE 311: Foundations of Computing
Compiler Construction
Introduction Reading: Sections 1.5 – 1.7.
COMPILERS LECTURE(6-Aug-13)
CSE 311 Foundations of Computing I
CSE 105 theory of computation
CSE 321 Discrete Structures
CSE 311 Foundations of Computing I
CSE 311 Foundations of Computing I
CSE 311 Foundations of Computing I
CSE 105 theory of computation
Presentation transcript:

CSE 311 Foundations of Computing I Lecture 18 Recursive Definitions and Structural Induction Autumn 2012 Autumn 2012 CSE 311

Announcements Reading assignments Midterm statistics: 7th Edition, Section 5.3 and pp. 878-880 6th Edition, Section 4.3 and pp. 817-819 5th Edition, Section 3.4 and pp. 766 Midterm statistics: Min 40, Max 100, Median 80, Mean 78 Autumn 2012 CSE 311

Highlight from last lecture: Recursive Definitions - General Form Basis step: Some specific elements are in S Recursive step: Given some existing named elements in S some new objects constructed from these named elements are also in S. Exclusion rule: Every element in S follows from basis steps and a finite number of recursive steps Autumn 2012 CSE 311

Structural Induction: proving properties of recursively defined sets How to prove x∈S. P(x) is true: Base Case: Show that P is true for all specific elements of S mentioned in the Basis step Inductive Hypothesis: Assume that P is true for some arbitrary values of each of the existing named elements mentioned in the Recursive step Inductive Step: Prove that P holds for each of the new elements constructed in the Recursive step using the named elements mentioned in the Inductive Hypothesis Conclude that x∈S. P(x) Autumn 2012 CSE 311

Structural Induction versus Ordinary Induction Ordinary induction is a special case of structural induction: Recursive Definition of ℕ Basis: 0 ∈ ℕ Recursive Step: If k ∈ ℕ then k+1 ∈ ℕ Structural induction follows from ordinary induction Let Q(n) be true iff for all x∈S that take n Recursive steps to be constructed, P(x) is true. Autumn 2012 CSE 311

Using Structural Induction Let S be given by Basis: 6  S; 15  S; Recursive: if x, y  S, then x + y  S. Claim: Every element of S is divisible by 3 Autumn 2012 CSE 311

Strings An alphabet  is any finite set of characters. The set * of strings over the alphabet  is defined by Basis:   * ( is the empty string) Recursive: if w  *, x  , then wx  * Autumn 2012 CSE 311

Structural Induction for strings Let S be a set of strings over {a,b} defined as follows Basis: a ∈ S Recursive: If w ∈ S then aw ∈ S and baw ∈ S If u ∈ S and v ∈ S then uv ∈ S Claim: if w ∈ S then w has more a’s than b’s Autumn 2012 CSE 311

Function definitions on recursively defined sets len () = 0; len (wa) = 1 + len(w); for w  *, a   Reversal: R =  (wa)R = awR for w  *, a   Concatenation: x •  = x for x  * x • wa = (x • w)a for x, w  *, a   Autumn 2012 CSE 311

len(x•y)=len(x)+len(y) for all strings x and y Let P(w) be “len(x•w)=len(x)+len(w)” Autumn 2012 CSE 311

Rooted Binary trees Basis: • is a rooted binary tree Recursive Step: If and are rooted binary trees then so is: T2 T1 T2 T1 Autumn 2012 CSE 311

Examples Autumn 2012 CSE 311

Functions defined on rooted binary trees size(•)=1 size( ) = 1+size(T1)+size(T2) height(•)=0 height( )=1+max{height(T1),height(T2)} T1 T2 T1 T2 Autumn 2012 CSE 311

For every rooted binary tree T size(T)  2height(T)+1 -1 Autumn 2012 CSE 311

Languages: Sets of Strings Sets of strings that satisfy special properties are called languages. Examples: English sentences Syntactically correct Java/C/C++ programs All strings over alphabet  Palindromes over  Binary strings that don’t have a 0 after a 1 Legal variable names. keywords in Java/C/C++ Binary strings with an equal # of 0’s and 1’s (HW6) Autumn 2012 CSE 311

Regular Expressions over  Each is a “pattern” that specifies a set of strings Basis: ,  are regular expressions a is a regular expression for any a   Recursive step: If A and B are regular expressions then so are: (A  B) (AB) A* Autumn 2012 CSE 311

Each regular expression is a “pattern”  matches the empty string a matches the one character string a (A  B) matches all strings that either A matches or B matches (or both) (AB) matches all strings that have a first part that A matches followed by a second part that B matches A* matches all strings that have any number of strings (even 0) that A matches, one after another Autumn 2012 CSE 311

Examples 0* 0*1* (0  1)* (0*1*)* (0  1)* 0110 (0  1)* (0  1)* (0110  100)(0  1)* Autumn 2012 CSE 311

Regular expressions in practice Used to define the “tokens”: e.g., legal variable names, keywords in programming languages and compilers Used in grep, a program that does pattern matching searches in UNIX/LINUX Pattern matching using regular expressions is an essential feature of hypertext scripting language PHP used for web programming Also in text processing programming language Perl Autumn 2012 CSE 311

Regular Expressions in PHP int preg_match ( string $pattern , string $subject,...) $pattern syntax: [01] a 0 or a 1 ^ start of string $ end of string [0-9] any single digit \. period \, comma \- minus . any single character ab a followed by b (AB) (a|b)  a or b (A  B) a?     zero or one of a (A  ) a*     zero or more of a A* a+     one or more of a AA* e.g. ^[\-+]?[0-9]*(\.|\,)?[0-9]+$ General form of decimal number e.g. 9.12 or -9,8 (Europe) Autumn 2012 CSE 311

More examples All binary strings that have an even # of 1’s All binary strings that don’t contain 101 Autumn 2012 CSE 311

Regular expressions can’t specify everything we might want Fact: Not all sets of strings can be specified by regular expressions One example is the set of binary strings with equal #’s of 0’s and 1’s from HW6 Autumn 2012 CSE 311