graph theory - university of...

79
9/27/2016 1 Graph Theory Varying Applications (examples) Computer networks Distinguish between two chemical compounds with the same molecular formula but different structures Solve shortest path problems between cities Scheduling exams and assign channels to television stations

Upload: others

Post on 19-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

1

Graph Theory

Varying Applications (examples)

Computer networks Distinguish between two chemical compounds

with the same molecular formula but different structures

Solve shortest path problems between cities Scheduling exams and assign channels to

television stations

Page 2: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

2

Definitions - Graph

A generalization of the simple concept of a setof dots, links, edges or arcs.Representation: Graph G =(V, E) consists set of verticesdenoted by V, or by V(G) and set of edges E, or E(G)

Definitions – Edge TypeDirected: Ordered pair of vertices. Represented as (u, v)directed from vertex u to v.

Undirected: Unordered pair of vertices. Represented as {u, v}.Disregards any sense of direction and treats both end verticesinterchangeably.

u v

u v

Page 3: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

3

Definitions – Edge Type Loop: A loop is an edge whose endpoints are equal

i.e., an edge joining a vertex to it self is called a loop.Represented as {u, u} = {u}

Multiple Edges: Two or more edges joining thesame pair of vertices.

u

Definitions – Graph TypeSimple (Undirected) Graph: consists of V, a nonempty set ofvertices, and E, a set of unordered pairs of distinct elements ofV called edges (undirected)Representation Example: G(V, E), V = {u, v, w}, E = {{u, v},{v, w}, {u, w}}

u v

w

Page 4: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

4

Definitions – Graph TypeMultigraph: G(V,E), consists of set of vertices V, set ofEdges E and a function f from E to {{u, v}| u, v V, u ≠ v}.The edges e1 and e2 are called multiple or parallel edges if f(e1) = f (e2).Representation Example: V = {u, v, w}, E = {e1, e2, e3}

u

v

we1e2

e3

Definitions – Graph TypePseudograph: G(V,E), consists of set of vertices V, set of EdgesE and a function F from E to {{u, v}| u, v Î V}. Loops allowed insuch a graph.Representation Example: V = {u, v, w}, E = {e1, e2, e3, e4}

u

v

we1

e3

e2e4

Page 5: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

5

Definitions – Graph TypeDirected Graph: G(V, E), set of vertices V, and set of Edges E, that are ordered pair of elements of V (directed edges)Representation Example: G(V, E), V = {u, v, w}, E = {(u, v), (v, w), (w, u)}

u

w

v

Definitions – Graph TypeDirected Multigraph: G(V,E), consists of set of vertices V, setof Edges E and a function f from E to {{u, v}| u, v V}. Theedges e1 and e2 are multiple edges if f(e1) = f(e2)Representation Example: V = {u, v, w}, E = {e1, e2, e3, e4}

uu

u

e1e2

e3

e4

Page 6: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

6

Definitions – Graph Type

Type Edges Multiple Edges Allowed ?

Loops Allowed ?

Simple Graph undirected No No

Multigraph undirected Yes No

Pseudograph undirected Yes Yes

Directed Graph directed No Yes

Directed Multigraph

directed Yes Yes

Terminology – Undirected graphs u and v are adjacent if {u, v} is an edge, e is called incident with u and v. u

and v are called endpoints of {u, v}

Degree of Vertex (deg (v)): the number of edges incident on a vertex. A loop contributes twice to the degree (why?).

Pendant Vertex: deg (v) =1

Isolated Vertex: deg (v) = 0

Representation Example: For V = {u, v, w} , E = { {u, w}, {u, w}, (u, v) },deg (u) = 2, deg (v) = 1, deg (w) = 1, deg (k) = 0, w and v are pendant , k isisolated

uk

w

v

Page 7: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

7

Terminology – Directed graphs For the edge (u, v), u is adjacent to v OR v is adjacent from u, u – Initial

vertex, v – Terminal vertex

In-degree (deg- (u)): number of edges for which u is terminal vertex

Out-degree (deg+ (u)): number of edges for which u is initial vertex

Note: A loop contributes 1 to both in-degree and out-degree (why?)

Representation Example: For V = {u, v, w} , E = { (u, w), ( v, w), (u, v) }, deg-

(u) = 0, deg+ (u) = 2, deg- (v) = 1, deg+ (v) = 1, and deg- (w) = 2, deg+ (u) = 0

u

w

v

Theorems: Undirected Graphs

Theorem 1The Handshaking theorem:

(why?) Every edge connects 2 vertices

Vv

ve2

Page 8: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

8

Theorems: Undirected GraphsTheorem 2:An undirected graph has even number of vertices with odd degree

even

Voof

2

21

V v

1,

V vV u V v

deg(v) termsecond even also is termsecond Hence

2e. is sum sinceeven is inequalitylast the of side handright on the termslast two theof sum The

even. is inequalitylast theof side handright in the first term TheV for veven is (v) deg

deg(v) deg(u) deg(v) 2e verticesdegree odd torefers V2 and verticesdegreeeven ofset theis 1 Pr

Theorems: directed Graphs Theorem 3: deg + (u) = deg - (u) = |E|

Page 9: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

9

Simple graphs – special cases Complete graph: Kn, is the simple graph that contains exactly

one edge between each pair of distinct vertices.

Representation Example: K1, K2, K3, K4

K2K1 K4K3

Simple graphs – special cases Cycle: Cn, n ≥ 3 consists of n vertices v1, v2, v3 … vn and edges

{v1, v2}, {v2, v3}, {v3, v4} … {vn-1, vn}, {vn, v1}Representation Example: C3, C4

C3 C4

Page 10: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

10

Simple graphs – special cases Wheels: Wn, obtained by adding additional vertex to Cn and

connecting all vertices to this new vertex by new edges.

Representation Example: W3, W4

W3 W4

Simple graphs – special cases N-cubes: Qn, vertices represented by 2n bit strings of length n.

Two vertices are adjacent if and only if the bit strings that they represent differ by exactly one bit positions Representation Example: Q1, Q2

