Graph_Traversals_Breadth_First_Search_Flashcards

1
Q

Define graph traversal.

A

It is the process of visiting each node in a graph at most once by following edges.

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

How does Breadth-First Search (BFS) operate?

A

It explores nodes level-by-level, visiting all immediate neighbors before moving deeper.

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

Which data structure powers BFS?

A

A FIFO (First-In-First-Out) queue.

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

Name three key node attributes used in BFS.

A

visited (boolean), π (parent), d (depth from start).

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

What is the function of the π (parent) attribute?

A

It records the node from which the current node was discovered.

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

What does the d (depth) attribute track?

A

The number of edges from the start node to the current node.

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

What’s the first step in running BFS?

A

Mark the start node as visited, set its depth to 0, and enqueue it.

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

When do you enqueue a node in BFS?

A

You have discovered the node, but haven’t explored its neighbors yet.
1. Mark it as visited
2. Set its distance from the source
3. Record its parent in the traversal (e.g., π[v] = u).
4. Add it to the queue (e.g., queue.append(v)).

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

How does BFS ensure shortest paths?

A

By visiting nodes in increasing order of distance, it guarantees the shortest path in edge count.

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

How do you reconstruct a path using BFS?

A

Follow the parent pointers (π) from the target node back to the start.

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

What is the time complexity of BFS?

A

O(V + E), where V is vertices and E is edges.

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

What is the space complexity of BFS?

A

O(V), due to storage of visited markers, parents, depths, and the queue.

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

Can BFS be used on both directed and undirected graphs?

A

Yes, it works on both types.

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

Does BFS revisit nodes?

A

No, each node is visited only once.

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

What real-world task is similar to BFS?

A

Web crawling, such as Google indexing pages by following hyperlinks.

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

What traversal strategy does BFS represent?

A

Breadth-wise exploration—visiting all neighbors before going deeper.