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

What is Dijkstra’s algorithm used for?

A

Finds shortest path in weighted graphs (O(V + E log V)).

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

What is the difference between Prim’s and Kruskal’s algorithms?

A

: Prim’s for dense graphs, Kruskal’s for sparse graphs (both find MST).

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

What is a topological sort, and when is it used?

A

Orders tasks when some must be done before others.

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

What is the Bellman-Ford algorithm, and how does it differ from Dijkstra’s?

A

Bellman-Ford works with negative weights.

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

What is Floyd-Warshall used for?

A

Finds shortest paths between all nodes (O(n³)).

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