lect17 - Strings A string over a set A is a finite sequence...

This preview shows pages 1–6. Sign up to view the full content.

1 Strings A string over a set A is a finite sequence of elements from A. Definition . An alphabet is a nonempty, finite set of indivisible symbols. We are going to denote it by Σ . Any program is a string of keywords, variable names, and permissible symbols. The set of elements from which the strings are built is called an alphabet . A programming language should satisfy general rules (grammar) to be understood by computer (compiler). These rules are studied by the formal theory of programming languages.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Definition . A string w over an alphabet Σ is a sequence of symbols, w = a 1 a 2 a n , where each a i Σ , 1 i n. The number of symbols is called the length of the string, | w |= n . There is one special string that has zero length (contains no symbols). It is called the empty string and has special notation , λ . | w |=0 w = λ . λ is not an element of any alphabet, λ∉ Σ . Example. Let Σ = { a , b , c }. Find all possible strings with length less or equal 3 built from Σ . Length 0: λ Length 1: a b c Length 2: aa ab ac ba bb bc ca cb cc Length 3: aaa aab aac aba abb abc aca acb acc …
3 Two strings u and v can be concatenated to form a single string uv , that consists of the symbols of string u , followed by symbols of of string v . The length | uv | = | u|+| v |. λ u = u λ = u Concatenation is associative: ( uv ) w = u ( vw ), but not commutative: uv vu (the order is important!).

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Definition. Any set of strings over some alphabet is called a language. Alphabet itself is a language as well (the language of all one-symbol words). Since languages are sets, we can apply all set operations to languages: union, intersection and set difference. There is one operation specific for languages: concatenation of two languages : L 1 L 2 ={ uv | u L 1 and v L 2 } Q : L 1 L 2 = L 2 L 1 ? A: L 1 L 2 L 2 L 1 Examples: Set of all executable computer programs is a language.
Example. Take the alphabet Σ = { a , b , c }. Consider two languages over alphabet Σ : L 1 ={ a , ab } and L 2 ={ b , bc , c }. Find L 1 L 2 and L 2 L 1 . We need to take every string from L 1 and concatenate with every string from L 2 . In this way we get | L 1 | | L 2 | strings: ab , abc , ac , abb , abbc , abc . Note, that not all strings are distinct, like abc . L 1 L 2 = { ab , abc , ac , abb , abbc } . The cardinality | L 1 L 2 | is the number of distinct strings, resulting from concatenation . In general, | L 1 L 2 | | L 1 | | L 2 | and | L 1 L 2 | | L 2 L 1 | In the example | L 1 L 2 | = 5< | L 1 | | L 2 |=6. In the same way:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 07/14/2011.

Page1 / 23

lect17 - Strings A string over a set A is a finite sequence...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online