Rédigé par des étudiants ayant réussi Disponible immédiatement après paiement Lire en ligne ou en PDF Mauvais document ? Échangez-le gratuitement 4,6 TrustPilot
logo-home
Notes de cours

Data structure & algorithms (BFS & DFS notes)

Note
-
Vendu
-
Pages
40
Publié le
06-09-2025
Écrit en
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.

Montrer plus Lire moins
Établissement
Cours

Aperçu du contenu

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

École, étude et sujet

Établissement
Cours

Infos sur le Document

Publié le
6 septembre 2025
Nombre de pages
40
Écrit en
2024/2025
Type
Notes de cours
Professeur(s)
Dr.bilal ashfaq
Contient
Class no.12

Sujets

$12.49
Accéder à l'intégralité du document:

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Faites connaissance avec le vendeur
Seller avatar
hafizhasc

Document également disponible en groupe

Faites connaissance avec le vendeur

Seller avatar
hafizhasc umt
S'abonner Vous devez être connecté afin de suivre les étudiants ou les cours
Vendu
-
Membre depuis
6 mois
Nombre de followers
1
Documents
19
Dernière vente
-

0.0

0 revues

5
0
4
0
3
0
2
0
1
0

Documents populaires

Récemment consulté par vous

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions