Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 13 - Wednesday.  What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing.

Similar presentations


Presentation on theme: "Week 13 - Wednesday.  What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing."— Presentation transcript:

1 Week 13 - Wednesday

2  What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing bounds for running time functions

3

4  Ten people are marooned on a deserted island  They gather many coconuts and put them all in a community pile  They are so tired that they decide to divide them into ten equal piles the next morning  One castaway wakes up hungry and decides to take his share early  After dividing up the coconuts, he finds he is one coconut short of ten equal piles  He notices a monkey holding one coconut  He tries to take the monkey's coconut so that the total is evenly divisible by 10  However, when he tries to take it, the monkey hits him on the head with it, killing him  Later, another castaway wakes up hungry and also decides to take his share early  On the way to the coconuts he finds the body of the first castaway and realizes that he is now be entitled to 1/9 of the total pile  After dividing them up into nine piles he is again one coconut short of an even division and tries to take the monkey's (slightly) bloody coconut  Again, the monkey hits the second man on the head and kills him  Each of the remaining castaways goes through the same process, until the 10 th person to wake up realizes that the entire pile for himself  What is the smallest number of coconuts in the original pile (ignoring the monkey's)?

5 Student Lecture

6

7  Computer science grew out a lot of different pieces  Mathematics  Engineering  Linguistics  Describing an algorithm precisely requires that it be framed in terms of some formal language with exact rules

8  We say that a language is a set of strings  A string is an ordered n-tuple of elements of an alphabet Σ or the empty string ε (which has no characters)  An alphabet Σ is a finite set of characters

9  Let alphabet Σ = {a, b}  Define a language L 1 over Σ to be the set of all strings that begin with the character a and have length at most three characters  Write out L 1  A palindrome is a string which stays the same if the order of its characters is reversed  Define a language L 2 over Σ to be the set of all palindromes made up of characters from Σ  Write 10 strings in L 2

10  Let Σ be some alphabet  For any nonnegative integer n, let  Σ n be the set of all strings over Σ that have length n  Σ + be the set of all strings over Σ that have length at least 1  Σ * be the set of all strings over Σ  Σ * is called the Kleene closure of Σ and the * operator is often called the Kleene star

11  Let alphabet Σ = {x, y, z}  Find Σ 0, Σ 1, and Σ 2  What is A = Σ 0  Σ 1 ? What is B = Σ 1  Σ 2 ? How would you describe these sets and set A  B in words?  Describe a systematic way of writing out Σ +  How would you have to change your system to write out Σ * ?

12  Let Σ be a finite alphabet  Given strings x and y over Σ, the concatenation of x and y is the string made by writing x with y appended afterwards  With languages L and L' over Σ, we can define the following new languages:  Concatenation of L and L', written LL' ▪ LL' = { xy | x  L and y  L' }  Union of L and L', written L  L' ▪ L  L' = { x | x  L or x  L' }  Kleene closure of L, written L * ▪ L * = { x | x is a concatenation of any finite number of strings in L }

13  Let alphabet Σ = {a, b}  Let L 1 be the set of all strings consisting of an even number of a's (including the empty string)  Let L 2 = {b, bb, bbb}  Find L1L2L1L2 L1  L2L1  L2 (L1  L2)*(L1  L2)*

14  It's getting annoying trying to describe infinite languages using ellipses  Notation called a regular expression can allow us to express languages precisely and compactly  Given a finite alphabet Σ, we can define regular expressions recursively: I. Base: The empty set, the empty string ε, and any individual character in Σ is a regular expression II. Recursion: If r and s are regular expressions over Σ, then the following are too: a)Concatenation: (rs) b)Alternation: (r | s) c)Kleene star: (r*) III. Restriction: Nothing else is a regular expression

15  For a finite alphabet Σ, the language L(r) defined by a regular expression r is as follows  Base: L(  ) = , L(ε) = {ε}, L(a) = {a} for every a  Σ  Recursion: If L(r) and L(r') are the languages defined by the regular expressions r and r' over Σ, then  L(r r') = L(r)L(r')  L(r | r') = L(r)  L(r')  L(r * ) = (L(r)) *

16  Let Σ = {a, b, c}  Let language L = a | (b | c)* | (ab)*  Write 5 strings in L  Let language M = ab * (c |ε)  Write 5 strings in M

17  For the sake of consistency, regular expressions obey a particular order of precedence  * is the highest precedence  Concatenation is the next highest  Alternation is the lowest  Parentheses can be omitted if there is no ambiguity  Write (a((bc)*)) with as few parentheses as possible  Write a | b* c, using parentheses to mark the precedence of each operation

18  As before, let Σ = {a, b}  Can you describe (a | b)* in another way?  What about ( ε | a* | b* )*?  Given that L = a*b(a | b)*, write 5 strings that belong to L  Let M = a* | (ab)*  Which of the following belong to M? ▪a▪a ▪b▪b ▪ aaaa ▪ abba ▪ ababab

19  Let Σ = {0, 1}  Find regular expressions for the following languages:  The language of all strings of 0's and 1's that have even length and in which the 0's and 1's alternate  The language consisting of all strings of 0's and 1's with an even number of 1's  The language consisting of all strings of 0's and 1's that do not contain two consecutive 1's  The language that gives all binary numbers written in normal form (that is, without leading zeroes, and the empty string is not allowed)

20  Regular expressions are used in some programming languages (notably Perl) and in grep and other find and replace tools  The notation is generally extended to make it a little easier, as in the following:  [ A – C] means any character in that range,  [A – C] means ( A | B | C )  [0 – 9] means ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 )  [ABC] means (A | B | C )  ABC means the concatenation of A, B, and C  A dot stands for any letter: A.C could match AxC, A&C, ABC  ^ means NOT, thus [^D – Z] means not the characters D through Z  Repetitions:  R? means 0 or 1 repetitions of R  R* means 0 or more repetitions of R  R+ means 1 or more repetitions of R  Notations vary and have considerable complexity  Use this notation to describe the regular expression for legal C++ identifiers

21

22  Finite state automata  Simplifying FSA's

23  Keep reading Chapter 12


Download ppt "Week 13 - Wednesday.  What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing."

Similar presentations


Ads by Google