Graph: Dr. Mohammad Ahmad
Graph: Dr. Mohammad Ahmad
Lecture 5
Dr. Mohammad Ahmad
Topics related to Graphs
Graph terminology: vertex, edge, adjacent, degree, cycle,
path, connected component, spanning tree
Types of graphs: undirected, directed, weighted
Graph representations: adjacency matrix, array adjacency
lists, linked adjacency lists
Graph search methods: breath-first, depth-first search
Algorithms:
– to find a path in a graph
– to find the connected components of an undirected graph
Graphs
G = (V,E)
V is the vertex set.
Vertices are also called nodes and points.
E is the edge set.
Each edge connects two vertices.
Edges are also called arcs and lines.
Vertices i and j are adjacent vertices iff (i, j) is an edge in
the graph
The edge (i, j) is incident on the vertices i and j
Graphs
Undirected edge has no orientation (no arrow head)
Directed edge has an orientation (has an arrow head)
Undirected graph – all edges are undirected
Directed graph – all edges are directed
u v u v
undirected edge directed edge
Path and Simple Path
A sequence of vertices P = i1, i2, …, ik is an i1 to ik
path in the graph G=(V, E) iff the edge (ij, ij+1) is in
E for every j, 1≤ j < k
Length (Cost) of a Path
Each edge in a graph may have an associated length (or
cost). The length of a path is the sum of the lengths of the
edges on the path
What is the length of the path 5, 9, 11, 10?
Subgraph & Cycle
Let G = (V, E) be an undirected graph
A graph H is a subgraph of graph G iff its vertex and edge
sets are subsets of those of G
A cycle is a simple path with the same start and end vertex
Spanning Tree
Let G = (V, E) be an undirected graph
A connected undirected graph that contains no cycles is a
tree
A subgraph of G that contains all the vertices of G and is a
tree is a spanning tree
A spanning tree has n vertices and n-1 edges
The spanning tree that costs the least is called the
minimum-cost spanning tree
Graph Properties
The degree of vertex i is the no. of edges incident on
vertex i.
The sum of vertex degrees = 2e (where e is the number of
edges)
In-degree of vertex i is the number of edges
incident to i
Out-degree of vertex i is the number of edges
incident from i
Complete Undirected/Directed Graphs
A complete undirected graph has n(n-1)/2 edges (i.e., all
possible edges) and is denoted by Kn