Graph ADT - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Graph ADT

Description:

A path is a list of vertices {v1, v2, ..., vn} such that (vi, vi 1) E for all 0 i n. ... Connectivity. Undirected graphs are connected if ... Connectivity ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 20
Provided by: eugene86
Category:

less

Transcript and Presenter's Notes

Title: Graph ADT


1
Graph ADT
2
Introduction
  • relationships between people, things
  • callgraph - which functions call which others
  • dependence graphs - which variables are defined
    and used at which statements
  •  Computer graphics
  • Computer networks
  • Maps and Driving direction applications
  • Circuit Layout

3
Graph ADT
  • a graph G is represented as G (V, E)
  • V is a set of vertices v1, v2, , vn
  • E is a set of edges e1, e2, , em where each
    ei connects two vertices (vi1, vi2)
  • operations include
  • iterating over vertices
  • iterating over edges
  • iterating over vertices adjacent to a specific
    vertex
  • asking whether an edge exists connected two
    vertices

4
Graph Representations
  • 2-D matrix of vertices (marking edges in the
    cells)
  • adjacency matrix
  • List of vertices each with a list of adjacent
    vertices
  • adjacency list

5
Graph Representations
  • Consider the following graph, give the following
  • Mathematical representation of the graph
  • Adjacent matrix representation
  • Adjacent list representation

6
Adjacency Matrix
  • A V x V array in which an element (u, v) is
    true if and only if there is an edge from u to v

7
Adjacency List
  • A V-ary list (array) in which each entry stores
    a list (linked list) of all adjacent vertices

8
Directed Graphs
0
2
1
  • In directed graphs, edges have a specific
    direction

9
Undirected Graphs
  • In undirected graphs, The edges dont (edges are
    two-way) have direction
  • Vertices u and v are adjacent if (u, v) ? E

0
2
1
10
Weighted Graphs
Each edge has an associated weight or cost.
100
0
2
500
1
200
The weight may represent distance, driving time,
cost of building the highway, etc
11
Paths
  • A path is a list of vertices v1, v2, , vn such
    that (vi, vi1) ? E for all 0 ? i lt n.

12
Paths
  • P1 A, D, E
  • P2 B, E, D, C

100
C
30
50
50
200
10
20
150
13
Path Length and Cost
  • Path length
  • the number of edges in the path
  • Path cost
  • the sum of the costs of each edge
  • What are the path length and path cost of P1 and
    P2 on the previous slides?

14
Simple Paths
  • A simple path repeats no vertices (except that
    the first can be the last)
  • P1 A, D, E
  • P2 B, E, D, C
  • Both P1 and P2 are simple paths.

15
Cycles and Simple Cycles
  • A cycle is a path that starts and ends at the
    same node
  • p3 A, D, E, B, A is a cycle
  • A simple cycle is a cycle that repeats no
    vertices except that the first vertex is also the
    last (in undirected graphs, no edge can be
    repeated)

16
Connectivity
  • Undirected graphs are connected if there is a
    path between any two vertices

17
Connectivity
  • Directed graphs are strongly connected if there
    is a path from any one vertex to any other
  • Di-graphs are weakly connected if there is a path
    between any two vertices, ignoring direction

18
Trees as Graphs
  • Every tree is a graph with some restrictions
  • the tree is directed
  • there are no cycles (directed or undirected)
  • there is a directed path from the root to every
    node

A
B
C
D
E
F
H
G
J
I
19
Directed Acyclic Graphs (DAGs)
  • DAGs are directed graphs with no cycles.

main()
Sort()
Swap()
Assign()
Compare()
Trees ? DAGs ? Graphs
Write a Comment
User Comments (0)
About PowerShow.com