Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Depth First Search Data Structures algorithm (DFS)
## DFS & BFS:
DFS = storing the vertices "stacks", stacks are LIFO (push, pop).
BFS = storing the vertices "queue", queues are FIFO (shift, unshift or enqueue and dequeue).
## Why to use BFS and DFS?
#### DFS = memory requirements than BFS. It will take a lot of memory to traverse deeper trees while it works well with wider trees.
commonly used when you need to search the entire tree.
#### BFS = is better for deeper trees since it will take a lot more memory to operate on wider trees.
## When to use BFS and DFS?
#### DFS can also be implemented using recursion and often used in simulations of games.
In a typical game you can choose one of several possible actions
#### BFS can be used for BitTorrent, GPS systems to find nearby locations, social networking sites
to find people in the specified distance and things like that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment