Presentation is loading. Please wait.

Presentation is loading. Please wait.

Strings and Languages CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5)

Similar presentations


Presentation on theme: "Strings and Languages CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5)"— Presentation transcript:

1 Strings and Languages CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5)

2 Alphabet An alphabet  is a finite nonempty set of symbols. Each symbol is a non- divisible or atomic object used in the construction of strings. Examples  1 = { a, b, c, d, e, …, z }  2 = { 0, 1 }

3 Strings A string w of length k on an alphabet  is a sequence of k symbols w = a 1 a 2 a 3 … a k where each symbol a j comes from . Examples aabakkejaa is a string of length 10 from  1 00011001 is a string of length 8 from  2

4 Length of a string The string w = a 1 a 2 a 3 … a k has length k and we write: |w| = k The unique string containing no symbols is called the empty string, denoted by . Thus |  | = 0. Examples: |bababaako| = 9 |01101001| = 8

5 Set of all strings on  If  is an alphabet, we denote by  k the set of all strings of length k on  :  k = {all w such that |w| = k }. We denote by  0 the set containing just the empty string  0 = {  }. The set of all strings on  is  *, and is defined by  * =  k where k = 0 to . Thus  * =  0   1   2   3  … Also,  + =  1   2   3  …

6 Concatenation on strings Concatenation is a binary operation on  * which takes two strings w 1 and w 2 and produces a third string w 1 w 2 by juxtaposing w 2 after w 1. Example: If  = {0, 1} and if w 1 = 00011, w 2 = 100000, then w 1 w 2 = 00011100000.

7 Prefixes and suffixes If  and  are two strings from  *, and if  = , then we say that  is a prefix of , and  is a suffix of . If  is not empty, then  is a proper prefix of . Similarly, if  is not empty, then  is a proper suffix of .

8 Properties of concatenation  * is closed under concatenation. If    *, and    *, then    *. Concatenation is associative. If , ,    *, then  (  ) = (  ) . The empty string  is the identity element. For each string  in  *,  =  = .

9 More properties Concatenation is not commutative. If ,    *, then   , in general. For all ,    *, the lengths are related as follows: |  | = |  | + |  |.

10 Other notation w k is the concatenation of k copies of w, that is w k = www … w, k times. If w = a 1 a 2 a 3 … a k, then w R = a k a k-1 … a 3 a 2 a 1. w R is called the reverse of w.

11 Languages A language L over an alphabet  is any set L of strings on . That is L   *. The set of all languages over  is the set of all subsets of  *, that is P (  *) the powerset of  *. Note:  * is countably infinite, but P (  *) is uncountably infinite.

12 Examples of languages  = { 0, 1 } L = { 00, 01, 10, 11 }  = { a, b } L = { , a, a 2, a 3, a 4,... } = { w | w=a k, k  0 }  = { 0, 1 } L = { 1, 01, 001, 0001,... } = { w | w=0 k 1, k  0 }

13 Describing a language using “set-formers” L = { w | say something about w } Examples  = { 0, 1 }; L = { 000, 001, 010, 011 } L = { w | w starts with a 0 and |w|=3 }  = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } L = { w | w is a prime number }  = set of ASCII characters L = { w | w is a valid Java program }

14 Operations on languages Set operations on languages A and B union A  B intersection A  B complement A c = W – A Concatenation of languages A and B AB = {  |   Kleene closure A*

15 Concatenation of languages Example: A = { a, ab } B = { c, bc } AB = { ac, abc, abbc } BA = { ca, cab, bca, bcab } Thus AB  BA

16 Kleene closure A* If  is an alphabet,  * the set of all strings on , A   *, A a language on V, then the Kleene closure of A, denoted by A*, is defined as follows: A 0 = {  } =  A 1 = A, A 2 = AA A 3 = A 2 A,..., A k+1 = A k A,... A* = A 0  A 1  A 2  A 3 ...

17 Languages and problems Consider the following language over  = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }: L = { w | w is a number divisible by 3 } Consider the following problem: Given a number, determine if the number is divisible by 3 Problems correspond to languages The above problem can be restated as “determine if a given number/string is in L”


Download ppt "Strings and Languages CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5)"

Similar presentations


Ads by Google