1 / 27

CSCI 3130: Formal languages and automata theory Tutorial 2

CSCI 3130: Formal languages and automata theory Tutorial 2. Chin. Reminder. Homework 1 is due at 23:59, today! Subscribe Moodle for tutorial information My office hour: 11:00 – 12:00, Tuesday. Outline. Regular expression Closure properties

selah
Download Presentation

CSCI 3130: Formal languages and automata theory Tutorial 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 3130: Formal languagesand automata theoryTutorial 2 Chin

  2. Reminder • Homework 1 is due at 23:59, today! • Subscribe Moodle for tutorial information • My office hour: 11:00 – 12:00, Tuesday

  3. Outline • Regular expression • Closure properties • In this (only this) tutorial. Assume S = {0, 1}.

  4. Regular Expressions • The symbols Æ andeare regular expressions • Every ainS is a regular expression • If R and S are regular expressions, so are R+S, RS and R* • Remember for R*, * could be 0

  5. Regular Expressions • What are their regular expressions? 1. L1 = {w : w is a string of even length} ((0 + 1)(0 + 1))* 2. L2 = {w : w begins with 0 or ends with 0} 0(0 + 1)* + (0 + 1)*0 3. L3 = {w : w contains the pattern 01 at least once} (0 + 1)* 01 (0 + 1)*

  6. Regular Expressions • What are their regular expressions? 1. L1 = {w : w is a string of odd length} 2. L2 = {w : w begins with 0 or ends with 0 but not both} 3. L3 = {w : w contains the pattern 01 at least twice} 4. L4 = {w : w contains less 1s than 0s and at most two 0s}

  7. Regular Expressions 1. L1 = {w : w is a string of odd length} odd means of length 2n + 1 string of length 2n = ((0 + 1)(0 + 1))* (0 + 1)((0 + 1)(0 + 1))*

  8. Regular Expressions 2. L2 = {w : w begins with 0 or ends with 0 but not both} w must be of length at least 2 Either starts with 0 and ends with 1, or starts with 1 and ends with 0 0(0 + 1)*1 + 1(0 + 1)*0

  9. Regular Expressions 3. L3 = {w : w contains the pattern 01 at least twice} w must contain 01 twice in the expression can be anything before, after, or between the two 01s (0 + 1)* 01 (0 + 1)* 01 (0 + 1)*

  10. Regular Expressions 4. L4 = {w : w contains less 1s than 0s and at most two 0s} There can be at most two 0s Enumerate all possible cases: 0, 00, 001, 010, 100 OR them using + 0 + 00 + 001 + 010 + 100

  11. Regular Expressions • What do these regular expressions represent? 1. 0(0 + 1)*0 + 1(0 + 1)*1 + 0 + 1 2. 1*(011*)* 3. (0*10*10*)* 4. ((0 + 1)1)*

  12. Regular Expression 1. 0(0 + 1)*0 + 1(0 + 1)*1 + 0 + 1 First alphabet must be equal to the last alphabet

  13. Regular Expression 2. 1*(011*)* 011* = start with 0 then followed by at least one 1 (011*)* = start with 0 and every 0 must be followed by at least one 1 1* at the beginning = possibly start with 1s Every 0 is followed by at least one 1

  14. Regular Expression 3. (0*10*10*)* There are two 1s inside the brackets 0*10*10* = there can be 0 before, after, or between the two 1s = there are two 1s (0*10*10*)* = there are 2n 1s All strings that contain even number of 1s

  15. Regular Expression 4. ((0 + 1)1)* (0 + 1)1 = X1, X = 0/1 ((0 + 1)1)* = strings of the form X1X1…X1, X = 0/1 Strings of even length and every even position is 1

  16. Closure Properties • Suppose L and L’ are both regular 1. L is also regular 2. LR is also regular 3. L ∪ L’ is also regular 4. L ∩ L’ is also regular

  17. Closure Properties • Suppose L and L’ are both regular. Then L and L’ are also regular L ∪ L’ is also regular (L ∪ L’) is also regular L ∩ L’ = (L ∩ L’) by De Morgan’s law 4. Hence L ∩ L’ is also regular The construction idea in lecture is also important.

  18. Closure Properties Let L be a language comprising all strings w such that • w contains an even number of 1s, • an odd number of 0s, and • no occurrences of the substring 10. Is L regular?

  19. Closure Properties • To show a language L is regular, • represent L using a DFA / NFA / RE, or • use closure properties

  20. Closure Properties 1. L1 = {w : w contains an even number of 1s} regular 2. L2 = {w : w contains an odd number of 0s} regular 3. L3 = {w : w contains the substring 10} regular

  21. Closure Properties Let L be a language comprising all strings w such that • w contains an even number of 1s, • an odd number of 0s • no occurrences of the substring 10. Is L regular? L = L1∩L2∩L3. Hence it is regular.

  22. Regular Expression (Extra) • L = {1ky : y ∈ {0, 1}* and y contains at least k 1s, k ≥ 1} • What is the regular expression of L?

  23. Regular Expression (Extra) • L = {1ky : y ∈ {0, 1}* and y contains at least k 1s, k ≥ 1} e.g. 111 0001111 (k = 3) is in L. 1k y

  24. Regular Expression (Extra) • L = {1ky : y ∈ {0, 1}* and y contains at least k 1s, k ≥ 1} • What about 111 00011? • Same as 1 1100011. Hence is in L! • L = Strings that start with 1 and contain at least two 1s 1k y

  25. Non-regular languages • Homework 1 Problem 4 • What happens if we allow nested parans?

  26. Non-regular languages • Consider the case ((((( ))))) • same as • L = {(n )n : n ≥ 0} • L’ = {0n1n : n ≥ 0} is NOT regular (lecture) • More on non-regular languages next week.

  27. The End • Questions?

More Related