Sunteți pe pagina 1din 26

ALGORITHMIC GRAPH THEORY

Contents
Introduction Terminology Data Structures for the Representation of Graphs Examples of Graph Algorithms

Depth-first Search Breadth-first Search

Introduction

Since the invention of integrated circuits thirty years ago, manufacturing of electronic systems has taken rapid strides in improvement in speed, size, and cost. The manufacture of integrated circuit chips is similar to the manufacture of other highly sophisticated engineering products in many ways. The three major steps are designing the product, fabricating the product, and testing the fabricated product.

In the design step, a large number of components are to be designed or selected, specifications on how these components should be assembled are to be made, and verification steps are to be carried out to assure the correctness of the design. In the manufacturing step, a great deal of man power, and a large collection of expensive equipment, together with painstaking care are needed to assemble the product according to the design specification. Finally, the fabricated product must be tested to check its physical functionality.

As in all engineering problems, there are conflicting requirements in all these steps. In the design step, we want to obtain an optimal product design, and yet we also want the design cycle to be short. In the fabrication step, we want the product yield to be high, and yet we also need to be able to produce a large volume of the product and get them to market in time. In the testing step, we want the product to be tested thoroughly and yet we also want to be able to do so quickly. VLSI Physical Design deals with how the issue of enormous design complexity is to be handled so that high quality designs can be obtained in a reasonable amount of design time: We use muscles (automation) and we use brain (algorithms).

Terminology

Graph A graph is a mathematical structure that describes a set of objects and the set of connections between them. A graph is characterized by two sets: a vertex set V and an edge set E. It is customary to denote a graph by G(V,E), where G refers to the graph itself.
v2 e1 v1 e2 v3 e3 e4 v6 v4 v5 e5

Fig: An example of a graph.

Terminology

Subgraph - When one removes vertices and/or edges from a given graph G, one gets a subgraph of G. Degree - The degree of a vertex is equal to the number of edges incident with it. An edge (u,u), i.e. one starting and finishing at the same vertex, is called a self loop. Paralled edges - Two edges of the form e1= (v1,v2) and e2= (v1,v2), i.e. having the same endpoints, are called paralled edges. Simple graph - A graph without self loops or parallel edges is called a simple graph.

Terminology

Multigraph - A graph without self loops but with paralled edges is called a multigraph. Bipartite graph If the vertex set V of a graph is the union of two disjoint sets V1 and V2 and all edges of this graph exclusively connect a vertex from V1 with a vertex V2, the graph is called bipartite. Such a graph is often denoted by e1 G(v1,v2,E). V2,1
V1,1

e2 e3 e5

V2,2

v1,2

v2,3

Fig: An example of a bipartite graph.

Terminology

Planar/Nonplanar graph - A graph that can be drawn on a two-dimensional plane without any of its edges intersecting is called planar. Otherwise, the graph is called nonplanar. Path - A sequence of alternating vertices and edges, starting and finishing with a vertex, such that an edge e=(u ,v) is preceded by u and followed by v in the sequence (or vice versa), is called a path.

The length of a path equals the number of edges it contains. A path, of which the first and last vertices are the same and the length is larger than zero, is called a cycle/loop.

Terminology

Connected Graph - Two vertices u and v are called connected if there is a path starting at u and finishing at v. If all pairs of vertices in a graph are connected, the graph is called a connected graph. Otherwise, the graph is disconnected. Directed Graph - Sometimes a direction is associated with the edges in a graph. Such a graph is called a directed graph.
v3 e2 v4 e4 Fig: Directed Graph e5 v1 v5

e6
v2 e1

Data structures for the Representation of Graphs

If one wants to implement graph algorithms, one of the first issues to be settled is how to represent the graph in a computer. In other words, one should choose a suitable data structure for graphs. Adjacency matrix - One of the most straightforward ways to represent graphs is by means of an adjacency matrix. If the graph G(V,E) has n vertices, an n x n matrix A is used. When using the adjacency matrix, testing whether two given vertices are connected or not can be performed in constant time, i.e. the time to perform the test does not depend on the size of the graph.

However, finding all vertices connected to a given vertex requires inspection of a complete row and a complete column of the matrix. This is not very efficient when most of the entries in the matrix are equal to zero. The adjacency list representation is a better choice in such a case. Adjacency list - It consists of an array that has as many elements as the number of vertices in the graph. So, an array element identified by an index I corresponds with the vertex vi. Each array element points to a linked list that contains the indices of all vertices to which the vertex corresponding to the element is connected.

