<<

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 • Relations and Operations 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

• 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

• 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 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 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 and Strings Definition: 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

∗ 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 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

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 . • 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 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 ,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 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 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). • S ∩ T consists of elements that are in both S and T . Examples: • If S = { ab, bb } and T = { aa, bb, a }, Definition: Sets S and T are disjoint if S ∩ T = ∅. then S ∪ T = { ab, bb, aa, a }. Examples: • = { } = ∅ If S a, ba and T , • Suppose S = { ab, bb } and T = { aa, bb, a }. then S ∪ T = S. Then S ∩ T = { bb }.

• If S = { a, ba } and T = { ε }, • Suppose S = { ab, bb } and T = { aa, ba, a }. then S ∪ T = { ε, a, ba }. Then S ∩ T = ∅,soS and T are disjoint.

CS 341: Chapter 0 0-27 CS 341: Chapter 0 0-28 Set Subtraction

Definition: The difference of two sets S and T is Definition: The complement of a set S is S − T = { x | x ∈ S, x ∈ T }. S = { x | x ∈ S }. • S is the set of all elements under consideration that are not in S. Examples: • Suppose S = { a, b, bb, bbb } and T = { a, bb, bab }. Example: − = { } Then S T b, bbb . • Let S be set of strings over alphabet Σ={a, b} that begin with What is T − S ? symbol b. • Then S is set of strings over Σ that do not begin with symbol b, i.e., • Suppose S = { ab, ba } and T = { ab, ba }. ∗ S =Σ − S. Then S − T = ∅. • S is not the set of strings over Σ that begin with the symbol a ε ∈ S and ε does not begin with a. CS 341: Chapter 0 0-29 CS 341: Chapter 0 0-30 Concatenation Concatenation Recall Definition: The concatenation (or product)ofsetsS and T is S ◦ T = { xy | x ∈ S, y ∈ T }. S ◦ T = { xy | x ∈ S, y ∈ T }. Examples: Remarks: • If S = { a, aa } and T = { ε, a, ba },then • S ◦ T is the set of strings that can be split into 2 parts S ◦ T = { a, aa, aba, aaa, aaba }, first part of string is in S,and T ◦ S = { a, aa, aaa, baa, baaa }. second part is in T . aba ∈ S ◦ T , but aba ∈ T ◦ S.

• Sometimes write ST rather than S ◦ T to denote concatenation. Thus, S ◦ T = T ◦ S.

• If S = { ab, ba } and T = ∅,then S ◦ T = T ◦ S = ∅.

CS 341: Chapter 0 0-31 CS 341: Chapter 0 0-32 Cardinality of Union

Definition: The cardinality |S| of a set S is number of elements in S. Fact: If S and T are any 2 sets such that |S ∩ T | < ∞,then |S ∪ T | = |S| + |T |−|S ∩ T |. Definition: S T • AsetS is finite if |S| < ∞. • If S is not finite, then S is infinite.

Examples: In particular, if S ∩ T = ∅,then|S ∪ T | = |S| + |T |. • Suppose S = { ε, bba } and T = { an | n ≥ 1 }. Then |S| =2and |T | = ∞.

• If S = ∅,then|S| =0. CS 341: Chapter 0 0-33 CS 341: Chapter 0 0-34 Sequences and Tuples Definition: Sequence of objects is a list of these objects in some order. Definition: The Cartesian product (or cross product) • Sometimes sequences are written within parentheses. of two sets S and T is the set of pairs × = { ( ) | ∈ ∈ } Example: The sequence 7, 2, 7, 8 may be written as (7, 2, 7, 8). S T x, y x S, y T . Examples: Suppose S = { a, ba, bb } and T = { ε, ba }. Example: The sequence (7, 2, 7, 8) =(2, 8, 7) • S × T = { (a, ε), (a, ba), (ba, ε), (ba, ba), (bb, ε), (bb, ba) }. • Order and redundancy matter in a sequence (but they don’t in a set). • For example, the pair (a, ba) ∈ S × T . Definition: Finite sequences are called tuples. • T × S = { (ε, a), (ε, ba), (ε, bb), (ba, a), (ba, ba), (ba, bb) }. • A k-tuple has k elements in the sequence. • (ba, a) ∈ T × S, but (ba, a) ∈ S × T ,soT × S = S × T . • Concatenation is not the same as Cartesian product: Examples: S ◦ T = { a, aba, ba, baba, bb, bbba } = S × T. • (43, 2, 7871) is a 3-tuple, which is also called a triple. • (9, 23) is a 2-tuple, which is also called a pair.

