Trees and Graphs Flashcards
1
Q
Depth-first Search (DFS)
A
Pros:
* on a binary tree, it generally requires less memory than BFS
* Can easily be implemented with recursion
Cons:
* Doesn’t necessarily find the shortest path to a specific node, while BFS does
Implementation Data Structure:
* Stack (Last in First Out - LIFO)
2
Q
Breadth-First Search (BFS)
A
Pros:
* Will find the shortest path between the starting point and any other reachable node.
Cons:
* generally requires more memory than a DFS
Implementation Data Structure:
* Queue (First in First Out or FIFO)
3
Q
A