Graphs Flashcards

1
Q

What is the difference between BFS and DFS?

A

BFS explores level by level (queue), DFS goes deep first (stack).

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

What data structure is used for BFS?

A

Queue.

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

What data structure is used for DFS?

A

Stack (or recursion).

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

How can we detect cycles in a graph?

A

Use DFS or Union-Find.

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

What is the difference between an adjacency matrix and an adjacency list?

A

Matrix uses O(V²) space; List is O(V + E).

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