CS 341: Chapter 0 0-35 CS 341: Chapter 0 0-36 Cartesian Product Cartesian Product

Example: For Z = {...,−2, −1, 0, 1, 2,...}, Example: • Z×Z= { (x, y) | x ∈Z,y∈Z} Suppose S1 = { ab, ba, bbb }, Remark: |S × T | = |S|·|T |.Why? S2 = { a, bb }, S3 = { ab, b }. Remark: Can also define Cartesian product of more than 2 sets. • Then Definition: The Cartesian product (or cross product)ofk sets S1 × S2 × S3 = { (ab,a,ab), (ab, a, b), (ab, bb, ab), S1,S2,...,S is the set k (ab, bb, b), (ba, a, ab), (ba,a,b), × ×···× S1 S2 Sk (ba, bb, ab), (ba, bb, b), (bbb, a, ab), = { ( ) | ∈ =1 2 } x1,x2,...,xk xi Si for i , ,...,k (bbb, a, b), (bbb, bb, ab), (bbb, bb, b) }. of k-tuples. • Note that the 3-tuple (ab, a, ab) ∈ S1 × S2 × S3. k Definition: S = S × S ×···× S k times CS 341: Chapter 0 0-37 CS 341: Chapter 0 0-38 Power Set Repeated of a Set

( ) Definition: The power set P(S) of a set S is Definition: Given a set S of strings, we define S k for k ≥ 0 as (0) P(S)={ A | A ⊆ S }. S = { ε } and (k) = (k−1) ◦ ≥ 1 •P(S) is the set of all possible of S. S S S for k . Remarks: Example: If S = { a, bb },then • Can show (by induction) that for k ≥ 1, P( )={∅ { } { } { }} S , a , bb , a, bb . (k) S = S ◦ S ◦···◦ S k times = { ··· | ∈ ∀ =1 2 } Fact: If |S| < ∞,then w1w2 wk wi S, i , ,...,k . | | |P( )| =2S ( ) S , • S k is the set of strings formed by concatenating k strings from S, | | i.e., there are 2 S different subsets of S.Why? where we allow repetition.

(1) • Note that S = S.

CS 341: Chapter 0 0-39 CS 341: Chapter 0 0-40 ∗ Example Kleene Star S

= { } Example: If S a, bb ,then Definition: The (Kleene star) closure of a set of strings S is ∞ ∗  ( ) (0) (1) (2) (3) (0) S = S k = S ∪ S ∪ S ∪ S ∪··· . S = { ε }, k=0

(1) = { } S a, bb , Remarks: (2) • ∗ S = { aa, abb, bba, bbbb }, S is the set of all strings formed by concatenating zero or more strings from S, where we may use the same string more than once. (3) S = { aaa, aabb, abba, abbbb, bbaa, bbabb, bbbba, bbbbbb }. • In set notation, ∗ = { ··· | ≥ 0 ∈ =1 2 } S w1w2 wk k and wi S for all i , ,...,k , = ∅ Example: If S ,then where the concatenation of k =0strings is the empty string ε. (0) S = {ε}, • ⊆ ∗ ( ) S S . S k = ∅, for all k ≥ 1. CS 341: Chapter 0 0-41 CS 341: Chapter 0 0-42 ∗∗ ∗ Examples of Kleene Star Closure S = S

