Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Graph Search: Understanding Breadth-First Search (BFS) and Depth-First Search (DFS), Study Guides, Projects, Research of Communication

An overview of graph search algorithms, specifically Breadth-First Search (BFS) and Depth-First Search (DFS). It discusses their usage in various networks such as transportation, communication, information, and social networks. The document also covers the BFS algorithm, its running time, and applications, as well as DFS, its algorithm, running time, and applications. The document concludes with a comparison of BFS and DFS trees.

Typology: Study Guides, Projects, Research

2021/2022

Uploaded on 09/12/2022

amlay
amlay 🇺🇸

4.1

(18)

12 documents

1 / 41

Toggle sidebar

Related documents


Partial preview of the text

Download Graph Search: Understanding Breadth-First Search (BFS) and Depth-First Search (DFS) and more Study Guides, Projects, Research Communication in PDF only on Docsity! GRAPH SEARCH BFS & DFS By: Parminder Benipal Usage 2 !  Transportation networks (airline carrier, airports as node and direct flights as edges (direct edge). !  Communication networks (a collection of computers as nodes and the physical link between them as edges). !  Information networks (World Wide Web can be viewed as directed graph, the Web pages are nodes and the hyperlink between the pages are directed edges). !  Social Network (People are nodes and friendship is an edge). Breadth-First Search (BFS) C G H S D E F B A 5 Breadth-First Search (BFS) C G H S D E F B A 6 Breadth-First Search (BFS) C G H S D E F B A 7 Breadth-First Search (BFS) C G H S D E F B A 10 Breadth-First Search (BFS) C G H S D E F B A 11 Breadth-First Search (BFS) C G H S D E F B A 12 Breadth-First Search (BFS) C G H S D E F B A 15 Breadth-First Search (BFS) C G H S D E F B A {A B S C G D E F H} 16 Tree after BFS run C G H S D E F B A 17 BFS Applications !  Breadth-first search can be used to solve many problems in graph theory, for example: ¤  Finding all nodes within one connected component ¤ Finding the shortest path between two nodes u and v ¤ Finding the diameter of a graph (seen in assignment). ¤ Testing a graph for bipartiteness (how ?). If there are two vertices x,y in the same level (layer) L_i that are adjacent then the graph is not bipartite. ¤ More… 20 Depth-First Search (DFS) 21 !  We don’t visit the nodes level by level! As long as there is an unvisited node adjacent to the current visited node we continue! Once we are stuck, trace back and go to a different branch! Depth-First Search (DFS) C G H S D E F B A 22 Depth-First Search (DFS) C G H S D E F B A 25 Depth-First Search (DFS) C G H S D E F B A 26 Depth-First Search (DFS) C G H S D E F B A 27 Depth-First Search (DFS) C G H S D E F B A 30 Depth-First Search (DFS) C G H S D E F B A {A B S C D E H G F} 31 Edges of G that are not in DFS C G H S D E F B A 32 Depth-First Algorithm using Stack DFS(s) 1.Initialize S to be a stack with element s only. 2. While S is not empty 3. Take a node u from top of S. 4. If Explored[u] =false then 5. Set Explored[u]=true 6 For every uv edge add v to S. DFS running time 1)  If we represent the graph G by adjacency matrix then the running time of DFS algorithm is O(n ), where n is the number of nodes. 2)  If we represent the graph G by link lists then the running time of DFS algorithm is O(m + n), where m is the number of edges and n is the number of nodes. 2 36 DFS Applications !  We use DFS to find a cycle or shortest cycle. We also use DFS to find strong components in digraph (used in Tarjan’s algorithm) 37 BFS & DFS Example 40 !  Previous example shows that if there is a cycle in graph G then the BFS tree and DFS tree are different. THANKS }
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved