Depth first vs Breadth first search Flashcards

1
Q

What is a common use of breadth first search?

A

To find the path containing the least number of nodes between two points in an unweighted graph

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

How does a breadth first search work?

A

The algorithm starts searching at a designated start node and searches through all the adjacent nodes (neighbours) before moving on.

Uses a queue as a supporting data structure to keep track of the nodes that have not been fully explored.

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

What is a common use of depth first search?

A

Navigating a maze

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

How does a depth first search work?

A

Begins at the start node and then searches as far as possible down a branch of the graph until there are no more nodes along the current branch to be explored. If the target node is found along the way, the search can stop. Otherwise, the algorithm must backtrack and find another branch to explore.

uses a stack as each newly discovered node is inspected immediately and route can be stepped through in reverse to find a new path.

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

Difference between depth first and breadth first search?

A

. In a depth-first search, a ​branch​ is​ fully explored ​before backtracking, whereas in a breadth-first search a ​node​ is fully explored​ before venturing on to the next node.

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