Terminology
Graph ADT
Data Structures
Reading: 12.1-12.2
COSC 2011, Summer 2004
Definition
• A graph is a pair (V, E), where
– V is a set of nodes, called vertices
– E is a collection of pairs of vertices, called edges
• Both are objects (i.e. store data)
G
E
B
F
A
Vertex city computer web page airport C
D
COSC 2011, Summer 2004
H
Edge
road cable hyperlink flight Example Applications
•
•
•
•
•
Electronic circuits
– Printed circuit board
– Integrated circuit
Transportation networks
– Highway network
– Flight network
Computer networks
– Local area network
– Internet
– Web
Databases
– Entity-relationship diagram
Questions
– Are two points connected?
– What is the shortest path between them? cslab1a
cslab1b math.brown.edu cs.brown.edu
brown.edu qwest.net att.net
cox.net
John
Paul
COSC 2011, Summer 2004
David
Types of edges
• Undirected edge {u,v}
– Does not indicate direction
– We can “travel” in either direction
A
B
• Directed edge (u,v)
– Has a direction
A
– We can only “travel” in one direction along the edge
B
• Self-loop
– Edge that originates and ends at the same vertex
• Parallel edges
A
– Two undirected edges with same end vertices
– Two directed edges with same origin and destination
COSC 2011, Summer 2004
A
B
Types of graphs
• Undirected graph
– All edges are undirected
• Directed graph
– All edges are directed
• Mixed graph
– Has both directed and undirected edges
• Simple graph
– No parallel edges and self-loops
COSC 2011, Summer 2004
Example find route from C to G
G
E
B
F
A
C
D
H
G
E
B
F
A
C
D
COSC 2011, Summer 2004
H
Vertices and Edges
•
•
•
•
•
•
End vertices (or endpoints) of an edge
– U and V are the endpoints of a
Edges incident on a vertex - all edges that have the vertex as endpoint
– a, d, and b are incident on V
Adjacent vertices - endpoints of the same edge
– U and V are adjacent
Degree of a vertex - number of edges incident
V
h b a
– X has degree 5
Parallel edges
U
X