Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leolanese/dd5a196c183d9fb21942ae4f39a0911c to your computer and use it in GitHub Desktop.
Save leolanese/dd5a196c183d9fb21942ae4f39a0911c to your computer and use it in GitHub Desktop.
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