0% found this document useful (0 votes)
32 views

Graph: Dr. Mohammad Ahmad

The document discusses topics related to graphs including graph terminology, types of graphs, graph representations, and graph search methods. It defines key graph concepts such as vertices, edges, paths, cycles, connected components, and spanning trees. It also covers graph representations like adjacency matrices and adjacency lists, as well as search algorithms for finding paths and connected components in graphs.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Graph: Dr. Mohammad Ahmad

The document discusses topics related to graphs including graph terminology, types of graphs, graph representations, and graph search methods. It defines key graph concepts such as vertices, edges, paths, cycles, connected components, and spanning trees. It also covers graph representations like adjacency matrices and adjacency lists, as well as search algorithms for finding paths and connected components in graphs.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 22

Graph

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

 A complete directed graph (also denoted by Kn) on n


vertices contains exactly n(n-1) edges
Path Finding
 Path between 1 and 8

• What is a possible path & its


length?
• A path is 1, 2, 5, 9, 8 and its
length is 20.
Connected Graph
 Let G = (V, E) be an undirected graph
 G is connected iff there is a path between every
pair of vertices in G
Representation of Unweighted Graphs
 The most frequently used representations for
unweighted graphs are
– Adjacency Matrix
– Linked adjacency lists
– Array adjacency lists
Adjacency Matrix
 0/1 n x n matrix, where n = # of vertices
 A(i, j) = 1 iff (i, j) is an edge.
Adjacency Matrix Properties
 Diagonal entries are zero.
 Adjacency matrix of an undirected graph is symmetric (A(i,j)
= A(j,i) for all i and j).
Adjacency Matrix for Digraph
 Diagonal entries are zero.
 Adjacency matrix of a digraph need not be symmetric.
Adjacency Lists
 Adjacency list for vertex i is a linear list of vertices adjacent
from vertex i.
 An array of n adjacency lists for each vertex of the graph.
Linked Adjacency Lists
 Each adjacency list is a chain.
Array length = n.
# of chain nodes = 2e (undirected graph)
# of chain nodes = e (digraph)
Array Adjacency Lists
 Each adjacency list is an array list.
Array length = n.
# of chain nodes = 2e (undirected graph)
# of chain nodes = e (digraph)
Representation of Weighted Graphs
 Weighted graphs are represented with simple extensions
of those used for unweighted graphs
 The cost-adjacency-matrix representation uses a matrix
C just like the adjacency-matrix representation does
 Cost-adjacency matrix: C(i, j) = cost of edge (i, j)
 Adjacency lists: each list element is a pair
(adjacent vertex, edge weight)
Graph Search Methods
Graph Search Methods
 Many graph problems solved by a search method
– Finding a path from one vertex to another.
– Determining whether a graph is connected
– Find a spanning tree
– Finding a minimum-cost path/spanning tree
 Breadth-first search (BFS)
– Method of starting at a vertex and identifying all vertices reachable
from it

 Depth-first search (DFS)


– an alternative to BFS

You might also like