0

10

1

00

11

Q1

01

Q2

Page 11: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

11

Bipartite graphs In a simple graph G, if V can be partitioned into two disjoint

sets V1 and V2 such that every edge in the graph connects avertex in V1 and a vertex V2 (so that no edge in G connectseither two vertices in V1 or two vertices in V2)Application example: Representing RelationsRepresentation example: V1 = {v1, v2, v3} and V2 = {v4, v5, v6},

v1

v2

v3

v4

v5

v6

V1V2

Complete Bipartite graphs Km,n is the graph that has its vertex set portioned into two

subsets of m and n vertices, respectively There is an edgebetween two vertices if and only if one vertex is in the firstsubset and the other vertex is in the second subset.Representation example: K2,3, K3,3

K2,3 K3,3

Page 12: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

12

Subgraphs A subgraph of a graph G = (V, E) is a graph H =(V’, E’) where V’ is a

subset of V and E’ is a subset of EApplication example: solving sub-problems within a graphRepresentation example: V = {u, v, w}, E = ({u, v}, {v, w}, {w, u}}, H1 , H2

u

v w

uu

wv v

H1H2G

Subgraphs G = G1 U G2 wherein E = E1 U E2 and V = V1 U V2, G, G1 and G2 are

simple graphs of G

Representation example: V1 = {u, w}, E1 = {{u, w}}, V2 = {w, v},E1 = {{w, v}}, V = {u, v ,w}, E = {{{u, w}, {{w, v}}

u

vw w vw

u

G1 G2 G

Page 13: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

13

Representation Incidence (Matrix): Most useful when information about

edges is more desirable than information about vertices.

Adjacency (Matrix/List): Most useful when informationabout the vertices is more desirable than information about theedges. These two representations are also most popular sinceinformation about the vertices is often more desirable thanedges in most applications

Representation- Incidence Matrix G = (V, E) be an unditected graph. Suppose that v1, v2, v3, …, vn

are the vertices and e1, e2, …, em are the edges of G. Then theincidence matrix with respect to this ordering of V and E is the nxm matrix M = [m ij], where

Can also be used to represent :Multiple edges: by using columns with identical entries, sincethese edges are incident with the same pair of verticesLoops: by using a column with exactly one entry equal to 1,corresponding to the vertex that is incident with the loop

otherwise 0

ith vincident w is e edge when 1 m

ijij

Page 14: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

14

Representation- Incidence Matrix Representation Example: G = (V, E)

v w

ue1

e3

e2

e1 e2 e3

v 1 0 1

u 1 1 0

w 0 1 1

Representation- Adjacency Matrix There is an N x N matrix, where |V| = N , the Adjacenct Matrix

(NxN) A = [aij]

For undirected graph

For directed graph

This makes it easier to find subgraphs, and to reverse graphs if needed.

otherwise 0

G of edgean is ) v,(v if 1 a

jiij

otherwise 0

G of edgean is } v,{v if 1 a

jiij

Page 15: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

15

Representation- Adjacency Matrix Adjacency is chosen on the ordering of vertices. Hence, there

as are as many as n! such matrices. The adjacency matrix of simple graphs are symmetric (aij = aji)

(why?) When there are relatively few edges in the graph the adjacency

matrix is a sparse matrix Directed Multigraphs can be represented by using aij = number

of edges from vi to vj

Representation- Adjacency Matrix Example: Undirected Graph G (V, E)

v u w

v 0 1 1

u 1 0 1

w 1 1 0

u

v w

Page 16: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

16

Representation- Adjacency Matrix Example: directed Graph G (V, E)

v u w

v 0 1 0

u 0 0 1

w 1 0 0

u

v w

Representation- Adjacency ListEach node (vertex) has a list of which nodes (vertex) it is adjacent

Example: undirectd graph G (V, E)

u

v w

node Adjacency List

u v , w

v w, u

w u , v

Page 17: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

17

Graph - Isomorphism G1 = (V1, E2) and G2 = (V2, E2) are isomorphic if: There is a one-to-one and onto function f from V1 to

V2 with the property that a and b are adjacent in G1 if and only if f (a) and f (b) are

adjacent in G2, for all a and b in V1. Function f is called isomorphism

Application Example:In chemistry, to find if two compounds have the same

structure

Graph - IsomorphismRepresentation example: G1 = (V1, E1) , G2 = (V2, E2)f(u1) = v1, f(u2) = v4, f(u3) = v3, f(u4) = v2,

u1

u3u4

u2

v3v4

v1 v2

Page 18: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

18

Connectivity Basic Idea: In a Graph Reachability among vertices

by traversing the edgesApplication Example:- In a city to city road-network, if one city can bereached from another city.- Problems if determining whether a message can besent between two

computer using intermediate links- Efficiently planning routes for data delivery in theInternet

Connectivity – PathA Path is a sequence of edges that begins at a vertexof a graph and travels along edges of the graph,always connecting pairs of adjacent vertices.

Representation example: G = (V, E), Path Prepresented, from u to v is {{u, 1}, {1, 4}, {4, 5}, {5,v}}

1

u3

4 5

2v

Page 19: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

19

Connectivity – PathDefinition for Directed Graphs

A Path of length n (> 0) from u to v in G is a sequence of nedges e1, e2 , e3, …, en of G such that f (e1) = (xo, x1), f (e2) =(x1, x2), …, f (en) = (xn-1, xn), where x0 = u and xn = v. A path issaid to pass through x0, x1, …, xn or traverse e1, e2 , e3, …, en

For Simple Graphs, sequence is x0, x1, …, xn

In directed multigraphs when it is not necessary to distinguishbetween their edges, we can use sequence of vertices torepresent the path

Circuit/Cycle: u = v, length of path > 0

Simple Path: does not contain an edge more than once

Connectivity – ConnectednessUndirected Graph

An undirected graph is connected if there exists is asimple path between every pair of vertices

Representation Example: G (V, E) is connected sincefor V = {v1, v2, v3, v4, v5}, there exists a pathbetween {vi, vj}, 1 ≤ i, j≤ 5

v1

v2

v3

v5

v4

Page 20: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

20

Connectivity – ConnectednessUndirected Graph

Articulation Point (Cut vertex): removal of a vertexproduces a subgraph with more connected components than inthe original graph. The removal of a cut vertex from aconnected graph produces a graph that is not connected

Cut Edge: An edge whose removal produces a subgraph withmore connected components than in the original graph.Representation example: G (V, E), v3 is the articulation point oredge {v2, v3}, the number of connected components is 2 (> 1)

v1

v2

v3

v4

v5

Connectivity – ConnectednessDirected Graph A directed graph is strongly connected if there is a path from

a to b and from b to a whenever a and b are vertices in thegraph

A directed graph is weakly connected if there is a(undirected) path between every two vertices in the underlyingundirected path

A strongly connected Graph can be weakly connected but thevice-versa is not true (why?)

Page 21: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

21

Connectivity – ConnectednessDirected Graph

Representation example: G1 (Strong component), G2 (WeakComponent), G3 is undirected graph representation of G2 or G1

G2G1 G3

Connectivity – Connectedness Directed Graph

Strongly connected Components: subgraphs of a Graph G that are strongly connectedRepresentation example: G1 is the strongly connected component in G

G1G

Page 22: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

22

Isomorphism - revisitedA isomorphic invariant for simple graphs is the existence of a simple circuit of length k , k is an integer > 2 (why ?)Representation example: G1 and G2 are isomorphic since wehave the invariants, similarity in degree of nodes, number ofedges, length of circuits

G1 G2

Counting Paths Theorem: Let G be a graph with adjacency matrix A with respect to the

ordering v1, v2, …, Vn (with directed on undirected edges, with multipleedges and loops allowed). The number of different paths of length r fromVi to Vj, where r is a positive integer, equals the (i, j)th entry of(adjacency matrix) Ar.

Proof: By Mathematical Induction.

Base Case: For the case N = 1, aij =1 implies that there is a path of length 1. Thisis true since this corresponds to an edge between two vertices.

We assume that theorem is true for N = r and prove the same for N = r +1.Assume that the (i, j)th entry of Ar is the number of different paths of length r fromvi to vj. By induction hypothesis, bik is the number of paths of length r from vi to vk.

Page 23: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

23

Counting PathsCase r +1: In Ar+1 = Ar. A,

The (i, j)th entry in Ar+1 , bi1a1j + bi2 a2j + …+ bin anj

where bik is the (i, j)th entry of Ar.

By induction hypothesis, bik is the number of paths of length r from vito vk.

The (i, j)th entry in Ar+1 corresponds to the length between i and jand the length is r+1. This path is made up of length r from vi to vkand of length from vk to vj. By product rule for counting, the number ofsuch paths is bik* akj The result is bi1a1j + bi2 a2j + …+ bin anj ,thedesired result.

Counting Pathsa ------- b| || |c -------d

A = 0 1 1 0 A4 = 8 0 0 81 0 0 1 0 8 8 01 0 0 1 0 8 8 00 1 1 0 8 0 0 8

Number of paths of length 4 from a to d is (1,4) th entry of A4 = 8.

Page 24: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

24

The Seven Bridges of Königsberg, Germany

The residents of Königsberg, Germany, wondered if itwas possible to take a walking tour of the town thatcrossed each of the seven bridges over the Presel riverexactly once. Is it possible to start at some node andtake a walk that uses each edge exactly once, andends at the starting node?

The Seven Bridges of Königsberg, Germany

You can redraw the original picture as long as for every edge betweennodes i and j in the original you put an edge between nodes i and j inthe redrawn version (and you put no other edges in the redrawnversion).

Original:

2

34 1

Redrawn:4

2 3

Page 25: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

25

The Seven Bridges of Königsberg, Germany

Has no tour that uses each edge exactly once. (Even if we allow the walk to start and finish in different

places.) Can you see why?

Euler:

Euler - definitions An Eulerian path (Eulerian trail, Euler walk) in a graph is a

path that uses each edge precisely once. If such a path exists,the graph is called traversable.

An Eulerian cycle (Eulerian circuit, Euler tour) in a graphis a cycle that uses each edge precisely once. If such a cycleexists, the graph is called Eulerian (also unicursal).

Representation example: G1 has Euler path a, c, d, e, b, d, a, b

a b

c d e

Page 26: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

26

The problem in our language:

Show that is not Eulerian.

In fact, it contains no Euler trail.

Euler - theorems1. A connected graph G is Eulerian if and only if G is connected

and has no vertices of odd degree

2. A connected graph G is has an Euler trail from node a tosome other node b if and only if G is connected and a b arethe only two nodes of odd degree

Page 27: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

27

Euler – theorems (=>)Assume G has an Euler trail T from node a to node b (a and bnot necessarily distinct).

For every node besides a and b, T uses an edge to exit for each edge it uses to enter. Thus, the degree of the node is even.

1. If a = b, then a also has even degree. Euler circuit

2. If a b, then a and b both have odd degree. Euler path

Euler - theorems1. A connected graph G is Eulerian if and only if G is connected

and has no vertices of odd degree

a b

c d

e

f

Building a simple path:{a,b}, {b,c}, {c,f}, {f,a}

Euler circuit constructed if all edgesare used. True here?

Page 28: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

28

Euler - theorems1. A connected graph G is Eulerian if and only if G is connected

and has no vertices of odd degree

c d

e Delete the simple path:{a,b}, {b,c}, {c,f}, {f,a}

C is the common vertex for thissub-graph with its “parent”.

Euler - theorems1. A connected graph G is Eulerian if and only if G is connected

and has no vertices of odd degree

c d

e

Constructed subgraph may not be connected.

C is the common vertex for this sub-graph with its “parent”.

C has even degree.

Start at c and take a walk:{c,d}, {d,e}, {e,c}

Page 29: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

29

Euler - theorems1. A connected graph G is Eulerian if and only if G is connected

and has no vertices of odd degree

a b

c d

e

f“Splice” the circuits in the 2 graphs:{a,b}, {b,c}, {c,f}, {f,a}

“+”{c,d}, {d,e}, {e,c}

“=“{a,b}, {b,c}, {c,d}, {d,e}, {e,c}, {c,f}{f,a}

Euler Circuit

1. Circuit C := a circuit in G beginning at an arbitraryvertex v.

1. Add edges successively to form a path that returns to thisvertex.

2. H := G – above circuit C3. While H has edges

1. Sub-circuit sc := a circuit that begins at a vertex in H thatis also in C (e.g., vertex “c”)

2. H := H – sc (- all isolated vertices)3. Circuit := circuit C “spliced” with sub-circuit sc

4. Circuit C has the Euler circuit.

Page 30: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

30

Representation- Incidence Matrix

e1 e2 e3

a 1 0 0

b 1 1 0

c 0 1 1

d 0 0 1

e 0 0 0

f 0 0 0

a b

c d

e

f

e1

e2

e3

e4e5

e6

e7

e4 e5 e6 e7

0 0 0 1

0 0 0 0

0 1 1 0

1 0 0 0

1 1 0 0

0 0 1 1

Hamiltonian Graph Hamiltonian path (also called traceable path) is a path that visits

each vertex exactly once.

A Hamiltonian cycle (also called Hamiltonian circuit, vertex tour orgraph cycle) is a cycle that visits each vertex exactly once (except forthe starting vertex, which is visited once at the start and once again atthe end).

A graph that contains a Hamiltonian path is called a traceable graph.A graph that contains a Hamiltonian cycle is called a Hamiltoniangraph. Any Hamiltonian cycle can be converted to a Hamiltonian pathby removing one of its edges, but a Hamiltonian path can be extendedto Hamiltonian cycle only if its endpoints are adjacent.

Page 31: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

31

A graph of the vertices of a dodecahedron.

Is it Hamiltonian?

Yes.

This one has a Hamiltonian path, but not aHamiltonian tour.

Hamiltonian Graph

Page 32: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

32

Hamiltonian Graph

This one has an Euler tour, but no Hamiltonian path.

Hamiltonian Graph Similar notions may be defined for directed graphs, where edges (arcs)

of a path or a cycle are required to point in the same direction, i.e.,connected tail-to-head.

The Hamiltonian cycle problem or Hamiltonian circuit problem in graphtheory is to find a Hamiltonian cycle in a given graph. The Hamiltonianpath problem is to find a Hamiltonian path in a given graph.

There is a simple relation between the two problems. The Hamiltonianpath problem for graph G is equivalent to the Hamiltonian cycleproblem in a graph H obtained from G by adding a new vertex andconnecting it to all vertices of G.

Both problems are NP-complete. However, certain classes of graphsalways contain Hamiltonian paths. For example, it is known that everytournament has an odd number of Hamiltonian paths.

Page 33: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

33

Hamiltonian Graph DIRAC’S Theorem: if G is a simple graph with n

vertices with n ≥ 3 such that the degree of everyvertex in G is at least n/2 then G has a Hamiltoncircuit.

ORE’S Theorem: if G is a simple graph with nvertices with n ≥ 3 such that deg (u) + deg (v) ≥ nfro every pair of nonadjacent vertices u and v in G,then G has a Hamilton circuit.

Shortest Path Generalize distance to weighted setting Digraph G = (V,E) with weight function W: E R (assigning

real values to edges) Weight of path p = v1 v2 … vk is

Shortest path = a path of the minimum weight Applications

static/dynamic network routing robot motion planning map/route generation in traffic

1

11

( ) ( , )k

i ii

w p w v v

Page 34: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

34

Shortest-Path Problems Shortest-Path problems

Single-source (single-destination). Find a shortest path from a given source (vertex s) to each of the vertices. The topic of this lecture.

Single-pair. Given two vertices, find a shortest path between them. Solution to single-source problem solves this problem efficiently, too.

All-pairs. Find shortest-paths for every pair of vertices. Dynamic programming algorithm.

Unweighted shortest-paths – BFS.

Optimal Substructure Theorem: subpaths of shortest paths

are shortest paths Proof (”cut and paste”)

if some subpath were not the shortest path, one could substitute the shorter subpath and create a shorter total path

Page 35: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

35

Negative Weights and Cycles? Negative edges are OK, as long as there are no

negative weight cycles (otherwise paths with arbitrary small “lengths” would be possible)

Shortest-paths can have no cycles (otherwise we could improve them by removing cycles) Any shortest-path in graph G can be no longer

than n – 1 edges, where n is the number of vertices

Shortest Path Tree The result of the algorithms – a shortest path tree. For each

vertex v, it records a shortest path from the start vertex s to v.

v.parent() gives a predecessor of v in this shortest path gives a shortest path length from s to v, which is recorded in

v.d(). The same pseudo-code assumptions are used. Vertex ADT with operations:

adjacent():VertexSet d():int and setd(k:int) parent():Vertex and setparent(p:Vertex)

Page 36: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

36

Relaxation For each vertex v in the graph, we maintain v.d(), the estimate

of the shortest path from s, initialized to at the start Relaxing an edge (u,v) means testing whether we can improve

the shortest path to v found so far by going through u

5u v

vu

2

2

9

5 7

Relax(u,v)

5u v

vu

2

2

6

5 6

Relax(u,v)

Relax (u,v,G)if v.d() > u.d()+G.w(u,v) then

v.setd(u.d()+G.w(u,v))v.setparent(u)

Dijkstra's Algorithm Non-negative edge weights Greedy, similar to Prim's algorithm for MST Like breadth-first search (if all weights = 1, one can simply use

BFS) Use Q, a priority queue ADT keyed by v.d() (BFS used FIFO

queue, here we use a PQ, which is re-organized whenever some d decreases)

Basic idea maintain a set S of solved vertices at each step select "closest" vertex u, add it to S, and relax

all edges from u

Page 37: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

37

Dijkstra’s ALgorithmSolution to Single-source (single-destination).

Input: Graph G, start vertex s

relaxing edges

Dijkstra(G,s)01 for each vertex u G.V()02 u.setd()03 u.setparent(NIL)04 s.setd(0)05 S // Set S is used to explain the

algorithm06 Q.init(G.V()) // Q is a priority queue ADT07 while not Q.isEmpty()08 u Q.extractMin()09 S S {u}10 for each v u.adjacent() do11 Relax(u, v, G)12 Q.modifyKey(v)

Dijkstra’s Example

0s

u v

yx

10

5

1

2 3 94 67

2

10

5

0s

u v

yx

10

5

1

2 3 94 67

2

Dijkstra(G,s)01 for each vertex u G.V()02 u.setd()03 u.setparent(NIL)04 s.setd(0)05 S 06 Q.init(G.V())07 while not Q.isEmpty()08 u Q.extractMin()09 S S {u}10 for each v u.adjacent() do11 Relax(u, v, G)12 Q.modifyKey(v)

Page 38: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

38

Dijkstra’s Exampleu v

8 14

5 7

0s

yx

10

5

1

2 3 94 67

2

8 13

5 7

0s

u v

yx

10

5

1

2 3 94 67

2

Dijkstra(G,s)01 for each vertex u G.V()02 u.setd()03 u.setparent(NIL)04 s.setd(0)05 S 06 Q.init(G.V())07 while not Q.isEmpty()08 u Q.extractMin()09 S S {u}10 for each v u.adjacent() do11 Relax(u, v, G)12 Q.modifyKey(v)

Dijkstra’s Example8 9

5 7

0

u v

yx

10

5

1

2 3 94 67

2

8 9

5 7

0

u v

yx

10

5

1

2 3 94 67

2

Dijkstra(G,s)01 for each vertex u G.V()02 u.setd()03 u.setparent(NIL)04 s.setd(0)05 S 06 Q.init(G.V())07 while not Q.isEmpty()08 u Q.extractMin()09 S S {u}10 for each v u.adjacent() do11 Relax(u, v, G)12 Q.modifyKey(v)

Page 39: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

39

Dijkstra’s Algorithm O(n2) operations

(n-1) iterations: 1 for each vertex added to the distinguished set S.

(n-1) iterations: for each adjacent vertex of the one added to the distinguished set.

Note: it is single source – single destination algorithm

Traveling Salesman Problem Given a number of cities and the costs of traveling from one to

the other, what is the cheapest roundtrip route that visits each city once and then returns to the starting city?

An equivalent formulation in terms of graph theory is: Find the Hamiltonian cycle with the least weight in a weighted graph.

It can be shown that the requirement of returning to the starting city does not change the computational complexity of the problem.

A related problem is the (bottleneck TSP): Find the Hamiltonian cycle in a weighted graph with the minimal length of the longest edge.

Page 40: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

40

Planar Graphs A graph (or multigraph) G is called planar if G can be drawn in the plane with

its edges intersecting only at vertices of G, such a drawing of G is called anembedding of G in the plane.

Application Example: VLSI design (overlapping edges requires extra layers), Circuit design (cannot overlap wires on board)

Representation examples: K1,K2,K3,K4 are planar, Kn for n>4 are non-planar

K4

Planar Graphs Representation examples: Q3

Page 41: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

41

Planar Graphs Representation examples: K3,3 is Nonplanar

v1 v2

v5v4

v3

v6

v1

v2v4v4

v5 v1

v2

v5

v3

R1R2

R21R1

R22

Theorem : Euler's planar graph theorem

For a connected planar graph or multigraph: v – e + r = 2

numberof vertices

numberof edges

numberof regions

Planar Graphs

Page 42: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

42

Planar GraphsExample of Euler’s theorem

K4R1

R2

R3

A planar graph divides the planeinto several regions (faces), one of them is the infinite region.

v=4,e=6,r=4, v-e+r=2

R4

Planar Graphs Proof of Euler’s formula: By Induction

Base Case: for G1 , e1 = 1, v1 = 2 and r1= 1

n+1 Case: Assume, rn = en – vn + 2 is true. Let {an+1, bn+1} be the edge that is added to Gn to obtain Gn+1 and we prove that rn = en –vn + 2 is true. Can be proved using two cases.

R1v

u

Page 43: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

43

Planar Graphs Case 1:

rn+1 = rn + 1, en+1 = en + 1, vn+1 = vn => rn+1 = en+1 – vn+1 + 2

R

an+1

bn+1

Planar Graphs Case 2:

rn+1 = rn, en+1 = en + 1, vn+1 = vn + 1 => rn+1 = en+1 – vn+1 + 2

R

an+1

bn+1

Page 44: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

44

Planar GraphsCorollary 1: Let G = (V, E) be a connected simple planar graph with |V| = v, |E| = e > 2, and r regions. Then 3r ≤ 2e and e ≤ 3v – 6Proof: Since G is loop-free and is not a multigraph, the boundary ofeach region (including the infinite region) contains at least threeedges. Hence, each region has degree ≥ 3.Degree of region: No. of edges on its boundary; 1 edge may occurtwice on boundary -> contributes 2 to the region degree.Each edge occurs exactly twice: either in the same region or in 2different regions

R

an+1

bn+1

Region Degree

R

R

Degree of R = 3

Degree of R = ?

Page 45: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

45

Planar GraphsEach edge occurs exactly twice: either in the same region or in 2different regions2e = sum of degree of r regions determined by 2e2e ≥ 3r. (since each region has a degree of at least 3)r ≤ (2/3) eFrom Euler’s theorem, 2 = v – e + r2 ≤ v – e + 2e/32 ≤ v – e/3So 6 ≤ 3v – eor e ≤ 3v – 6

Planar GraphsCorollary 2: Let G = (V, E) be a connected simple planar graph then G has a vertex degree that does not exceed 5Proof: If G has one or two vertices the result is trueIf G has 3 or more vertices then by Corollary 1, e ≤ 3v – 62e ≤ 6v – 12If the degree of every vertex were at least 6:

by Handshaking theorem: 2e = Sum (deg(v)) 2e ≥ 6v. But this contradicts the inequality 2e ≤ 6v – 12There must be at least one vertex with degree no greater than 5

Page 46: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

46

Planar GraphsCorollary 3: Let G = (V, E) be a connected simple planar graph with v vertices ( v ≥ 3) , e edges, and no circuits of length 3 then e ≤ 2v -4Proof: Similar to Corollary 1 except the fact that no circuits of length3 imply that degree of region must be at least 4.

Planar Graphs Elementary sub-division: Operation in which a graph are

obtained by removing an edge {u, v} and adding the vertex wand edges {u, w}, {w, v}

Homeomorphic Graphs: Graphs G1 and G2 are termed ashomeomorphic if they are obtained by sequence of elementarysub-divisions.

u v u vw

Page 47: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

47

Planar Graphs Kuwratoski’s Theorem: A graph is non-planar if and only if it

contains a subgraph homeomorephic to K3,3 or K5Representation Example: G is Nonplanar

a b

c

j

d

i

e

gf

k

ba

c

e

d

fg

h

G

H K5

e

d

c

ba

Graph Coloring Problem Graph coloring is an assignment of "colors", almost always

taken to be consecutive integers starting from 1 without loss ofgenerality, to certain objects in a graph. Such objects can bevertices, edges, faces, or a mixture of the above.

Application examples: scheduling, register allocation in amicroprocessor, frequency assignment in mobile radios, andpattern matching

Page 48: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

48

Vertex Coloring Problem Assignment of colors to the vertices of the graph such that proper

coloring takes place (no two adjacent vertices are assigned the samecolor)

Chromatic number: least number of colors needed to color the graph A graph that can be assigned a (proper) k-coloring is k-colorable, and

it is k-chromatic if its chromatic number is exactly k.

Vertex Coloring Problem The problem of finding a minimum coloring of a graph is NP-Hard The corresponding decision problem (Is there a coloring which uses at

most k colors?) is NP-complete The chromatic number for Cn = 3 (n is odd) or 2 (n is even), Kn = n,

Km,n = 2 Cn: cycle with n vertices; Kn: fully connected graph with n vertices;

Km,n: complete bipartite graph

C5 K4 K2, 3

C4

Page 49: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

49

Vertex Covering Problem The Four color theorem: the chromatic number of a planar

graph is no greater than 4 Example: G1 chromatic number = 3, G2 chromatic number = 4 (Most proofs rely on case by case analysis).

G1 G2

Trees

Page 50: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

50

Rooted Trees

Rooted Trees

These terms are illustrated in the following Figure of Rooted Tree

Page 51: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

51

Rooted Trees

Example

Binary Trees

Page 52: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

52

Representation of Algebraic Expressions

a/b a/(c+d)

((a − b)·c) + (d/e)

Spanning Trees and Shortest Paths

An East Coast airline company wants to expand service to theMidwest and has received permission from the Federal AviationAuthority to fly any of the routes shown in Figure

Page 53: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

53

Spanning Trees and Shortest Paths

The fact is that the graph of any system of routes that satisfies thecompany’s wishes is a tree, because if the graph were to contain a circuit,then one of the routes in the circuit could be removed withoutdisconnecting the graph, and that would give a smaller total number ofroutes. But any tree with eight vertices has seven edges. Therefore, anysystem of routes that connects all eight vertices and yet minimizes thetotal number of routes consists of seven routes.

Spanning Trees and Shortest Paths

DefinitionA spanning tree for a graph G is a subgraph ofG that contains every vertex of G and is a tree.

Theorem1. Every connected graph has a spanning tree.

2. Any two spanning trees for a graph have the samenumber of edges.

Page 54: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

54

Spanning TreesExample

Find all spanning trees for the graph G pictured below.

SolutionThe graph G has one circuit v2v1v4v2, and removal of any edge of the circuit gives a tree. Thus, as shown below, there are three spanning

trees for G.

Minimum Spanning TreesNow suppose the airline company wants to serve all the cities shown, butwith a route system that minimizes the total mileage.

More generally, a graph whose edges are labeled with numbers (known asweights) is called a weighed graph. A minimum-weight spanning tree, orsimply a minimum spanning tree, is a spanning tree for which the sum of theweights of all the edges is as small as possible.

Page 55: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

55

Minimum Spanning Trees

In Kruskal’s algorithm, the edges of a connectedweighted graph are examined one by Courtesy ofJoseph Kruskal (born 1928) one in order of increasingweight. At each stage the edge being examined isadded to what will become the minimum spanning tree,provided that this addition does not create a circuit.After n − 1 edges have been added (where n is thenumber of vertices of the graph), these edges, togetherwith the vertices of the graph, form a minimumspanning tree for the graph.

Kruskal’s Algorithm

Page 56: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

56

Kruskal’s Algorithm

Kruskal’s AlgorithmDescribe the action of Kruskal’s algorithm on the graph shown in Figure,where n = 8.

Page 57: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

57

Kruskal’s Algorithm

Kruskal’s Algorithm

Page 58: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

58

Prim’s Algorithm

Prim’s algorithm works differently from Kruskal’s. Itbuilds a minimum spanning tree T Courtesy of Alcatel-Lucent Technologies Robert Prim (born 1921) byexpanding outward in connected links from somevertex. One edge and one vertex are added at eachstage. The edge added is the one of least weight thatconnects the vertices already in T with those not in T ,and the vertex is the endpoint of this edge that is notalready in T .

Prim’s Algorithm

Page 59: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

59

Describe the action of Prim’s algorithm for the graph in Figure using theMinneapolis vertex as a starting point.

Prim’s Algorithm

Prim’s Algorithm

Page 60: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

60

Finding Minimum Spanning TreesExampleFind all minimum spanning trees for the following graph. Use Kruskal’salgorithm and Prim’s algorithm starting at vertex a. Indicate the order inwhich edges are added to form each tree.

SolutionWhen Kruskal’s algorithm is applied, edges are added in one of thefollowing two orders:

Finding Minimum Spanning TreesWhen Prim’s algorithm is applied starting at a, edges are added in one ofthe following two orders:

Thus, as shown below, there are two distinct minimum spanning trees forthis graph.

Page 61: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

61

Reference Books• Discrete Mathematics and its Applications

(with Combinatorics and Graph Theory)6th Edition, The McGraw-Hill Companies, 2007, Kenneth

H. Rosen.• Discrete Mathematics with Applications

2nd Edition, Thomson Learning, 1995,Susanna S. Epp.

• Discrete Mathematics for Computer Scientists 2nd Edition, Addison-Wesley, 1999, John

Truss.

BOOLEAN ALGEBRA

Discrete Mathematics and Its Applications

Page 62: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

62

The English mathematician George Boole (1815-1864) sought to give symbolic form to Aristotle's system of logic.

Boole wrote a treatise on the subject in 1854, titled An Investigation of the Laws of Thought, on Which Are Founded the Mathematical Theories of Logic and Probabilities, which codified several rules of relationship between mathematical quantities limited to one of two possible values: true or false, 1 or 0.

His mathematical system became known as Boolean algebra.

INTRODUCTION

All arithmetic operations performed with Boolean quantities have but one of two possible outcomes: either 1 or 0. There is no such thing as "2" or "-1" or "1/2" in the Boolean world.

It is a world in which all other possibilities are invalid by fiat. As one might guess, this is not the kind of math you want to use when balancing a checkbook or calculating current through a resistor.

However, Claude Shannon of MIT fame recognized how Boolean algebra could be applied to on-and-off circuits, where all signals are characterized as either "high" (1) or "low" (0). His 1938 thesis, titled A Symbolic Analysis of Relay and Switching Circuits, put Boole's theoretical work to use in a way Boole never could have imagined, giving us a powerful mathematical tool for designing and analyzing digital circuits. (http://www.databanker.org/Home/BoolAlg/tabid/53/Default.aspx)

Page 63: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

63

The rules of logic are used to design circuits and form the basis for Boolean algebra. The circuits in all electronic devices like computers have inputs that can be identified as either 1 or 0 to produce outputs labeled as 1s and 0s OR switches that are in ‘on’ or in ‘off’ position.

Boolean algebra provides the operations and the rules for working with the set {0,1}. The operation of a circuit is defined by a Boolean function that specifies the value of an output for each set of inputs. This function is built using Boolean expressions and operations.

OPERATIONS IN BOOLEAN ALGEBRA

COMPLEMENTATIONThe complement of an element, denoted with a bar, is defined by:

BOOLEAN SUMThe Boolean sum, denoted by + or by OR, has the following values:

BOOLEAN PRODUCTThe Boolean product, denoted by or by AND, has the following values:

10 01

111 110 101 000

111 010 001 000

Page 64: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

64

Unless parentheses are used, all complements are computed first followed by Boolean products, then followed by all Boolean sums.

The complement, Boolean sum, and the Boolean product correspond to the logical operators , ,respectively where 0 is False and 1 is True.

Example: Find the value of .)10(01

,,

Rules of Precedence for Boolean Operators

BOOLEAN FUNCTION

Let Then

is the set of all possible n-tuples of 0’s and 1’s.

The variable is called a Boolean variable if it assumes values only from B, i.e., if its only possible values are 0 and 1. A function from to is called a Boolean function of degree n.

}.1,0{B ) niforBxxxxxB in

n 1:,,,, 321

nB B

Page 65: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

65

Example: The function from the set of ordered pairs of Boolean variables to the set {0,1} is a Boolean function of degree 2 with the values of as

shown in the table.

1 1 01 0 10 1 00 0 0

yxyxF ),(

F

x y ),( yxF

Clearly,

0)0,0(;0)1,0(;1)0,1(;0)1,1( FFFF

The Boolean expressions in the variables

are defined recursively as

are Boolean expressions; if and are Boolean expressions, then, and are Boolean expressions.

Each Boolean expression represents a Boolean function. The values of this function are obtained by substituting 0 and 1 for the variables in the expression.

nxxxx ,,,, 321

,1,0 nxxxx ,,,, 321

1E 2E

)211 , EEE

)21 EE

