0% found this document useful (0 votes)
5 views5 pages

CS203 Week 11

The document covers key algorithms in graph theory, including Breadth-First Search (BFS), Depth-First Search (DFS), Topological Sorting, and Minimum Spanning Tree (MST). It details the properties, applications, and algorithms associated with each method, highlighting their significance in various computational problems. The document serves as a lecture note for a course on Design and Analysis of Algorithms.

Uploaded by

Prateek Sindhiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

CS203 Week 11

The document covers key algorithms in graph theory, including Breadth-First Search (BFS), Depth-First Search (DFS), Topological Sorting, and Minimum Spanning Tree (MST). It details the properties, applications, and algorithms associated with each method, highlighting their significance in various computational problems. The document serves as a lecture note for a course on Design and Analysis of Algorithms.

Uploaded by

Prateek Sindhiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

[CS203] Design and Analysis of Algorithms

Course Instructor: Dr. Dibyendu Roy Autumn 2023-24


Scribed by: Pratik Sindhiya (202251103) Lecture (Week:- 11)

1 Breadth-First Search (BFS)

The Breadth-First Search (BFS) relies on its ability to visit every reachable node in a graph exactly
once, systematically exploring outward from the starting node. This ensures that no reachable node
is missed and that the shortest path to each node is discovered.

Upon termination of BFS, d[v] = dist(s, v) for all vertices v.

Proof :-

Assume the converse: let’s suppose there exists a vertex v for which dist(s, v) ̸= d[v]. Let v be the
vertex with the smallest dist(s, v), where v ̸= s (as d[s] = dist(s, s) = 0).

Let δ(S, v) denote the shortest path from source S to vertex v.

δ(S, v) ≤ δ(S, u) + 1 (by the nature of shortest paths)


≤ d(u) + 1 (since δ(S, u) ≤ d(u))
≤ d(v) (since d(u) ≤ d(v))

By Lemma 2, d[v] ≥ dist(s, v), implying d[v] ≥ dist(s, v) + 1. As dist(s, v) represents the shortest
distance from s to v, there must be a neighboring vertex u of v such that dist(s, u) + 1 = dist(s, v).
This implies dist(s, u) < dist(s, v), and by our choice of v, we have dist(s, u) = d[u]. According to
Corollary 2, we then have d[v] ≤ d[u] + 1.

Therefore, d[v] ≤ dist(s, u) + 1, leading to d[v] ≤ dist(s, v). But this contradicts our initial as-
sumption that dist(s, v) ̸= d[v].

Hence, d[v] = dist(s, v) for all vertices v.

1
2 Depth-First Search (DFS) :-

Depth-First Search (DFS) is a fundamental algorithm for traversing or searching tree and graph
data structures. It works by exploring one branch as far as possible before backtracking and
exploring other branches.

Properties :-

1. Completeness :- DFS guarantees to visit all reachable nodes in a connected graph.

2. Non-optimality :- DFS does not necessarily visit the nodes in the shortest order, mak-
ing it suboptimal for finding shortest paths.

3. Space complexity :- DFS uses a stack data structure to keep track of the explored path,
leading to a space complexity of O(n).

4. Time complexity :- DFS has a time complexity of O(m + n), where m is the number
of edges and n is the number of nodes.

Applications :-
• Finding connected components in a graph

• Cycle detection

• Topological sorting

• Pathfinding (in specific cases)

• Solving mazes

• Garbage collection

Variations :-
• Iterative DFS:- Utilizes an explicit stack to implement the recursive calls, making it more
memory efficient.

• Pre-order, In-order, and Post-order DFS :- Represent different traversal orders based on the
order of visiting nodes and their children.

2
Algorithm :- Depth-First Search (DFS)

Procedure : DFS(G)
1. for each vertex u in G.V do
2. u.color ← WHITE
3. u.π ← NIL
4. end for
5. time ← 0
6. for each vertex u in G.V do
7. if u.color = WHITE then
8. DFS-VISIT(G, u)
9. end if
10. end for
11. end Procedure

Procedure : DFS-VISIT(G, u)

1. time ← time + 1 ▷ White vertex u has just been discovered


2. u.d ← time
3. u.color ← GRAY
4. for each vertex v in G.Adj[u] do
5. if v.color = WHITE then
6. v.π ← u
7. DFS-VISIT(G, v)
8. end if
9. end for
10. time ← time + 1
11. u.f ← time ▷ Blacken u; it is finished
12. u.color ← BLACK
13. end Procedure

3
3 Topological Sorting :-

Topological sorting is a fundamental algorithm used to arrange the vertices of a Directed Acyclic
Graph (DAG) in a linear order. This ordering ensures that for every directed edge (u, v), vertex u
always appears before vertex v in the sequence.

Key Properties :-

• Applicable only to DAGs (no directed cycles)

• Represents the dependency order between vertices

• Useful for various applications like task scheduling, makefile generation, and dependency
analysis

Algorithm :- TOPOLOGICAL-SORT

1. Procedure TopologicalSort(G)

2. Perform Depth-First Search (DFS) on graph G to compute finish times v.f for each vertex
v.

3. Initialize an empty linked list L.

4. Sort vertices in decreasing order of v.f and iterate through each vertex v

5. Insert v at the front of linked list L. (Insert each finished vertex at the front of the linked
list)

6. end for

7. Return the linked list L containing vertices in topological order.

8. end procedure

4 Minimum Spanning Tree (MST)


A Minimum Spanning Tree (MST) is a subset of edges in a connected, undirected, weighted graph
that connects all vertices with the minimum possible total edge weight. It represents the most
cost-effective way to connect all nodes in a network, making it crucial for various applications like
network design, communication infrastructure, and resource allocation.

4
Properties :-

• Connects all vertices in the graph


• Contains no cycles
• Has minimum total edge weight among all spanning trees

Popular MST Algorithms :-

• Prim’s Algorithm: This greedy algorithm starts with an arbitrary vertex and iteratively
adds the cheapest edge that connects the existing tree to a new vertex until all vertices are
included.
• Kruskal’s Algorithm: This greedy algorithm sorts all edges by weight and then adds them
to the MST in ascending order, ensuring inclusion only if it doesn’t create a cycle.

Applications :-

• Network design :- Optimizing the layout of communication networks, like wired or wireless
networks, by minimizing the total cable length.
• Clustering :- Grouping similar data points together by finding the minimum cost connections
between them.
• Image segmentation :- Identifying and separating different objects in an image by minimizing
the total cost of cutting edges between pixels.
• Circuit design :- Optimizing the layout of circuits by minimizing the total wire length.

Algorithm :- GENERIC-MST(G, w)

1. Procedure GENERIC-MST(G, w)
2. Let A be an empty set initially, representing the MST.
3. While A does not form a spanning tree.
4. Find an edge (u, v) that is safe to add to A. (This depends on the specific algorithm used)
5. Add the edge (u, v) to A.
6. Return A as the Minimum Spanning Tree.
7. end procedure

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy