Sei sulla pagina 1di 4

Graphs

CS 107
Theory of Automata
Chapter 01

A graph is composed of edges E and vertices V that link the vertices together. A graph G is often denoted G=(V,E). Two types of graphs: Directed graphs: G=(V,E) where E is composed of ordered pairs of vertices; i.e. the edges have direction and point from one vertex to another. Also called digraphs. Undirected graphs: G=(V,E) where E is composed of unordered pairs of vertices; i.e. the edges are bidirectional.
CJD

Fundamentals

Directed Graph

Undirected Graph

2 5

2 5

CJD

CJD

Graph Terminology
The degree of a vertex in an undirected graph is the number of edges that leave/enter the vertex. The degree of a vertex in a directed graph is the same, but we distinguish between in-degree and out-degree. Degree = in-degree + out-degree. A path in a graph is a sequence of nodes connected by edges A path from u to v is <u, w1, , wn, v> where (u,w1), (w1,w2), (w2,w3), , (wn,v) are edges of the graph.

Graph Terminology
An undirected graph is connected if every two nodes have a path between them A directed graph is strongly connected if a path connects every two nodes in both directions A path is a cycle if it starts and ends in the same node A simple cycle is one that contains at least three nodes and repeats only the first and last nodes A graph is a tree if it is connected and has no simple cycles
CJD CJD

Trees
An ordered directed tree is a digraph where There is one vertex called the root that has no predecessors, and from which there is a path to every vertex. Each vertex other than the root has exactly one direct predecessor, called its parent. The direct successors (the children) of each vertex are ordered from left to right.
<subject> <noun phrase> <adjective> the <noun phrase>

Example Tree
<sentence> <predicate> <verb phrase> <verb> <adverbial phrase>

<adjective>

<noun phrase>

jumped <preposition> <noun phrase> over <adjective> <noun phrase>

quick <adjective> <noun phrase> brown <noun>

the <adjective> <noun phrase>

fox

lazy

<noun> dog

CJD

CJD

Equivalence Relations
A relation R on a set S that is reflexive, symmetric and transitive is an equivalence relation. An equivalence relation partitions S into disjoint non-empty equivalence classes.
Examples : 1. S = dates, x,yS, xRymonth(x)=month(y). 12 equivalence classes, one for each month. [May 7, 1611] is the equivalence class that represents all dates in May. [May 7, 1611] [May 31, 2012]. 2. S = integers, x,yS, xRy|x|=|y|. Infinite number of equivalence classes. [0]={0}, [3][-3]={-3,3}.
CJD

Proof by Induction
Essential for proving recursively defined objects We can perform induction on integers, automata, and concepts like trees and graphs. To make an inductive proof about a statement S(X) we need to prove two things: Basis: Prove for one or several small values of X directly. Inductive step: Assume S(Y) for Y smaller than" X; then prove S(X) using that assumption.
CJD

An Induction Example
For all n 0, prove that:

An Inductive Proof
Inductive Step : Assume formula is true up to n = k 0.

n( n + 1) i = 2 i =1
Inductive Proof: Basis : Let n=0. Then, the sum is over no terms and therefore the sum is 0. That is:

i =
i =1

k ( k + 1) 2

Prove formula is true when n = k+1. That is, show that :

i =
i =1

k +1

(k + 1)(k + 2) k 2 + 3k + 2 = 2 2

But

i = 0 =
i =1

0(0 + 1) 2
Done !
CJD

i = i + (k + 1) =
i =1 i =1

k +1

k (k + 1) + ( k + 1) 2

k (k + 1) + 2(k + 1) ( k + 2)(k + 1) k 2 + 3k + 2 = = 2 2 2
CJD

Induction Example 2
Prove : If x 4 then 2x x2 Basis : If x=4, then 2x = 16 and x2 = 16. Thus, the theorem holds. Induction : Suppose for some x 4 that 2x x2. With this statement as the hypothesis, we need to prove the same statement, with x+1 in place of x: 2(x+1) (x+1)2 2x

