Depth_First_Search_Flashcards

1
Q

Front

A

Back

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

What is the main idea behind DFS?

A

DFS explores as deep as possible along each branch before backtracking.

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

What data structure is typically used to implement DFS?

A

A stack or recursion (implicitly using the call stack).

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

What are the key attributes tracked for each node in DFS?

A

Seen (visited), Parent, Discovery Time, Finish Time.

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

What is the purpose of discovery time in DFS?

A

It marks when a node is first visited.

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

What is the purpose of finish time in DFS?

A

It marks when all descendants of a node have been fully explored.

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

How does DFS handle disconnected graphs?

A

It runs DFS from each unvisited node (using an outer loop), forming a DFS forest.

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

What is a DFS Tree?

A

A tree formed from edges used to discover new nodes during DFS.

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

What is a DFS Forest?

A

A collection of DFS trees created when the graph is disconnected.

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

What are the four types of edges in DFS?

A

Tree Edge, Back Edge, Forward Edge, Cross Edge.

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

What defines a Tree Edge in DFS?

A

An edge used to first discover a node.

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

What defines a Back Edge?

A

An edge from a descendant to an ancestor in the DFS tree.

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

What defines a Forward Edge?

A

An edge from an ancestor to a non-child descendant.

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

What defines a Cross Edge?

A

An edge between nodes in different DFS branches (neither ancestor nor descendant).

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

How can discovery and finish times identify a Back Edge (u → v)?

A

v.d < u.d < u.f < v.f

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

How can discovery and finish times identify a Forward Edge (u → v)?

A

u.d < v.d < v.f < u.f

17
Q

How can discovery and finish times identify a Cross Edge?

A

The intervals [u.d, u.f] and [v.d, v.f] are disjoint.

18
Q

What DFS edge type is critical for detecting cycles?

A

Back Edge — if one exists, the graph has a cycle.

19
Q

What is the DFS-based method to check if a graph contains a cycle?

A

Run DFS and check for any back edges.

20
Q

What makes DFS useful in graph algorithms?

A

It enables cycle detection, topological sorting, and identification of graph components.