Graphs: Representation and Traversals Flashcards

(5 cards)

1
Q

How can a graph be represented in memory?

A

Using adjacency lists (efficient for sparse graphs) or adjacency matrices (efficient for dense graphs).

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

What is Breadth-First Search (BFS)?

A

Explores the graph level by level using a queue. Suitable for shortest path in unweighted graphs.

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

What is Depth-First Search (DFS)?

A

Explores the graph deeply before backtracking, often implemented with recursion or a stack.

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

What is the time complexity of BFS and DFS?

A

Both have O(V + E) time complexity for a graph with V vertices and E edges.

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

What is a visited array used for in graph traversal?

A

To track already visited nodes and prevent infinite loops in cyclic graphs.

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