∗∗ ∗ ∗ ∗∗ Example: If S = { ba, a },then Remark: S =(S ) ,soS is the set of strings formed by ∗ ∗ S = { ε, a, aa, ba, aaa, aba, baa, aaaa, aaba, . . . }. concatenating strings from S . ∗ ∈ ∗∗ ∗ If x S ,canbb ever be a substring of x? Fact: S = S for any set S of strings. Σ={ } Example: If a, b ,then Proof. The way we will prove this is by showing two things: ∗ Σ = { ε, a, b, aa, ab, ba, bb, aaa, aab, aba, . . . }, ∗∗ ∗ 1. S ⊆ S which is all possible strings over the alphabet Σ. ∗ ∗∗ 2. S ⊆ S . ∗ Example: If S = ∅,thenS = { ε }. To show part 2, • ⊆ ∗ = { } ∗ = { } for any set A, we know that A A . Example: If S ε ,thenS ε . ∗ ∗ ∗∗ • Hence, letting A = S ,weseethatS ⊆ S .

CS 341: Chapter 0 0-43 CS 341: Chapter 0 0-44 ∗∗ ∗ + Proof that S ⊆ S Positive Closure S

∗∗ ∗ To show 1, need to prove that any string w ∈ S is also in S . Definition: If S is a set of strings, then the positive closure of S is + (1) (2) (3) ∗∗ = ∪ ∪ ∪··· • Since w ∈ S ,canwritew as a concatenation of zero or more strings S S S S ∗ = { ··· | ≥ 1 ∈ } from S . w1w2 wk k and each wi S . = ··· ≥ 0 ∈ ∗ • + w w1w2 wk for some k , where each wi S . S is the set of all strings formed by concatenating one or more • ∈ ∗ strings from S. Each string wi S can be written as a concatenation of zero or more strings from S. Example: If Σ={ a },then • Thus, the original string w can be written as a concatenation of zero or + ∗ Σ = { a, aa, aaa, . . . } =Σ. more strings from S. ∗ • Since S is the collection of all strings that are concatenation of zero or Example: If S = { a, ba },then ∗ S w ∈ S + ∗ more strings from , this implies that the original string . S = { a, aa, ba, aaa, aba, baa, aaaa, aaba, . . . } = S . ∗∗ ∗ ∗∗ ∗ • Therefore, w ∈ S implies w ∈ S ,soS ⊆ S . Example: If S = { ε, a, ba },then + ∗ S = { ε, a, aa, ba, aaa, aba, baa, aaaa, aaba, . . . } = S . CS 341: Chapter 0 0-45 CS 341: Chapter 0 0-46 Functions and Operations Examples of Functions Examples: Definition: A function (or operator, operation,ormapping) f • : Z→Z maps each element in a domain D to a single element in a range R. We can define a function f as 2 f(x)=x − 5. • We denote this by f : D → R. Note that f(3) = f(−3) = 4. Remarks: • Integer addition has function g : Z×Z→Zwith • ∈ ∈ If f is a function that outputs b R when the input is a D,wewrite g(x, y)=x + y. f(a)=b. ∗ • If Σ is an alphabet, then we can define f :Σ →Z+ such that for ∗ • We say that the mapping f any string w ∈ Σ , f(w)=|w|, defined on the domain D which is the length of w. R-valued mapping. • Let Σ be an alphabet. Then we can define concatenation as the :Σ∗ × Σ∗ → Σ∗ • A real-valued function has range R ⊆R,whereR denotes the set function f with of real numbers. f(x, y)=xy

