Graphs Flashcards
1
Q
What is the difference between BFS and DFS?
A
BFS explores level by level (queue), DFS goes deep first (stack).
2
Q
What data structure is used for BFS?
A
Queue.
3
Q
What data structure is used for DFS?
A
Stack (or recursion).
4
Q
How can we detect cycles in a graph?
A
Use DFS or Union-Find.
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).
6
Q
A