forked from mishasaggi/toy-problem-workshop-tree-traversal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplications.js
More file actions
45 lines (27 loc) · 1.26 KB
/
applications.js
File metadata and controls
45 lines (27 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Some applications of DF:
1. Detecting cycle in a graph
A graph has cycle if and only if we see a back edge during DFS.
So we can run DFS for the graph and check for back edges.
2. Topological Sorting
Some applications of BF:
1. Peer to Peer Networks. In Peer to Peer Networks like BitTorrent, BFS is used to find all neighbor nodes.
2. Crawlers in Search Engines: Crawlers build index using Bread First.
The idea is to start from source page and follow all links from source and
keep doing same. Depth First Traversal can also be used for crawlers,
but the advantage with Breadth First Traversal is that the depth or levels of
built tree can be limited.
3. Social Networking Websites: In social networks, we can find people within a
given distance ‘k’ from a person using Breadth First Search till ‘k’ levels.
4. GPS Navigation systems: BFS is used to find all neighboring locations.
Many algorithms like Prim’s Minimum Spanning Tree and Dijkstra’s Single Source Shortest Path use structure similar to Breadth First Search.
Problem 1: Make a binary search tree
Problem 2: Duplicate a binary tree
Problem 3: Make a game tree to help select chess moves
Problem 4: Delete a binary tree (freeing all nodes)
Answer:
1 :
2 :
3 :
4 :
*/