n8 - CS 70-2 Spring 2009 Discrete Mathematics and...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 70-2 Discrete Mathematics and Probability Theory Spring 2009 Alistair Sinclair, David Tse Note 8 An Introduction to Graphs Formulating a simple, precise specification of a computational problem is often a prerequisite to writing a computer program for solving the problem. Many computational problems are best stated in terms of graphs : a directed graph G ( V , E ) consists of a finite set of vertices or nodes ) V and a set of (directed) edges E . An edge is an ordered pair of vertices ( v , w ) and is usually indicated by drawing a line between v and w , with an arrow pointing towards w . Undirected graphs may be regarded as special kinds of directed graphs, in which ( u , v ) E if and only if ( v , u ) E . Thus in an undirected graph the directions of the edges are unimportant, so an edge of an undirected graph is an unordered pair of vertices { u , v } and is indicated by a line between u and v with no arrow. More formally, the edge set of a directed graph is a subset E V × V , where V × V is the Cartesian product of V with itself. 1 As we have defined them, graphs are allowed to have self-loops ; i.e., edges of the form ( u , u ) or { u , u } that go from a vertex u to itself. Usually, however, graphs are assumed to have no self-loops unless otherwise stated, and we will assume this from now on. Graphs are useful for modeling many diverse situations. For example, the vertices of a graph might represent cities, and edges might represent highways that connect them. In this case, the edges would be undirected: In the above picture, V = { SF , LA , NY ,... } , and E = {{ SF , LA } , { SF , NY } ,... } . Alternatively, an edge might represent a flight from one city to another, and now the edges would be directed (since there may be a non-stop flight from SF to LA, but no non-stop flight back from LA to SF). Graphs can also be used to represent more abstract relationships. For example, the vertices of a graph might represent tasks, and the edges might represent precedence constraints: a directed edge from u to v says that task u must be completed before v can be started. An important problem in this context is scheduling : in what order should the tasks be scheduled so that all the precedence constraints are satisfied? A path in a directed graph G =( V , E ) is a sequence of neighboring edges ( v 1 , v 2 ) , ( v 2 , v 3 ) ,..., ( v n - 2 , v n - 1 ) , ( v n - 1 , v n ) . In this case we say that there is a path between v 1 and v n . A path in an undirected graph is defined similarly. A path is called simple if it has no repeated vertices. A cycle (or circuit ) is a path that begins and ends at the same vertex (i.e., it is a path from v to v for some v ). A graph is said to be
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/06/2009 for the course CS 70 taught by Professor Papadimitrou during the Spring '08 term at University of California, Berkeley.

Page1 / 5

n8 - CS 70-2 Spring 2009 Discrete Mathematics and...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online