Download presentation
Presentation is loading. Please wait.
Published bySophie James Modified over 8 years ago
1
1 Strings and Languages Lecture 2-3 Ref. Handout p12-17
2
2 Strings Examples abcdef 11011100101 Җ □ فقلΛφψωΫ√ Finite alphabet = a set of symbols Definition A string is a sequence of discrete symbols from a known finite alphabet
3
3 The Empty String – Λ (lambda)
4
4 Notation for Strings if x = abcd (use x to stand for “abcd”) and y = dba (use y to stand for “dba”) x R = dcba (reversing the symbols in x) |x| = |abcd| = 4 (the number of symbols in x) x.y = abcddba (the result of joining x and y) concatnation x 2 = x.x = abcdabcd x 3 = abcdabcdabcd x 1 = abcdx 0 = Λ (x.y is normally written as xy)
5
5 Languages A language is a set of strings
6
6 Sets Sets – A set is a collection of objects (informal) For example, S = {0,1,2,3,4,5,6,7,8,9} all digits S = { } ( an empty set, also written as Φ ) S = {1,2,3,4, …} all positive integers x ∈ S means that x is an element in S
7
7 Sets Two special properties about sets: No particular order of elements i.e. { a, b } = { b, a } No redundant elements i.e. { a, a } = { a } Recall the definition for string Strings “as” and “sa” are different strings, i.e. as ≠ sa But for sets, {a, s} = {s, a}
8
8 Some Simple Examples of Languages {yes, no, come-here, sit, run, good-boy} this is a finite language { a, aa, aaa, aaaa, …… } this is an infinite language { } { Λ }
9
9 Natural Languages English: alphabet = { a,b,c, …,z,., ;, !, :, etc } String: a valid sequence of English symbols = a valid English sentence English Language = a set of valid English sentences
10
10 A Programming Language class abc { public start(int x) { …… } Alphabet: class public, private if, while, = {, }, +, -, *., /, (, ), numbers, identifiers, ……
11
11 Use Set Notation to Define a Language { a, aa, aaa, aaaa, … } what does … mean? = { a n | n > 0 } it read as – the set of a n where n > 0 In set notation, S = { x | x has property P or the conditions for x }
12
12 Examples { ab n c | n >= 0 } = { xx R | x ∈ {cat, dog} } = { a m b n c k | m+n > k, 0<k, k<4 } = { } = { 00, 01, 10, 11 } { } = {Λ, 0, 1, 00, 01, 10, 11}
13
13 Memo for In-class test 2 [ /5] questionsmy answers correct answers comments 1 2 3 4 5
14
14 New Languages from Old A U Ball strings in either A or B the union of A and B A ∩ Ball strings in both A and B the intersection of A and B A. Bevery combination of one string from A followed by one from B the product of A and B
15
15 Examples A = { a, b, c } B = { b, c, d } What is: A ∩ B = A U B = A.B = |A| =|B| = |A| x |B| = |A.B| =
16
16 More Examples A = { the } B = { big, red }C = { car, bus } What is: A ∩ B = B U C = B.C = A.B.B.C = A.( B U {Λ} ).C = (A U { a }).B.(C ∩ { car }) =
17
17 More Operations on Sets The difference between two sets A and B: A \ B = { x | x ∈ A and x ∉ B } e.g. A = { a, b, c }, B = { b, c, d } A \ B = { a },B \ A = { d } The complement of A A’ = { x | x ∉ A } all strings not in A using the same alphabet as A Let U denote ‘the universe’, i.e. all possible string using same alphabet as A, then the complement of A can be also expressed as A’ = U \ A
18
18 Examples A = {Λ, a, aa, aaa } ( alphabet = {a} ) The universe set = {Λ, a, aa, aaa, aaaa, … } = { a n | n >= 0 } A’ = {aaaa, aaaaa, aaaaaa, … } = { a n | n > 3 }
19
19 Venn Diagrams – illustrating the set operations: 1. Union A = B = a b cc d e A U B = a b c d e = { a, b, c, d, e}
20
20 Venn Diagrams – illustrating the set operations: 2. Intersection A = B = a b cc d e A ∩ B = a b c d e = { c }
21
21 Venn Diagrams – illustrating the set operations: 3. difference A = B = a b cc d e A \ B = a b c d e = { a, b } B \ A = = { d, e } a b c d e
22
22 Venn Diagrams – illustrating the set operations: 4. complement A = Universe U = a b c Λ a b c aa ab ac ba bb bc ca cb cc aaa aab aac baa bab bac bba bbb bbc caa cab cac cba cbb cbc cca ccb ccc aaaa......... A’ = U \ A = Λ aa ab ac ba bb bc ca cb cc aaa aab aac baa bab bac bba bbb bbc caa cab cac cba cbb cbc cca ccb ccc aaaa...... a b c
23
23 Closure A 0 = { Λ },A 1 = A, A 2 = A.A etc A* = A 0 U A 1 U A 2 U …… (Kleene star of A ) (the closure of A) A + = A 1 U A 2 U A 3 U ……
24
24 Examples A = { a, b }, B = { Λ, a, b } What is: A* = B* = A + = B + =
25
25 Memo for In-class test 3 [ /5] questionsmy answers correct answers comments 1 2 3 4 5
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.