Elementary Graph Algorithms
Elementary Graph Algorithms
Algorithms
This presentation introduces fundamental graph algorithms. We will
cover concepts like graph representation, traversal methods, and
applications of graph algorithms.
by Aftab Kapsi
Introduction to Graphs
What is a Graph? Types of Graphs
A graph is a data structure representing connections Graphs can be directed (edges have direction) or
between objects. It consists of nodes (vertices) and edges undirected (edges have no direction). Graphs can also be
that connect them. weighted (edges have associated values).
Representation of Graphs
Adjacency List Adjacency Matrix
Each node maintains a list of A matrix where rows and
its adjacent nodes. Efficient columns represent nodes,
for sparse graphs. and cells indicate
connections. Efficient for
dense graphs.
Depth-First Search (DFS)
Tree Structure
DFS explores the graph in a depth-first manner, creating
a tree structure.
Stack
Uses a stack to keep track of the nodes to be visited.
Applications
Finding connected components, cycle detection,
topological sorting.
Breadth-First Search (BFS)
1 Level-by-Level
BFS explores the graph level-by-level, starting from a
source node.
2 Queue
Uses a queue to manage nodes at each level.
3 Applications
Shortest paths in unweighted graphs, finding
connected components.
Shortest Path Algorithms
Kruskal's Algorithm
2
Greedy approach, adding edges in ascending order of weight.
Prim's Algorithm
3 Starts with a single node and iteratively adds the
nearest node.
Topological Sorting
DAG Requirement
1
Applicable only to Directed Acyclic Graphs (DAGs), where there are no cycles.
Linear Ordering
2
Produces a linear ordering of nodes, respecting dependencies.
Applications
3
Task scheduling, dependency management.
Strongly Connected
Components
1 2
Definition Kosaraju's Algorithm
A strongly connected component Efficient algorithm for finding
(SCC) in a directed graph is a SCCs in a directed graph.
subgraph where every pair of
nodes has a path between them.
Applications of Graph Algorithms