comp-330 theory of computationcrypto.cs.mcgill.ca/~crepeau/comp330/lecture-2.pdf · theory of...
TRANSCRIPT
![Page 1: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/1.jpg)
COMP-330 Theory of Computation
Fall 2017 -- Prof. Claude Crépeau
Lecture 2 : Regular Expressions & DFAs
![Page 2: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/2.jpg)
COMP 330 Fall 2017: Lectures Schedule
14. Context-free languages15. Pushdown automata16. Parsing17. The pumping lemma for CFLs18. Introduction to computability19. Models of computation Basic computability theory20. Reducibility, undecidability and Rice’s theorem21. Undecidable problems about CFGs22. Post Correspondence Problem23. Validity of FOL is RE / Gödel’s and Tarski’s thms24. Universality / The recursion theorem 25. Degrees of undecidability26. Introduction to complexity
1-2. Introduction 1.5. Some basic mathematics2-3. Deterministic finite automata +Closure properties,3-4. Nondeterministic finite automata5. Minimization+ Myhill-Nerode theorem 6. Determinization+Kleene’s theorem7. Regular Expressions+GNFA8. Regular Expressions and Languages9-10. The pumping lemma11. Duality12. Labelled transition systems13. MIDTERM
![Page 3: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/3.jpg)
95% of people cannot solve this!
🍎 + 🍌 + 🍍 = 4 🍌+🍍 🍍+🍎 🍎+🍌 .
Can you find positive whole values for 🍎,🍌, and 🍍?
Simple Puzzle
🍎=154476802108746166441951315019919837485664325669565431700026634898253202035277999🍌=36875131794129999827197811565225474825492979968971970996283137471637224634055579 🍍=4373612677928697257861252602371390152816537558161613618621437993378423467772036
95% 99.9999%
Bremner and MacLeod looked at what happens when we replace the 4 with something else. When you try to represent 178 in this way, you’ll need 398,605,460 digits. If you try 896, you’ll be up to trillions of digits…
![Page 4: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/4.jpg)
Not all problems were born equal...
![Page 5: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/5.jpg)
Is it possible to paint a colour on each region (province) of a map so that no neighbours are of the same colour ?
Vietnam
![Page 6: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/6.jpg)
Obviously, yes, if you can use as many colours as you like...
Vietnam
![Page 7: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/7.jpg)
2-colouring problem
Vietnam
![Page 8: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/8.jpg)
2-colouring problem
![Page 9: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/9.jpg)
3-colouring problem
Vietnam
![Page 10: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/10.jpg)
3-colouring problem
![Page 11: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/11.jpg)
4-colouring problem
Vietnam
![Page 12: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/12.jpg)
K-colouring of Maps (planar graphs)K=1, only the maps with zero or one region are 1-colourable.
K=2, easy to decide. Impossible as soon as 3 regions touch each other.
K=3, No known efficient algorithm to decide. However it is easy to verify a solution.
K≥4, all maps are K-colourable. (looong proof) Not easy to find a K-colouring. However it is easy to verify a solution.
http://people.math.gatech.edu/~thomas/FC/fourcolor.html
![Page 13: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/13.jpg)
3-colouring of Maps
Seems hard to solve in general,
Is easy to verify when a solution is given,
Is a special type of problem (NP-complete) because an efficient solution to it would yield efficient solutions to MANY similar problems !
![Page 14: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/14.jpg)
Examples of NP-Complete ProblemsSAT: given a boolean formula, is there an assignment of the variables making the formula evaluate to true ?
Travelling Salesman: given a set of cities and distances between them, what is the shortest route to visit each city once.
KnapSack: given items with various weights, is there of subset of them of total weight K.
![Page 15: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/15.jpg)
NP-Complete Problems
Many practical problems are NP-complete.
If any of them is easy, they are all easy.
In practice, some of them may be solved efficiently in some special cases.
Some books list hundreds of such problems.
![Page 16: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/16.jpg)
Tractable Problems (P)
2-colorability of maps.
Primality testing. (but probably not factoring)
Solving NxNxN Rubik’s cube.
Finding a word in a dictionary.
Sorting elements.
![Page 17: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/17.jpg)
Tractable Problems (P)
Fortunately, many practical problems are tractable. The name P stands for Polynomial-Time computable.
Computer Science studies mostly techniques to approach and find efficient solutions to tractable problems.
Some problems may be efficiently solvable but we might not be able to prove that...
![Page 18: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/18.jpg)
DecidableLanguages
NP
complete
Complexity Theory
P
P = NP ?
![Page 19: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/19.jpg)
Beyond NP-Completeness
PSpace Completeness: problems that require a reasonable (Poly) amount of space to be solved but may use very long time though.
Many such problems. If any of them may be solved within reasonable (Poly) amount of time, then all of them can.
![Page 20: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/20.jpg)
PSpace Completeness
Geography Game:Given a set of country names: Arabia, Cuba, Canada, France, Italy, Japan, Korea, Vietnam
A two player game: One player chooses a name. The other player must choose a name that starts with the last letter of the previous name and so on. A player wins when his opponent cannot play any name.
![Page 21: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/21.jpg)
Generalized Geography
Given an arbitrary set of names: w1, ..., wn.
Is there a winning strategy for the first player to the previous game ?
![Page 22: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/22.jpg)
DecidableLanguages
complete
Complexity Theory
NP
P
NP = PSpace ?
PSpace
![Page 23: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/23.jpg)
Theoretical Computer Science
Challenges of TCS:
FIND efficient solutions to many problems. (Algorithms and Data Structures)
PROVE that certain problems are NOT computable within a certain time or space.
Consider new models of computation.(Such as a Quantum Computer)
![Page 24: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/24.jpg)
Regular expressions, and Deterministic Finite Automata
![Page 25: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/25.jpg)
Regular expressions, and Deterministic Finite Automata
![Page 26: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/26.jpg)
Swing doors
![Page 27: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/27.jpg)
Swing doors
![Page 28: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/28.jpg)
Swing doors
![Page 29: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/29.jpg)
Swing doors
![Page 30: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/30.jpg)
Swing doors
![Page 31: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/31.jpg)
Elevators
![Page 32: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/32.jpg)
Elevators
![Page 33: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/33.jpg)
Elevators
![Page 34: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/34.jpg)
Elevators
![Page 35: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/35.jpg)
DFA: example
M1
![Page 36: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/36.jpg)
States
Alphabet
Transition function
Start state
Accept states
Definition of DFA
q1q2 q3
a,b,c,d
q1 q2
b
q1
q2
![Page 37: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/37.jpg)
Definition of DFA
![Page 38: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/38.jpg)
10010101
q1
M1
![Page 39: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/39.jpg)
10010101
q2
1
q2
M1
![Page 40: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/40.jpg)
10010101
q3
0
q3
M1
![Page 41: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/41.jpg)
10010101
0
q2
q2
M1
![Page 42: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/42.jpg)
10010101
q2
1
q2
M1
![Page 43: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/43.jpg)
10010101
q3
0
q3
M1
![Page 44: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/44.jpg)
10010101
q2
q2
1
M1
![Page 45: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/45.jpg)
10010101
q3
0
q3
M1
![Page 46: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/46.jpg)
10010101
q2
q2
1
M1
![Page 47: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/47.jpg)
10010101
q2
M1
![Page 48: COMP-330 Theory of Computationcrypto.cs.mcgill.ca/~crepeau/COMP330/LECTURE-2.pdf · Theory of Computation Fall 2017 -- Prof. Claude Crépeau Lecture 2 : Regular Expressions & DFAs](https://reader036.vdocuments.site/reader036/viewer/2022062402/5fc0af727943e751dd71126c/html5/thumbnails/48.jpg)
COMP-330 Theory of Computation
Fall 2017 -- Prof. Claude Crépeau
Lecture 2 : Regular Expressions & DFAs