Induction Example 2
Assume 2(x+1) (x+1)2 (x+1) = 22x 2x2 . Consider 2 We want 2x2 (x+1)2 . For what values of x is this true? 2x2 (x2+2x+1) ? x2 2x+1 ? 1 2/x + 1/x2 which is true when x 4. The right side gets even smaller when x increases. Hence, 2(x+1) = 22x 2x2 (x+1)2 whenever x 4. Thus, the statement is proved by induction.
CJD CJD

x2 .Show

Alphabets
An alphabet is a finite, nonempty set of symbols. Let the notation denote an alphabet. Examples = {0,1} the binary alphabet = {a,b} = {a,b,c, z} the set of all lowercase English letters

Strings
A string (or word) is a finite sequence of symbols chosen from an alphabet. Ex: 010101010, 1, 0000 and 1111 are strings over the binary alphabet. The empty string is the string with no symbols. { } and { } {} The length |w| of the string w indicates how many symbols are in that string. Ex: the string 0101 has a length of 4. |0101| = 4 and || = 0
CJD CJD

Naming Convention
Let us agree to use numbers and the first letters as symbols : Ex. 0, 1, a, b, c, d Variables like x are used to denote strings Ex. Let x = abbb Let us agree to use the last letters as string variables. Ex. u, v, w, x, y, z

Concatenation and Exponents


The concatenation of two strings is the string formed by writing the first, then the second, with no intervening space. Ex. The concatenation of bud and get is budget. For any string w, then w = w = w. Exponents concatenate a symbol or string with itself n times. Ex: a2 = aa and a3 = aaa, etc. If x = ab, then x0 = x1 = x = ab x2 = xx = abab We use parentheses for grouping exponentiations (assuming that does not contain the parentheses) (ab)7 = ababababababab
CJD CJD

Powers of an Alphabet
k is the set of all strings of length k, with symbols from Ex: Given the alphabet = {0,1,2} then: 0 = {} 1 = {0,1,2} 2 = {00,01,02,10,11,12,20,21,22} 3 = {000,001,002,... 222} Note that and 1 are different. The first is the alphabet; its members are the symbols 0,1,2. The second is the set of strings whose members are the strings 0,1,2, each a string of length 1.

Kleene Star
The Kleene Star or Kleene Closure of an alphabet , written as *, is the language of all strings over * 0 1 2

= ...

{a}* is the set of all strings of zero or more as: {a}* = {, a, aa, aaa, } {a,b}* is the set of all strings of zero or more symbols, each of which is either a or b {a,b}* = {, a, b, aa, ab, ba, bb, aaa, } x * means x is a string over * is infinite The following is * excluding the empty string :

+ = 1 2 3 ...
CJD CJD

Languages
A language is a set of strings that is a subset of *. Languages may or may not include all strings in *. Languages may be finite or infinite. All our alphabets are finite, and all our strings are finite in length, but most of the languages we are interested in are infinite (i.e. contains an infinite number of strings.)
CJD

Example Languages
The language L1 of all strings consisting of n 0s followed by n 1s, for each n0 is L1 = { , 01, 0011, 000111, } The language L2 of binary prime numbers is L2 = { 10, 11, 101, 111, } is the empty language. There are no strings in this language. {} is the language consisting of only one element: the empty string. Note that this is not the same as .
CJD

Set-Forming Notation
The set L = { w | p(w) } is the set of all strings w with property p. For example: { w | w consists of an equal number of 0s and 1s }. { w | w is a binary integer that is prime } Let n be a natural number: i.e., integers 0 { 0n1n | n 1 }. This includes 01, 0011, 000111 but not { 0n1 | n 0 }. This includes 1, 01, 001, 0001, 00001, etc. { x {a, b}* | |x| 2} = {, a, b, aa, bb, ab, ba} { xy | x {a, aa} and y {b, bb}} = {ab, abb, aab, aabb} {(ab)n} = {, ab, abab, ababab, abababab, ...} {anbn} = {, ab, aabb, aaabbb, aaaabbbb, ...}
CJD

End

CJD

Potrebbero piacerti anche