Page 66: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

66

Example: Find the values of the Boolean function represented by

1 1 1 1 0 11 1 0 1 1 11 0 1 0 0 01 0 0 0 1 10 1 1 0 0 00 1 0 0 1 10 0 1 0 0 00 0 0 0 1 1

zxyzyxF ),,(

x y z xy z zxy

Remark:Two different Boolean expressions that represent the same function are equivalent.

Examples: and are equivalent.,0, xyxy 1xy

DUALITY and COMPLEMENT

The dual of a Boolean expression denoted by , is obtained by interchanging Boolean sums and Boolean products, and interchanging 0’s and 1’s. The dual of the function will be denoted by .

Example: Find the dual of and .

For , the dual is .For , the dual is .

The complement of the function is the function That is,

de

FdF

)0( yx

)zyx 1)0( yx

)1 yx )zyx 1 ) )zyx 0

F .F),,,(),,( 3,21,3,21 nn xxxxFxxxxF

Page 67: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

67

IDENTITIES

1. Digital computers contain circuits that implement Boolean functions.

2. The simpler that we can make a Boolean function, the smaller the circuit that will result.

Simpler circuits are cheaper to build, consume less power, and run faster than complex circuits.

3. With this in mind, we always want to reduce our Boolean functions to their simplest form.

4. There are a number of Boolean identities that help us to do this.

Most Boolean identities have an AND (product) form as well as an OR (sum) form. We give our identities using both forms.

Page 68: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

68

Remark: The above identities can be translated to logical equivalences about propositions and to identities about sets.

We can use Boolean identities to simplify the function

as follows:

Page 69: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

69

Example: Find the complement of the function

Applying DeMorgan’s Laws,

OR, you can take the complement of the function by taking its dual, then complement each literal (a variable or its complement).

REPRESENTATION OF BOOLEAN FUNCTIONSPROBLEM: Given the values of a Boolean function, how can a Boolean expression

that represents this function be found?Any Boolean function can be represented by a Boolean sum of Boolean

products of the variables and their complements.

Example: Find Boolean expressions that represents functions andwhich are given in the following table.

),,( zyxF),,( zyxG

1 1 1 0 01 1 0 0 11 0 1 1 01 0 0 0 00 1 1 0 00 1 0 0 10 0 1 0 00 0 0 0 0

x y z F G

Page 70: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

70

To represent , we need an expression that has the value 1. A combination of values of the variables for which the function has the value 1 leads to a Boolean product of the variables or their complements. From the table, has the value 1 when

and , and the value 0 otherwise. To form the Boolean product that has the value 1, is obtained. What about function ?

F

F

1 zx 0yzyx

G

CANONICAL FORMS of a Boolean FunctionDEFINITION

A literal is a Boolean variable or its complement. A minterm is a Boolean product of n literals, with one literal for each variable. A minterm is the standard product.

A minterm has the value 1 for one and only combination of values of its variables.

Example: Find a minterm that equals 1 if and and equal 0 otherwise.

A minterm that has the value 1 is .

Given a Boolean function, a Boolean sum of Boolean products (minterms) or simply, sum of minterms, can be formed that has the value 1 when this Boolean function has the value 1, and has the value 0 when the function has the value 0.

031 xx 1542 xxx

54321 xxxxx

Page 71: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

71

The minterms in this Boolean sum correspond to those combinations of values for which the function has the value 1. The sum of minterms that represents this function is called the sum-of-products expansion or the disjunctive normal form (DNF) of the Boolean function.

Example: Find the sum-of-products expansion for the function .

The sum-of-products expansion of the function can be done in two ways:

1. Use the Boolean identities to expand the product and simplify.

zyxzyxF )(),,(

zyxzyxF )(),,( zyzx zyzx 11

zyxxzyyx )()( zyxzxyzyxzxy

zyxzyxzxy

2. Construct a table and form the Boolean sum of minterms that have the value 1.

Based on the table, the sum-of-terms expansion for the Boolean function is .

1 1 1 1 0 01 1 0 1 1 11 0 1 1 0 01 0 0 1 1 10 1 1 1 0 00 1 0 1 1 110 0 1 0 0 00 0 0 0 1 0

x y z yx z zyx )(

zyxzyxzxyzyxF ),,(

Page 72: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

72

It is also possible to get a Boolean expression that represents a Boolean function by taking a Boolean product of Boolean sums (maxterms). The maxterms in this Boolean product correspond to those combinations of values for which the function has the value 0. The resulting expansion is called the product-of-sums expansion or the conjunctive normal form (CNF) of the function.

A maxterm is the standard sum. A maxterm has the value 0 for one and only combination of values of its variables.

A minterm is the complement of a maxterm, and vice versa.

To get the CNF for : 1. Take the complement .2. Obtain the DNF for .3. Complement both sides of the DNF obtained in (2) .

Boolean functions expressed as a sum of minterms (DNF) or product of maxterms (CNF), are said to be in canonical form.

FF

F

Minterms & Maxtermsfor 3 Binary Variables

Minterms Maxtermsx y z Term Term

0 0 0 x’y’z’ x+y+z0 0 1 x’y’z x+y+z’

0 1 0 x’yz’ x+y’+z0 1 1 x’yz x+y’+z’

1 0 0 xy’z’ x’+y+z

1 0 1 xy’z x’+y+z’1 1 0 xyz’ x’+y’+z

1 1 1 xyz x’+y’+z’

Page 73: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

73

LOGIC GATES

1. Boolean Algebra is used to model circuitry of electronic devices.

2. Each circuit is designed using the rules of Boolean Algebra.3. The basic elements of circuits are called gates.4. Each type of gate implements a Boolean operation.5. The circuits give output that depends only on the input. 6. Circuits have no memory capabilities.7. These circuits are called combinational circuits or gating

networks and can be constructed using a combination of gates that may share inputs.

8. Each input (entering a gate) and each output (leaving a gate) of a circuit is a member of the set .}1,0{

Basic types of Gates

x F0 11 0

Accepts the value of one Boolean variable as input and produces the complement of

this value as output.

Inverter or NOT Gate

Page 74: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

74

AND Gate

The inputs to this gate are 2 or more Boolean variables. The output is the

Boolean product of their values.

x y F0 0 00 1 01 0 01 1 1

OR Gate

The inputs to this gate are the values of 2 or more Boolean variables. The output is

the Boolean sum of their values.

x y F0 0 00 1 11 0 11 1 1

Page 75: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

75

NAND Gate

x y F0 0 10 1 11 0 11 1 0

NOR Gate

x y F0 0 10 1 11 0 11 1 0

Page 76: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

76

XOR Gate

x y F0 0 00 1 11 0 11 1 0

XNOR Gate

x y F0 0 10 1 01 0 01 1 1

Page 77: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

77

Discrete Mathematical Structures: Theory and Applications

Discrete Mathematical Structures: Theory and Applications

Page 78: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

78

Discrete Mathematical Structures: Theory and Applications

Discrete Mathematical Structures: Theory and Applications

Page 79: Graph Theory - University of Kashmircs.uok.edu.in/Files/79755f07-9550-4aeb-bd6f-5d802d56b46d/Custo… · Graph Theory Varying Applications (examples) ... m,n is the graph that has

9/27/2016

79

Discrete Mathematical Structures: Theory and Applications

Examples1. Find two ways to draw the same circuit that produces the

output

2. Construct circuits that produce the following outputs:

a. b. c.

3. Construct a circuit using NAND gates only to produce the following outputs.

a. b. c.

.yxxy

xyx )( )( zyx ))(( zyxzyx

x xy yx