1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

13
1 EC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm

Transcript of 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

Page 1: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

1ELEC692 Fall 2004 Lecture 1b

ELEC692 Lecture 1a Introduction to graph theory and

algorithm

Page 2: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

2ELEC692 Fall 2004 Lecture 1b

Graphs A graph G(V,E) is a pair (V,E) where V is a set of vertices

and E is a binary relation on V which is called the edges of the graph.

In a directed graph, the edges are ordered pairs or vertices; in an undirected graph, the edges are unordered pairs.

Degree of a vertex (node) = number of edges incident to it. Hypergraph - extension of a graph where edges may be

incident to any number of vertices,

Undirected graph directed graph Hypergraph

Page 3: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

3ELEC692 Fall 2004 Lecture 1b

Undirected Graphs (I)

A vertex is adjacent to another if there is an edge incident to both of them.

Loop-an edge with two identical end-points A graph is simple if it has no loop and two

edges link the same vertex pair. Otherwise it is called multi-graph.

A walk is an alternating sequence of vertices and edges and a trail is a walk with distinct edges and a path is a trail with distinct vertices.

A cycle is a closed walk with distinct vertices. A graph is connected if all vertex pairs are

joined by a path. A graph with no cycles is called an acyclic

graph.

a b

c d

1

2

3

4 5

loop

a is adjacent to bThe graph is simple ifthe loop is removed.(a,1,b,2,d,5,a,1) is a walk.(a,1,b,2,d,5,a,4) is a trail.(a,1,b,2,d,3,c,4) is a path.(a,1,b,2,d,5,a) is a cycle.The graph is a connected.It is not an acyclic graph.

Page 4: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

4ELEC692 Fall 2004 Lecture 1b

Undirected Graphs (II) A tree is a connected acyclic graph. A rooted

tree is a tree with a distinct vertex called root. Vertices of a tree are called nodes. Nodes that

are only connected to one vertex are called leaves.

A cutset is a minimal set of edges whose removal from the graph makes it disconnected. Similarly a vertex separation set is a minimal set of vertex whose removal from the graph makes it disconnected.

A complete graph is one such that each vertex pair is joined by an edge. A complement of a graph G(V,E) is a graph with V and two vertices are adjacent iff they are not adjacent in G.

A bipartite graph is a graph where the vertex set can be partitioned into 2 subsets such that each edge has end-points in different subsets.

a b

c d

1

24

root

leaves

1a b

c d24

3

56

A complete graph{1,4,6} is a cutset{a} is a vertex sep. set

a b

c d24

56

Page 5: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

5ELEC692 Fall 2004 Lecture 1b

Undirected Graphs (III) A subgraph of a graph V(G,E) is a

graph whose vertex and edge sets are contained in the vertex and edges set of G. Give a vertex set U contains in V, the subgraph induced by U is the maximal subgraph of G(V,E), whose edges have end-points in U.

A clique of a graph is a complete subgraph.

A clique is maximal when it is not contained in other clique.

A graph is planar if it has a diagram on a plane surface such that no two edges cross.

Two graphs are said to be isomorphic if there is a one-to-one correspondence between their vertex sets that preserves adjacency.

maximalclique clique

planar

isomorphic

Page 6: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

6ELEC692 Fall 2004 Lecture 1b

Directed Graph

For any directed edge (vi, vj), vertex vj is called the head and vi is the tail.

The indegree of a vertex is the number of edges where it is the head, the outdegree the number of edges where it is the tail.

Directed acyclic graphs (DAGS) represent partially ordered sets. In a DAG, a vertex vj is called the successor (or descendant) of a vertex vi if vj is the head of a path whose tail is vi.

A polar dag is a graph having two distinguished vertices, a source and a sink and where all vertices are reachable from the source and where the sink are reachable from all vertices.

Directed and undirected graphs can be weighted. Weights can be associated with vertices and/or with edges.

Page 7: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

7ELEC692 Fall 2004 Lecture 1b

Matrix Representation

Incidence matrix and adjacency matrix.

1 2

4 3

a

b

c

d e

a b c d e1234

-1 0 0 -1 -11 -1 0 0 00 1 -1 0 10 0 1 1 0

Incidence matrix

1 2 3 41234

0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 0

Adjacency matrix

Page 8: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

8ELEC692 Fall 2004 Lecture 1b

Graph optimization problems and algorithms - Shortest/Longest path

Model Directed graph G(V,E) with N vertices Weights on each edge A source vertex

Single source shortest path problem find shortest path from the source to any vertex Inconsistent problem:

negative-weighted cycles Bellman’s equations:path weight to a vertex in terms of

the path weight to its direct predecessors:

)(

)(

min

min

)(: ,

kikEvvk

kikik

i

ws

wss

ik

Page 9: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

9ELEC692 Fall 2004 Lecture 1b

Shortest Path Problem Acyclic graphs:

Topological sort O(n2), All positive weights - Dikstra’s algorithm (greedy)

Complexity = O(|E| + |V| log |V|)

)(min kikjk

i wss

Dijkstra (G(V,E,W)){ s0 = 0; all other si = infinity for (i= 1 to N)

si = w0,i; repeat {

select unmarked vq s.t. sq is minimal;mark vq ;foreach (unmarked vertex vi ) si = min{si ,(sq + wq,i)}}

until (all vertices are marked)}

Page 10: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

10ELEC692 Fall 2004 Lecture 1b

Example- Dikstra’s algorithm

0

u

x y

s10 1

2 35

2

79 4 6 0

u

x y

s10 1

23

5

2

79 4 6

v v

v

0

u

x y

s10 1

2 35

2

79 4 6

v

0

u

x y

s10 1

2 35

2

79 4 6

10

5 5

8 14

7

5 7

8 13v

0

u

x y

s10 1

2 35

2

79 4 6

5 7

8 9v

0

u

x y

s10 1

2 35

2

79 4 6

5 7

8 9

Page 11: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

11ELEC692 Fall 2004 Lecture 1b

Shortest Path Problem

Graph has cycles and sign of weights is not restricted. Bellman-Ford algorithm - solve Bellman’s equation by

relaxation. Complexity O(|V||E|) < O(n3)Bellman_ford (G(V,E,W)){ s0

1 = 0; for (i= 1 to N)

si1 = w0,i;

for( j= 1 to N)for (i=1 to N)

}if (si

j+1 = = sij for all i } return (TRUE);

}return (FALSE)}

)}(,{ ,1 min iq

jk

ji

ik

ji wsss

Page 12: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

12ELEC692 Fall 2004 Lecture 1b

Lonest Path Problem

Use shortest path algorithms: by reversing signs on weights

Modify algorithms: by changing min with max

Remarks: Dijkstra’s algorithm is not relevant Inconsistent problem

positive-weighted cycles

Page 13: 1 ELEC692 Fall 2004 Lecture 1b ELEC692 Lecture 1a Introduction to graph theory and algorithm.

13ELEC692 Fall 2004 Lecture 1b

Example - Bellman-Ford

1

2

0 3

6-1-3-11

-1 -4

Iteration 0: l0 = 0; l1 = -3; l2 =-1; l3 =

Iteration 1: l0 = 0; l1 = -3; l2 =-2; l3 =-5

Iteration 2: l0 = 0; l1 = -3; l2 =-2; l3 =-6

Iteration 3: l0 = 0; l1 = -3; l2 =-2; l3 =-6