Graphs I
Graphs I
Chapter 10
Graphs and Graph Models
Data Structure
Introduction
• A graph G consist of
1. Set of vertices V (called nodes), V = {v1, v2, v3, v4......} and
2. Set of edges E={e1, e2, e3......}
• A graph can be represented as G = (V, E), where V is a finite
and non empty set of vertices and E is a set of pairs of vertices
called edges
• Each edge ‘e’ in E is identified with a unique pair (a, b) of
nodes in V, denoted by e = {a, b}
Data Structure
Formal definition of graphs
• A graph G is :
G=(V,E)
V(G): a finite, nonempty set of vertices
E(G): a set of edges (pairs of vertices)
Data Structure
• Consider the following graph, G
• Then the vertex V and edge E can be represented as:
V = {v1, v2, v3, v4, v5, v6} and E = {e1, e2, e3, e4, e5, e6}
G = {(v1, v2) (v2, v3) (v1, v3) (v3, v4),(v3, v5) (v5, v6)}
• There are six edges and vertex in the graph
Data Structure
Applications
• Computer networks
– Local area network
– Wide area network
– Internet
• Databases
– Entity-relationship diagram
Data Structure
Applications
• Transportation networks
– Highway network
– Flight network
JFK
LAX STL
HNL
DFW
FTL
Data Structure
• Graphs can be classified as:
– Directed graphs
– Undirected graphs
Data Structure
Directed vs. Undirected Graphs
• When the edges in a graph have no direction,
the graph is called undirected
Data Structure
Directed vs. Undirected Graphs
• When the edges in a graph have a direction, the
graph is called directed (or digraph)
Multigraphs
Simple Graphs
Simple Graph
• Definition: A graph in which each edge
connects two different vertices and where no
two edges connects the same pair of vertices
is called a “Simple Graph”.
Detroit
New York
San Francisco
Chicago
Denver Washington
Los Angeles
Multigraph
• A multigraph can have multiple edges (two or
more edges connecting the same pair of
vertices).
Detroit
New York
San Francisco
Chicago
Denver Washington
Los Angeles
Directed
Multigraphs
Directed Graphs
Directed Graph
• When a directed graph has no loops and no
multiple directed edges, it is called simple
directed graph
Directed Multigraph
• A directed multigraph is a directed graph with
multiple edges between the same two distinct
vertices
• It may contain loops as well.
Graph Models
• Graphs can be used to model structures,
sequences, and other relationships.
• Example: the Web graph
• The World Wide Web can be modeled as a
directed graph where:
– Each Web page is represented by a vertex
– An edge starts at the Web page a and ends at
the Web page b if there is a link on a pointing
to b.
Precedence Graphs
• Computer programs can be executed more
rapidly by executing certain statements
concurrently
• It is important not to execute a statement that
requires results of statements not yet executed
– Each statement is represented by a vertex,
– There is an edge from one statement to a second
statement if the second statement cannot be
executed before the first statement
Precedence Graphs
Graph Terminology
a g f e
(u, v)
e d f