
CS 341: Chapter 0 0-2 Chapter 0 Mathematical Background CS 341: Foundations of CS II Contents • Overview of course • Alphabets, Strings, and Languages Marvin K. Nakayama • Set Relations and Operations Computer Science Department • Functions and Operations New Jersey Institute of Technology Newark, NJ 07102 • Graphs • Boolean Logic CS 341: Chapter 0 0-3 CS 341: Chapter 0 0-4 Overview of Course Automata Theory • Finite automata and regular expressions • Automata Theory: String matching (grep in Unix) What is a computer? Circuit design • Computability Theory Communication protocols What can and cannot be computed? • Context-free grammars and pushdown automata Compilers • Complexity Theory Programming languages What can and cannot be computed efficiently? • Turing machines Computers Algorithms • Why study different models of computation? CS 341: Chapter 0 0-5 CS 341: Chapter 0 0-6 Computability Theory Complexity Theory • For a solvable problem, is there an efficient algorithm to solve it? • There are algorithms to solve many problems. • Some problems can be solved efficiently: • But there are some problems for which there is no algorithm. Is there a path from A to H with total cost at most 20? 11 • F These are called undecidable problems: 6 6 B 5 edge labels are costs 6 D Does a program run forever? 3 8 A 2 H Is a program correct? 2 6 C E 6 Are two programs equivalent? 5 16 G • Some problems have no known efficient algorithm: Is there a path from A to H with total cost at least 50? CS 341: Chapter 0 0-7 CS 341: Chapter 0 0-8 Alphabets, Strings, and Languages Sets Definition: A set is an unordered collection of objects or elements. Examples: • Sets are written with curly braces {}. • The set {a, b, c} has elements a, b,andc. • The elements in the set are written within the curly braces. • The sets {a, b, c} and {b, c, b, a, a} are the same. Order and redundancy do not matter in a set. Definition: • The set {a} has element a. • For any set S,“x ∈ S” denotes that x is an element of the set S. {a} and a are different things. • Also, “y ∈ S” denotes that y is not an element of the set S. {a} is a set with one element a. Remark: We often specify a set using set notation, e.g., • The set Z of integers is { | ∈R 2 − 4=0} x x ,x {...,−2, −1, 0, 1, 2,...}. •R denotes the set of real numbers. • The set Z+ of nonnegative integers is • | “ ” means “such that” {0, 1, 2, 3,...}. • Comma means “and” CS 341: Chapter 0 0-9 CS 341: Chapter 0 0-10 Sets Alphabets Examples: An alphabet is a finite set of fundamental units (called letters or symbols). • The set of even numbers is {0, 2, 4, 6, 8, 10, 12,...}, Remark: We typically denote an alphabet by a capital Greek letter { 2 | =0 1 2 } which we can also write as n n , , ,... • e.g., Σ or Γ (i.e., Sigma or Gamma) In particular, 0 is an even number. • The set of positive even numbers is Examples: {2, 4, 6, 8, 10, 12,...} • The alphabet of lower-case Roman letters is • The set of odd numbers Σ={ a, b, c,...,z }. {1, 3, 5, 7, 9, 11, 13,...} There are 26 lower-case Roman letters. can also be written as { 2n +1| n =0, 1, 2,...}. • The alphabet of upper-case Roman letters is Γ={ A, B, C,...,Z }. Example: If A is the set { 2n | n =0, 1, 2,...}, then 4 ∈ A, but 5 ∈ A. There are 26 upper-case Roman letters. CS 341: Chapter 0 0-11 CS 341: Chapter 0 0-12 Alphabets Sequences and Strings Definition: Sequence of objects is a list of these objects in some order. • The alphabet of Arabic numerals is • Σ={ 0, 1, 2,...,9 }. Order and redundancy matter in a sequence, unlike in a set. • There are 10 Arabic numerals. a, b, c and b, c, b, a, a are different sequences. •{a, b, c} and {b, c, b, a, a} are the same set. • In this class we will often use the alphabets Definition: A string over an alphabet is a finite sequence of Σ={a, b}, symbols from the alphabet (written without commas or spaces between Σ={0 1} , . the symbols). Examples: • x, cromulent, embiggen,andkwyjibo are strings over the alphabet Σ={a,b,c,...,z}. • 0131 is a string over the alphabet Σ={0, 1, 2,...,9}. CS 341: Chapter 0 0-13 CS 341: Chapter 0 0-14 String Length Kleene Star ∗ Definition: The length of a string w is the number of symbols in w. Definition: For a given alphabet Σ,letΣ denote the set of all possible strings (including ε)overΣ. • Sometimes denote length of w by length(w) or |w|. Example: If Σ={a, b},then ( )=| | =3 ∗ Example: length mom mom . Σ = { ε, a, b, aa, ab, ba, bb, aaa, aab, aba, abb, . }. Definition: The empty string or null string, denoted by ε (i.e., epsilon), is the string consisting of no symbols, i.e., |ε| =0. CS 341: Chapter 0 0-15 CS 341: Chapter 0 0-16 String Ordering Concatenation Definition: A list of strings w1,w2,... over an alphabet Σ is in Definition: The concatenation of strings x and y is the string xy. string order (also called shortlex order)if 1. shorter strings always appear before longer strings, and Examples: 2. strings of the same length appear in alphabetical order. • If x = cat and y = dog,thenxy = catdog and yx = dogcat. • = = = = ∗ If x ε and y ab,thenxy ab yx. Example: If Σ={0, 1}, the string ordering of the strings in Σ is ε, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011,... • If x = ε and y = ε,thenxy = ε = yx; i.e., εε = ε. Remarks: • Previous editions (before the 3rd) of Sipser’s book instead called this lexicographic order. • String ordering is not the same as dictionary ordering. Why? CS 341: Chapter 0 0-17 CS 341: Chapter 0 0-18 Substring Definition: For string w,wedefinewn for n ≥ 0 inductively as • 0 = w ε; Definition: A substring of a string w is any contiguous part of w. −1 • wn = wn w for any n ≥ 1. • i.e., y is a substring of w if there exist strings x and z (eitherorboth possibly empty) such that w = xyz. Example: If w = dog,then 0 w = ε, 1 0 Examples: w = w w = εdog = dog, 2 1 • =47 = 472 = =2 w = w w = dogdog, y is a substring of w since letting x ε and z 3 2 gives w = xyz. w = w w = dogdogdog, • 472 4 7 2 47 72 472 . The string has substrings ε, , , , , ,and . • 42 is not a substring of 472. Example: Can also apply this to a single symbol 3 • a = aaa 0 • a = ε. CS 341: Chapter 0 0-19 CS 341: Chapter 0 0-20 Languages Examples of Languages Definition: A (formal) language is a set of strings over an alphabet. Example: Alphabet Σ={a}. • Language typically denoted by capital Roman letter, e.g., A, B,orL. Language = { } Examples: L0 ε, a, aa, aaa, aaaa, . = { an | n =0, 1, 2, 3 ...} • Computer languages, e.g., C, C++, or Java, are languages with alphabet Note that 0 Σ={ a, b,...,z, A, B,...,Z,,0, 1, 2,...,9, , • a = ε,soε ∈ L0. >, <, =, +, -, *, /, (, ), ., ,, &, !, %, |, ’, ", • there are different ways we can specify a language. :, ;,ˆ, {, }, @, #, \, ?, $, ~, ‘, CR, FF}. Another language The rules of syntax define the rules for the language. L1 = { an | n ≥ 1 } • The set of valid variable names in C++ is a language. What are the has ε ∈ L1. alphabet and rules defining valid variable names in C++? CS 341: Chapter 0 0-21 CS 341: Chapter 0 0-22 Examples of Languages Examples of Languages Example: Alphabet Σ={a}. Example: Let Σ={a, b}, and we can define a language L consisting Language of all strings that begin with a followed by zero or more b’s; i.e., L2 = { a, aaa, aaaaa, aaaaaaa, . } L = { a, ab, abb, abbb, . } 2 +1 = { a n | n =0, 1, 2, 3,...} = { abn | n =0, 1, 2,...}. Is L the language of strings beginning with a? Example: Alphabet Σ={0, 1, 2,...,9}. Language Definition: The set ∅, which is called the empty set,istheset L3 = { any string of symbols that does not start with symbol “0”} consisting of no elements. = { ε, 1, 2, 3,...,9, 10, 11,...} Remarks: • ε ∈∅since ∅ has no elements. •∅= { ε } since ∅ has no elements. CS 341: Chapter 0 0-23 CS 341: Chapter 0 0-24 Set Relations and Operations Equal Sets Definition: If S and T are sets, then S ⊆ T (S is a subset of T )if Definition: Two sets S and T are equal, written S = T ,if x ∈ S implies that x ∈ T . S ⊆ T and T ⊆ S. • Each element of S is also an element of T . Examples: Examples: • Suppose S = { ab, ba } and T = { ba, ab }. • Suppose S = { ab, ba } and T = { ab, ba, aaa }. Then S ⊆ T and T ⊆ S. ⊆ Then S T . So S = T . But T ⊆ S. • Suppose S = { ab, ba } and T = { ba, ab, aaa }. • Suppose S = { ba, ab } and T = { aa, ba }. Then S ⊆ T , but T ⊆ S. ⊆ ⊆ Then S T and T S. So S = T . CS 341: Chapter 0 0-25 CS 341: Chapter 0 0-26 Union Intersection Definition: The union of two sets S and T is Definition: The intersection of two sets S and T is S ∪ T = { x | x ∈ S or x ∈ T } S ∩ T = { x | x ∈ S and x ∈ T }, • S ∪ T consists of all elements in S or in T (or in both).
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages16 Page
-
File Size-