Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Data structure & algorithms (BFS & DFS notes)

Rating
-
Sold
-
Pages
40
Uploaded on
06-09-2025
Written in
2024/2025

This document provides a concise comparison and detailed explanation of the BFS (Breadth-First Search) and DFS (Depth-First Search) algorithms. It covers the basic concepts, high-level steps, and applications of each, including their role in solving the shortest path problem. The document also includes information on advanced topics like Dijkstra's and Bellman-Ford algorithms, their complexity analysis, and provides pseudocode for practical implementation. This is a valuable resource for students studying graph traversal algorithms.

Show more Read less
Institution
Course

Content preview

Data Structures and Algorithm
(CC-2042)
Lecture 31
E N G R. D R B I L A L A S H FA Q A H M E D
S C H O O L O F S Y S T E M S A N D T E C H N O LO GY ( S S T )
C O M P U T E R S C I E N C E FA C U LT Y

,Breadth-First Search (BFS)
Breadth-First Search (BFS) is a fundamental graph traversal algorithm that
explores a graph in “layers.”
Key Concept
•Starting Point: You choose a source vertex.
•Layer-by-Layer Exploration:
• Visit all direct neighbors of the source (distance 1).
• Then, for each neighbor, visit their unvisited neighbors (distance 2), and so on
• This naturally proceeds in “layers” from the source.

This approach guarantees that you discover vertices in order of their distan
(in edges) from the source.



09/06/2025 DS

,How It Works (Algorithm Steps)
Initialization:
 Mark all vertices as “not visited.”
 Use a queue data structure to keep track of vertices to process.
Enqueue Source:
 Mark the source vertex as visited and enqueue it.
Main Loop:
 While the queue is not empty:
 Dequeue a vertex u.
 Process u (e.g., print it or record its order).
 For each unvisited neighbor v of u:
 Mark v as visited.
 Enqueue v.
Terminate when the queue is empty (no more vertices to explore).



09/06/2025 DS

, Shortest Path (Unweighted
Graph)
Distance Layers: In an unweighted graph, BFS naturally finds the shortes
number of edges between the source and every other reachable vertex.
Reason: By the time BFS reaches a vertex, it has taken the minimum
possible steps from the source (due to the layer-by-layer exploration).




09/06/2025 DS

Written for

Institution
Course

Document information

Uploaded on
September 6, 2025
Number of pages
40
Written in
2024/2025
Type
Class notes
Professor(s)
Dr.bilal ashfaq
Contains
Class no.12

Subjects

$12.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
hafizhasc

Also available in package deal

Get to know the seller

Seller avatar
hafizhasc umt
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
6 months
Number of followers
1
Documents
19
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions