1 / 17

Strings and Languages

CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5). Strings and Languages. 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 }.

lam
Télécharger la présentation

Strings and Languages

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. CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5) Strings and Languages

  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 symbolsw = a1a2a3 … akwhere each symbol aj 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 = a1a2a3 … ak has length kand 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 w1 and w2 and produces a third string w1w2 by juxtaposing w2 after w1. Example: If  = {0, 1} and ifw1 = 00011, w2 = 100000, thenw1w2 = 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 wk is the concatenation of k copies of w, that is wk = www … w, k times. If w = a1a2a3 … ak, thenwR = akak-1 … a3a2a1.wR 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, butP (*) is uncountably infinite.

  12. Examples of languages  = { 0, 1 }L = { 00, 01, 10, 11 }  = { a, b }L = {  , a , a2, a3, a4, ... } = { w | w=ak, k ³ 0 }  = { 0, 1 }L = { 1, 01, 001, 0001, ... } = { w | w=0k1, 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 charactersL = { 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 Ac = W – A Concatenation of languages A and BAB = { wj | w Î A, j Î B } 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:A0 = {} = , A1 = A, A2 = AAA3 = A2A, ... , Ak+1 = AkA, ...A* = A0È A1È A2È A3È ...

  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”

More Related