Copyright © Zeph Grunschlag,

Slides:



Advertisements
Similar presentations
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Advertisements

Copyright © Zeph Grunschlag, Recursion Zeph Grunschlag.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
1 Context Free Languages October 2, Announcement HW 3 due now.
CS5371 Theory of Computation Lecture 1: Mathematics Review I (Basic Terminology)
COMS 3261, Lecture 2 Strings, Languages, Automata September 6, 2001.
Fall 2006Costas Busch - RPI1 Languages. Fall 2006Costas Busch - RPI2 Language: a set of strings String: a sequence of symbols from some alphabet Example:
Lecture 1 String and Language. String string is a finite sequence of symbols. For example, string ( s, t, r, i, n, g) CS4384 ( C, S, 4, 3, 8) (1,
CMSC 330 Exercise: Write a Ruby function that takes an array of names in “Last, First Middle” format and returns the same list in “First Middle Last” format.
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Induction and recursion
Copyright © Cengage Learning. All rights reserved.
Sequences & Summation Notation 8.1 JMerrill, 2007 Revised 2008.
Chapter 4: Induction and Recursion
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
CSC312 Automata Theory Lecture # 2 Languages.
Costas Busch - LSU1 Languages. Costas Busch - LSU2 Language: a set of strings String: a sequence of symbols from some alphabet Example: Strings: cat,
Recursion. L162 Agenda Recursion and Induction Recursive Definitions Sets Strings.
1 Chapter 1 Introduction to the Theory of Computation.
Sequences and Summations
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Lecture 5 Regular Expressions CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Chapter 11 Sequences, Induction, and Probability Copyright © 2014, 2010, 2007 Pearson Education, Inc Sequences and Summation Notation.
1 Lecture 3.3: Recursion CS 250, Discrete Structures, Fall 2012 Nitesh Saxena Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
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.
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.
Module #10: Proof Strategies Rosen 5 th ed., §3.1 (already covered)
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
Theory of computation Introduction theory of computation: It comprises the fundamental mathematical properties of computer hardware, software,
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
Sequences Lecture 11. L62 Sequences Sequences are a way of ordering lists of objects. Java arrays are a type of sequence of finite size. Usually, mathematical.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
Copyright © 2012 Pearson Education, Inc. Publishing as Addison Wesley CHAPTER 8: Sequences, Series, and Combinatorics 8.1 Sequences and Series 8.2 Arithmetic.
Sequences and Sums.
Copyright © Zeph Grunschlag,
Chapter 4: Induction and Recursion
Chapter 4 Introduction to Set Theory
Sequences & Summation Notation
CIS Automata and Formal Languages – Pei Wang
Languages Prof. Busch - LSU.
Languages Costas Busch - LSU.
Induction and Recursion
LANGUAGES Prepared by: Paridah Samsuri Dept. of Software Engineering
Mathematical Induction Recursion
Discrete Structures for Computer Science
VCU, Department of Computer Science CMSC 302 Sequences and Summations Vojislav Kecman 9/19/2018.
Computer Science Department
Discrete Structures for Computer Science
Rosen 5th ed., §3.2 ~9 slides, ~½ lecture
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
Section 11.1 Sequences and Series
INTRODUCTION TO THE THEORY OF COMPUTATION
Specification of tokens using regular expressions
CS 250, Discrete Structures, Fall 2011 Nitesh Saxena
Copyright © Zeph Grunschlag,
Rosen 5th ed., §3.2 ~9 slides, ~½ lecture
CS 250, Discrete Structures, Fall 2015 Nitesh Saxena
Discrete Mathematics and its Applications
CS 250, Discrete Structures, Fall 2014 Nitesh Saxena
Introduction Reading: Sections 1.5 – 1.7.
Formal Languages Context free languages provide a convenient notation for recursive description of languages. The original goal of formalizing the structure.
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
CSC312 Automata Theory Lecture # 2 Languages.
Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion
10.1 Sequences and Summation Notation
Languages Fall 2018.
Presentation transcript:

Copyright © Zeph Grunschlag, 2001-2002. Recursion Zeph Grunschlag Copyright © Zeph Grunschlag, 2001-2002.

Agenda Recursion and Induction Recursive Definitions Sets Strings L16

Recursively Defined Sequences Often it is difficult to express the members of an object or numerical sequence explicitly. EG: The Fibonacci sequence: {fn } = 0,1,1,2,3,5,8,13,21,34,55,… There may, however, be some “local” connections that can give rise to a recursive definition –a formula that expresses higher terms in the sequence, in terms of lower terms. EG: Recursive definition for {fn }: INITIALIZATION: f0 = 0, f1 = 1 RECURSION: fn = fn-1+fn-2 for n > 1. L16

Recursive Definitions and Induction Recursive definition and inductive proofs are complement each other: a recursive definition usually gives rise to natural proofs involving the recursively defined sequence. This is follows from the format of a recursive definition as consisting of two parts: Initialization –analogous to induction base cases Recursion –analogous to induction step In both induction and recursion, the domino analogy is useful. L16

Recursive Functions It is possible to think of any function with domain N as a sequence of numbers, and vice-versa. Simply set: fn =f (n) For example, our Fibonacci sequence becomes the Fibonacci function as follows: f (0) = 0, f (1) = 1, f (2) = 1, f (3) = 2,… Such functions can then be defined recursively by using recursive sequence definition. EG: INITIALIZATION: f (0) = 0, f (1) = 1 RECURSION: f (n)=f (n -1)+f (n -2), for n > 1. L16

Recursive Functions Factorial A simple example of a recursively defined function is the factorial function: n! = 1· 2· 3· 4 ···(n –2)·(n –1)·n i.e., the product of the first n positive numbers (by convention, the product of nothing is 1, so that 0! = 1). Q: Find a recursive definition for n! L16

Recursive Functions Factorial A:INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. EG: 5! = L16

Recursive Functions Factorial A:INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. EG: 5! = 5 · 4! recursion L16

Recursive Functions Factorial A:INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. EG: 5! = 5 · 4! = 5 · 4 · 3! recursion L16

Recursive Functions Factorial A:INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2! recursion L16

Recursive Functions Factorial A:INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2! = 5 · 4 · 3 · 2 · 1! recursion L16

Recursive Functions Factorial A:INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2! = 5 · 4 · 3 · 2 · 1! = 5 · 4 · 3 · 2 · 1 · 0! recursion L16

Recursive Functions Factorial A:INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2! = 5 · 4 · 3 · 2 · 1! = 5 · 4 · 3 · 2 · 1 · 0! = 5 · 4 · 3 · 2 · 1 · 1 = 120 recursion L16 initialization

Recursive Definitions of Mathematical Notation Often, recursion is used to define what is meant by certain mathematical operations, or notations. L16

Recursive Definitions of Mathematical Notation Definition of summation notation: There is also a general product notation : Q: Find a simple formula for L16

Recursive Definitions of Mathematical Notation A: This is just the factorial function again. Q: Find a recursive definition for the product notation L16

Recursive Definitions of Mathematical Notation A: This is very similar to definition of summation notation. Note: Initialization is argument for “product of nothing” being 1, not 0. L16

Recursive Definition of Sets Sometimes sets can be defined recursively. One starts with a base set of elements, and recursively defines more and more elements by some operations. The set is then considered to be all elements which can be obtained from the base set under a finite number of allowable operations. EG: The set S of prices (in cents) payable using only quarters and dimes. BASE: 0 is a member of S RECURSE: If x is in S then so are x+10 and x+25 Q: What is the set S ? L16

Recursive Definition of Sets A: S = {0, 10, 20,25,30,35,40,45,… } Q: Find a recursive definition of the set T of negative and positive powers of 2 T = { …,1/32,1/16,1/8, ¼, ½, 1, 2, 4, 8, 16, …} A: BASE: 1  T RECURSE: 2x T and x/2 T if x T L16

Character Strings Strings are the fundamental object of computer science. Everything discrete can be described as a string of characters: Decimal numbers: 1010230824879 Binary numbers: 0111010101010111 Text. E.g. this document Computer programs: public class Hello{ Patterns of nature DNA Proteins Human language L16

Strings Notation DEF: A string is a finite sequence of 0 or more letters in some pre-set alphabet S. Q: What is the alphabet for each of the following types of strings: Decimal numbers Binary numbers L16

String Alphabets S = { 0, 1 } Decimal numbers Binary numbers S = { 0, 1 } L16

Strings Length The length of a string is denoted by the absolute value. Q: What are the values of |yet|, |another|, |usage|, |pipe|, |symbol| L16

Strings Length and the Empty String A: |yet|=3, |another|=7, |usage|=5, |pipe|=4, |symbol|=6. There is a very useful string, called the empty string and denoted by the lower case Greek letter l (lambda)1. Q: Do we really need the empty string? 1In other texts, including the text for computability the Greek letter epsilon is used instead. L16

Strings Length and the Empty String A: YES!!! Strings almost always represent some other types of objects. In many contexts, the empty string is useful in describing a particular object of unique importance. EG in life, l might represent a message that never got sent. 1In other texts, including the text for computability (CS3261) the Greek letter e (epsilon) is used instead. L16

Strings Concatenation Given strings u and v can concatenate u and v to obtain u · v (or usually just uv ). EG. If u = “ire” and v = “land” then uv = “ireland”. Q: l·v = ? 1In other texts, including the text for computability the Greek letter epsilon is used instead. L16

Strings Concatenation A: l·v = v · l = v The empty string acts like 0 under addition in that it doesn’t affect strings when concatenating them. 1In other texts, including the text for computability the Greek letter e (epsilon) is used instead. L16

Strings Reversal The reverse of a string is the string read from right to left instead of from left to right. For example the reverse of “oprah” is “harpo”. The reverse of w is denoted by w R. So: oprahR = harpo L16

Strings Recursive Sets One can define sets of strings recursively. For example B = the set of reduced non-negative binary numbers: B = {0,1,10,11,100,101,110,111,…} BASE: 0,1  B RECURSE: If u  B and u begins with 1, then u · 0 , u · 1  B Palindromes are strings that equal themselves when reversed. E.g. “racecar”, “Madam I’m Adam”, “010010”. The set pal consists of all palindromes over the alphabet {0,1}. Q: Find a recursive definition for pal. 1In other texts, including the text for computability the Greek letter e (epsilon) is used instead. L16

Strings Recursive Sets A: BASE: l , 0, 1  pal RECURSE: 0u 0, 1u 1  pal if u  pal 1In other texts, including the text for computability the Greek letter e (epsilon) is used instead. L16