Lecture 2 - BFS and DFS Flashcards

1
Q

What is DFS/BFS categorised as?

A

A traversal algorithm.

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

How do we know if BFS/DFS is efficient?

A

If it runs in O(V + E) time.

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

What are the steps of Depth First Search?

A
  • Follow a path of unvisited verticies until path cannot be extended further
  • Backtrack until a node with unvisited nodes
  • Repeat until all nodes visited
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Does DFS work with non-conncted graph?

A

Yes, with some changes.

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

What do the edges traversed form?

A

A spanning tree (forest).

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

What does a spanning tree consist of in reference to original graph?

A

All vertices and some or all edges.

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

What is the complexity of DFS?

A

O(m+n) using an adjacency list.
O(n^2) using an adjacency matrix.

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

Some applications of DFS ?

A
  • to determine if a graph is connected
  • to identify connected components of a graph
  • check whether a graph has a cycle
  • to determine if a graph is bipartite
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Steps of Breadth First Search?

A
  • add each adjacent vertex of current vertex to list
  • repeat for each node in list until no nodes left

The actual order of traversal and hence spanning tree depends on specific implementation of algorithm.

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

What is the complexity of BFS?

A

O(m+n) for adjacency list
O(n^2) for adjacency matrix

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

What are the applications of BFS?

A
  • finding distance between 2 verticies
  • shortest path from v to w in terms of edges
How well did you know this?
1
Not at all
2
3
4
5
Perfectly