Graphs:%20Definitions - PowerPoint PPT Presentation

About This Presentation
Title:

Graphs:%20Definitions

Description:

A chart of driving distances between cities of the US. A network ... a graph with two connected components. u. v. in this graph, u is not reachable from v ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 9
Provided by: vdou8
Category:

less

Transcript and Presenter's Notes

Title: Graphs:%20Definitions


1
Graphs Definitions
  • How would you represent the following?
  • A chart of driving distances between cities of
    the US
  • A network
  • The prerequisite relationship between CS classes
  • A map for the game Hunt the Wumpus
  • These problems have similar structure
  • A collection of objects (cities, computers,
    classes, caves) connected in some way (roads,
    cables, precedence relationship, doorways)

2
Graphs Definitions
  • Draw a picture where these objects are nodes
    (vertices) and the connections are links (edges)
    between vertices.
  • This picture is called a graph.
  • Formally A graph G(V,E) consists of a set V
    whose members are called vertices and a set E
    whose members are called edges and are pairs of
    distinct vertices from V.

3
Graphs Definitions
  • Adjacent vertices connected by an edge
  • An edge (u,v) is incident to vertices u and v
  • Degree of a vertex number of edges incident to
    it (or, number of adjacent vertices)
  • Path of length k a sequence (v0, v1, ...vk)
    such that (vi-1, vi)?E
  • A vertex is reachable from another if there is a
    path between them
  • Weighted graph each edge has an associated
    weight

4
Graphs Examples
w
complete graph of 5 vertices, aka K5
u
v
vertices u and v are adjacent
(u,v,w,u) is a cycle
v
a graph with two connected components
u
in this graph, u is not reachable from v
5
Graphs Representation
  • Adjacency matrix a V?V table A, such that

1, if (vi,vj)?E 0, otherwise
v1 v2 v3 v4 v5 v1 0
1 1 1 1 v2 1 0 1 0
0 v3 1 1 0 1 0 v4
1 0 1 0 1 v5 1 0 0
1 0
v1
v2
v3
v4
v5
6
Graphs Representation
  • Adjacency list an array A of V lists, one for
    each vertex. For each v?V, Av contains all the
    vertices adjacent to v.

v1
v2
v1 v2 v3 v4 v5
v2
v3
v4
v5
v1
v3
v2
v1
v4
v3
v4
v5
v1
v3
v5
v1
v4
7
Graphs Representation
  • What representation would you use for a sparse
    graph? (i.e. one that has very few edges)
  • How about a dense graph?
  • How would you modify the adjacency list/matrix
    definitions for weighted graphs?
  • How long does it take to perform the following
    operations in each representation?
  • compute the degree of a vertex
  • insert/delete a vertex
  • insert/delete an edge
  • areAdjacent(u,v)
  • How much space does each representation require?

8
Graphs Traversal
  • Searching/Traversing a graph visiting the
    vertices of a graph by following the edges in a
    systematic way
  • Example Given a highway map, find a path from
    one city to another.
  • What if the graph has cycles?
  • To avoid getting trapped in a cycle, mark the
    vertices that have already been visited.
Write a Comment
User Comments (0)
About PowerShow.com