BFS DFS Flashcards

1
Q

What’s DFS stands for ?

A

Depth First Search

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

What’s BFS stands for ?

A

Breadth First Sreach

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

What’s BFS ?

A

It is a vertex-based technique for finding the shortest path in the graph.

BFS is a traversal approach in which we first walk through all nodes on the same level before moving on to the next level.

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

What’s DFS

A

is an edge-based technique.

DFS is also a traversal approach in which the traverse begins at the root node and proceeds through the nodes as far as possible until we reach the node with no unvisited nearby nodes.

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

Do this with DFS :
A
/ \
B C
/ / \
D E F

A

A, B, C, D, E, F

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

Do this with BFS :
A
/ \
B C
/ / \
D E F

A

A, B, C, D, E, F

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

Which data structures use DFS ? BFS?

A

BFS(Breadth First Search) uses Queue data structure for finding the shortest path.

DFS(Depth First Search) uses Stack data structure.

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

Which approach use DFS? BFS?

A

BFS: It works on the concept of FIFO (First In First Out).

DFS: It works on the concept of LIFO (Last In First Out).

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

Suitablity for both

A

BFS: BFS considers all neighbors first and therefore not suitable for decision-making trees used in games or puzzles.

DFS:DFS is more suitable for game or puzzle problems. We make a decision, and the then explore all paths through this decision. And if this decision leads to win situation, we stop.

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

Visiting of Siblings/ Children for both

A

In BFS : siblings are visited before the children.

In DFS : children are visited before the siblings.

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

Which one uses backtracking ?

A

DFS

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

Memory

A

BFS requires more memory.

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

Optimality for finding the shortest path

A

BFS is optimal for finding the shortest path.

DFS is not optimal for finding the shortest path.

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

Speed

A

BFS is slow as compared to DFS.

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

Tapping in loops

A

In BFS, there is no problem of trapping into finite loops.

In DFS, we may be trapped in infinite loops.

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

When to use ?

A

BFS : When the target is close to the source, BFS performs better.

DFS : When the target is far from the source, DFS is preferable.