CS 341: Chapter 0 0-47 CS 341: Chapter 0 0-48 Closed Under an Operation String Reversal Definition: For any string w,thereverse of w, written as reverse(w) R Let A be some collection of objects. or w , is the same string of symbols written in reverse order. • = ··· Definition: We say that A is closed under operation f If w w1 w2 wn, where each wi is a symbol, then R = ··· if applying f to members of A always returns a member of A. w wn wn−1 w1. Examples: Examples: R R • (cat) = tac and ε = ε. •N = {1, 2, 3,...} is closed under addition. • The set A = { 0, 11, 01, 10 } is closed under reversal since R •N is not closed under subtraction since 4, 7 ∈N, but if w ∈ A,thenw ∈ A. 4 − 7=−3 ∈N. • Let B be the set of strings over Σ={0, 1, 2,...,9} such that the n • L1 = { a | n =1, 2, 3,...} is closed under concatenation. first symbol is not 0. • = { 2n+1 | =0 1 2 } R Is L2 a n , , ,... closed under concatenation? Note that 10 ∈ B, but (10) =01∈ B. Thus, B is not closed under reversal. CS 341: Chapter 0 0-49 CS 341: Chapter 0 0-50 Palindrome Defining Functions

Definition: Over the alphabet Σ={a, b}, the language Remark: Sometimes we define a function using a . PALINDROME is defined as ∗ R : {0 1 2 3 4}→{0 1 2 3 4} PALINDROME = { w ∈ Σ | w = w } Example: Consider function f , , , , , , , , as = { ε, a, b, aa, bb, aaa, aba, . . . } n f(n) 0 1 1 2 Remark: 2 3 • Strings abba, a ∈ PALINDROME, 3 4 4 0 but their concatenation abbaa is not in PALINDROME. Note that f(n)=(n +1)mod 5. • Thus, PALINDROME is not closed under concatenation. • a mod b returns the remainder after dividing a by b. • Example: 5 mod 7=5,and15 mod 7=1.

CS 341: Chapter 0 0-51 CS 341: Chapter 0 0-52 Example of Function k-ary Functions × ×···× Definition: When the domain of a function f is A1 A2 Ak Example: Let A = { ROCK, PAPER, SCISSORS } and for some sets A1,A2,...,Ak, B = { TRUE, FALSE }. Consider the function • input to function f is k-tuple beats : A × A → B ( ) ∈ × ×···× a1,a2,...,ak A1 A2 Ak, defined by the table • we call each ai an argument to f. beats ROCK PAPER SCISSORS ROCK FALSE FALSE TRUE Definition: A function f with k arguments is a k-ary function. PAPER TRUE FALSE FALSE • SCISSOR FALSE TRUE FALSE k is called the arity of f.

Definition: A unary function has arity k =1. • Then beats definesthegameRock-Paper-Scissors. • e.g., f(x)=3x +4or f(w)=|w|. • For example, =2 beats(ROCK, SCISSORS)=TRUE, Definition: A binary function has arity k beats(ROCK, PAPER)=FALSE. • e.g., beats is a binary function. CS 341: Chapter 0 0-53 CS 341: Chapter 0 0-54 Predicates and Relations Predicates Definition: A predicate or property is a function whose range is {TRUE, FALSE}, Remark: • • e.g., beats is a property. Sometimes more convenient to describe predicates with sets instead of functions.

Definition: A property whose domain is a set A ×···×A of k-tuples is • Sometimes write predicate P : D →{TRUE, FALSE } as called a relation,ak-ary relation,orak-ary relation on A. (D, S),whereS = { a ∈ D | P (a)=TRUE }, Definition: A 2-ary relation is a binary relation, or just S when domain D is obvious. • e.g., beats is a binary relation. • For example, beats canbewrittenas { (ROCK, SCISSORS), (PAPER, ROCK), (SCISSORS, PAPER) } Remark: If R is a binary relation, aRb means aRb = TRUE. which is the set { (x, y) | (x, y) ∈ D and xRy (i.e., x beats y) }. Example: For the binary relation “<”, we have 2 < 5=TRUE.

CS 341: Chapter 0 0-55 CS 341: Chapter 0 0-56 Reflexive, Symmetric and Transitive Relations

