03 Fundamentals of Algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is depth-first graph traversal?

A

Going as far down a path as possible before backtracking and going down next path e.g. used to navigate a maze

Uses a list to hold nodes visited and a stack to keep track of the last node visited

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

What is breadth-first graph traversal?

A

starts searching at a designated start node and searches through all the adjacent nodes (neighbours) before moving on e.g. commonly used to find the path containing the least number of nodes between two points in an unweighted graph

Uses a list to hold nodes visited and a queue is used to keep track of the next nodes to visit

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

What is the time complexity for DFS and BFS

A

O(n^2)

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