v3 e3 v4 e2 e4 e6 v2 v5 e1 e5 (a) Directed Graph v1

1 2 3

X
1 4 X 5 X 1 2 X 3 X

0 1 0 0 1

0 0 0 0 1

0 1 0 0 0

0 0 1 0 0

0 0 0 1 0

4 5

(c) Adjacency List

(b) Adjacency Matrix

struct vertex { int vertex_index; struct edge *outgoing-edges; }; struct edge { int edge_index; struct vertex *from, *to; struct edge *next; }; Fig: The data structure for a graph representation with explicit vertex and edge structures.

The choice of a suitable data structure in the implementation of a graph algorithm can be very important and may directly affect the computational effort necessary to solve some problems.

Given the characteristics of the algorithm to be implemented, one should carefully consider which of the data structures is most appropriate and how these basic data structures should be modified and extended to satisfy the requirements of the algorithm.

Examples of Algorithms

Depth-first Search: In many graph algorithms, one needs to traverse the graph in one way or the other and do something with the nodes and /or edges that one encounters during the traversal. One systematic way of doing this is by means of depth-first search. What is actually being done at each vertex and/or edge visited is not specified here. In this respect, the descriptions contain generic actions to be filled by the applications.

Depth-first Search
/* Given is the graph G(V,E) */ struct vertex { int mark; }; dfs (struct vertex v) { v.mark <- 0; process v ; for each (v , u) E{ process (v , u); if (u.mark) dfs (u); } } main( ) { for each v v.mark <- 1; for each v if (v.mark) dfs (v); } V V

Fig: A pseudo-code description of the depth-first search algorithm dfs.

Depth-first Search

The goal is to visit all vertices only once. This is achieved by introducing a member mark in the vertex structure. This member is initialized with the value 1 and given the value 0 when the vertex is visited. As the value is never restored to 1 and only the vertices whose mark members have value 1 are visited, it is guaranteed that each vertex is visited at most once.

Depth-first Search

The function dfs is a recursive function that takes a vertex as its argument. It processes the vertex (the generic vertex action) and then inspects all its outgoing edges one by one. After processing the edge, the vertex to which this edge is incident is used for a recursive call of dfs, unless the vertex had already been visited. In the main program, the function is applied to each vertex of the graph to account for the fact that not all vertices may be reachable from a single vertex.

Depth-first Search

v2 e1 v1 e2

e5 e3
e4 v3

v5
v4

v1
v2 v3 X v4 v5 X

e1 e3 e4

v2
v4 v3 X

e2 e5

v3
v5

X X

(a) A directed graph.

(b) Adjacency-list representation of (a).

Depth-first Search

dfs(v1) ->e1=(v1,v2)

dfs(v2) ->e3=(v2,v4) ->e5=(v2,v5)

dfs(v4) ->e4=(v4,v3) dfs(v5)

dfs(v3)

->e2=(v1,v3)
Fig: The different steps of the depth-first search algorithm applied to the graph of Fig (a).

Examples of Algorithms

Breadth-first Search: Breadth-first search is an alternative to depth-first search for systematically visiting all vertices of a graph.

Breadth-first Search
/*Given is the graph G(V,E)*/ struct vertex{ int mark; }; bfs ( struct vertex v) { struct fifo * Q; struct vertex u ,w ; Q<-( ); shift_in (Q ,v); do { w<-shift_out (Q); process w;
for each (w , u) E{ process (w , u); if (u.mark) { u.mark<-0; shift_in (Q , u); } } } while (Q!=0)

} main ( ) { for each v v.mark<-1; for each v if (v.mark) { v.mark<-0; bfs (v); } }

V V

Breadth-first Search

The central element in the description is the FIFO queue Q. Objects can be added and removed from such a queue in such a way that the order in which objects are removed is identical to the order in which the objects were originally added. The exact implementation is not very relevant here. It is sufficient to know that the call shift_in(q,0) adds an object 0 to the queue q, that shift_out (q) removes the oldest object from the queue q and that the empty queue is denoted by ( ) in pseudocode. Besides, one should know that adding and removing objects from a FIFO queue can be done in constant time.

Breadth-first Search
Q (v1) (v2,v3) (v3,v4,v5) (v4,v5) (v5) w v1 v2 v3 v4 v5 Edges processed e1=(v1,v2),e2=(v1,v3) e3=(v2,v4),e5=(v2,v5) e4=(v4,v3) -

Fig: The different steps of the breadth-first search algorithm

THANK YOU

S-ar putea să vă placă și