Example: Definition: A binary relation R is • Let N = {0, 1, 2,...}. • reflexive if for every x, xRx; • ≡ N×N For fixed positive integer k,definerelation k on as follows: • symmetric if for every x and y, xRy if and only if yRx; ∈N ≡ − for a, b , a k b iff a b is a multiple of k. • ≡ ( − )= ∈Z transitive if for every x, y,andz, xRy and yRz implies xRz. i.e., a k b iff a b rk,forsomer .

•≡ Definition: A binary relation is an if it is k defines the standard “modulo k”relation. reflexive, symmetric, and transitive. • Prove that this is an equivalence relation. CS 341: Chapter 0 0-57 CS 341: Chapter 0 0-58 ≡ ≡ k is an Equivalence Relation k is an Equivalence Relation • Recall: a ≡ b iff (a − b)=rk,forsomer ∈Z. k • ≡ ≡ ≡ Transitive: Show that x k y and y k z imply x k z. • ≡ Reflexive: Show that x k x. ≡ ≡ Suppose x k y and y k z. ∀ ∈N − =0=0 x , x x k. Then (x − y)=ik for some i ∈Z. 0 ∈Z ≡ Since , this shows that x k x. Also, (y − z)=jk for some j ∈Z. ≡ Therefore, k is reflexive. Thus, (x − y)+(y − z)=ik + jk. But (x − y)+(y − z)=(x − z) and ik + jk =(i + j)k. • Symmetric: Show that x ≡ y ⇒ y ≡ x. k k (i + j) ∈Zsince i ∈Zand j ∈Z. ∈N ≡ Consider x, y such that x k y. So (x − z)=(i + j)k. ( − )= ∈Z Therefore x y zk for some z by definition. Hence, x ≡ z. ( − )=− k But this means y x zk. Therefore, ≡ is transitive. − ∈Z ≡ k Since z as well, this shows that y k x. Therefore, ≡ is symmetric. • ≡ k Since k is reflexive, symmetric, and transitive, it is an equivalence relation.

CS 341: Chapter 0 0-59 CS 341: Chapter 0 0-60 Graphs Example of Directed Graph • Graph G =(V,E),where Definition: A directed graph is a set of nodes (or vertices)and V is the set of nodes of G directed edges (or arcs). E ⊆ V × V is the set of edges. 2 • For the graph below, V = {1, 2, 3}, 1 E = { (1, 2), (1, 3), (2, 3), (3, 2), (3, 3) }, G =({1, 2, 3}, { (1, 2), (1, 3), (2, 3), (3, 2), (3, 3) } ). 3 2

• In a graph G that contains nodes i and j, the pair (i, j) represents a 1 directed edge from node i to node j. • An undirected graph has undirected edges. 3 CS 341: Chapter 0 0-61 CS 341: Chapter 0 0-62 Boolean Logic Some Properties of Boolean Logic

• Boolean logic is a mathematical system built around two values: • TRUE and FALSE. The implication operator has the following truth table: • 1 0 Sometimes TRUE and FALSE are written as , . x y x → y (¬x) ∨ y • You should be familiar with 0 0 1 1 0 1 1 1 ∧ conjunction (AND), denoted by 1 0 0 0 ∨ disjunction (OR), denoted by 1 1 1 1 negation, denoted by ¬ or bar, e.g., ¬0 and 0¯ are 1 ⊕ exclusive or (XOR), denoted by • This means that an implication x → y is always true if x is false. equality operator (↔) implication operator (→) • The implication operator can be rewritten as “(not x)ory”. distributive laws

CS 341: Chapter 0 0-63 Summary of Chapter 0 • A language is a set of strings. • Kleene-star operation: ∗ = { ··· | ≥ 0 ∈ } S w1w2 wk k and each wi S . • Set operations and relations: subsets, union, equality, intersection, subtraction, complement, concatenation, cardinality, Cartesian product, power set • Functions, k-ary functions, predicates, relations • Set S is closed under a function f if applying f to elements in S always results in something in S. • Graphs • Boolean logic