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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly