CPSC 121: Models of Computation Instructor: Bob Woodham - - PowerPoint PPT Presentation

cpsc 121 models of computation
SMART_READER_LITE
LIVE PREVIEW

CPSC 121: Models of Computation Instructor: Bob Woodham - - PowerPoint PPT Presentation

CPSC 121: Models of Computation Instructor: Bob Woodham woodham@cs.ubc.ca Department of Computer Science University of British Columbia Lecture Notes 2009/2010, Section 203 CPSC 121: Models of Computation Menu March 15, 2010 Topics: DFAs


slide-1
SLIDE 1

CPSC 121: Models of Computation

Instructor: Bob Woodham woodham@cs.ubc.ca

Department of Computer Science University of British Columbia

Lecture Notes 2009/2010, Section 203

CPSC 121: Models of Computation

slide-2
SLIDE 2

Menu March 15, 2010

Topics: DFAs and Regular Expressions Pre-class reading: Today: Epp 12.1 Lab 7 (Pre-Lab) Reminders: Lab 8 this week (pre-lab worth marks) 2nd Midterm Wednesday, March 24, 7:00–8:00pm Final exam Thursday, Apr 29, noon, OSBO A Bob’s course office hours, Friday, 10:30–noon, ICCS 119 Bring iClickers to class READ the WebCT Vista course announcements board www: http://www.ugrad.cs.ubc.ca/~cs121/ WebCT Vista: http://www.vista.ubc.ca

CPSC 121: Models of Computation

slide-3
SLIDE 3

Formal Languages: Terminology

An alphabet, Σ, is a finite set of characters A string over Σ is an ordered n-tuple of elements of Σ, written without parentheses or commas, or the null (i.e., empty) string ǫ A formal language over Σ is a set of strings over the alphabet, Σ

CPSC 121: Models of Computation

slide-4
SLIDE 4

Formal Languages: Notation

Let Σ be a given alphabet. Then

1

Σn is the set of all strings over Σ with length n

2

Σ∗ is the set of all strings over Σ. Σ∗ is called the Kleene closure of Σ

3

Σ+ is the set of all strings over Σ with length at least 1. Σ+ is called the positive closure of Σ

CPSC 121: Models of Computation

slide-5
SLIDE 5

Operations on Formal Languages

Let L and L′ be languages over Σ. Three new languages are defined as follows:

1

The concatentation of L and L′, denoted LL′, is the set LL′ = {xy | x ∈ L and y ∈ L′}

2

The union of L and L′, denoted L ∪ L′, is the set L ∪ L′ = {x | x ∈ L or x ∈ L′}

3

The Kleene closure of L, denoted L∗, is the set L∗ = {x|x is the concatentation of any number of strings in L} NOTE: ǫ ∈ L∗

CPSC 121: Models of Computation

slide-6
SLIDE 6

Definition: Regular Expression

Let Σ be a given (finite) alphabet. The following defines the regular expressions over Σ:

1

Base cases: ∅, ǫ and each individual character in Σ are regular expressions over Σ

2

Recursive cases: If r and s are regular expressions over Σ, then so are the following: (rs), the concatenation of r and s (r|s), read as r or s (r ∗), the Kleene closure of R

3

Exclusion: Nothing is a regular expression over Σ except for the objects defined in the 1. Base cases and the

  • 2. Recursive cases given above

CPSC 121: Models of Computation

slide-7
SLIDE 7

Language Defined by a Regular Expression

Let Σ be a given (finite) alphabet. The function L that associates a language to each regular expression, r, over Σ is defined below. L(r) is called the language defined by r

1

Base cases: L(∅) = ∅, L(ǫ) = {ǫ}, ∀a ∈ Σ, L(a) = {a}

2

Recursive cases: If L(r) and L(s) are languages defined by regular expressions r and s over Σ, then L(rs) = L(r)L(s) L(r|s) = L(r) ∪ L(s) L(r ∗) = (L(r))∗

CPSC 121: Models of Computation

slide-8
SLIDE 8

Result: Regular Languages and DFAs

By definition, regular languages over a given alphabet, Σ, are (formal) languages that can be defined by a regular expression, r over Σ Kleene’s theorem: The set of languages defined by regular expressions is identical to the set of languages accepted by a deterministic finite state automaton (DFA). That is, Given any language that is accepted by a DFA, there is a regular expression that defines the same language Given any language defined by a regular expression, there is a DFA that accepts the same language

CPSC 121: Models of Computation