Week 6 - Breadth-First Search Flashcards

1
Q

What is a shortest path problem?

A

The shortest path problem involves finding the shortest path or minimum distance between two nodes in a graph.

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

What is a graph?

A

A graph is a data structure consisting of nodes (vertices) connected by edges (links), used to represent relationships or connections between elements.

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

What are the neighbours of a node?

A

The neighbours of a node are the set of nodes directly connected to it.

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

What are directed edges?

A

Directed edges are used to represent one way connections within graphs. An undirected edge kind of acts like two directed edges!

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

How can a graph be implemented in python?

A

You can represent a graph in python using a dictionary (aka hash table!)

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

What are some examples of use for the graph data structure.

A
  1. Social Networks
  2. Web pages
  3. Roads
  4. Biology
  5. Computer Networks
  6. Economics
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is breadth-first search?

A

Breadth-First Search (BFS) is a search algorithm that explores a graph level by level, starting from a given node and visiting all its neighbors before moving on to their neighbors. It uses a queue to keep track of nodes to visit next, ensuring that nodes are explored in the order of their distance from the starting node.

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

What is a queue?

A

A queue is a linear data structure that follows the First-In-First-Out (FIFO) principle, where elements are added at the end and removed from the front.

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

Why do we keep track of the nodes that have been visited?

A

Tracking visited nodes is essential in graph traversal algorithms to prevent infinite loops caused by cycles. Without this, the algorithm could repeatedly revisit nodes and get stuck in an endless cycle.

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

What is the overall time complexity of BFS?

A

The overall time complexity of Breadth-First Search (BFS) is O(number of nodes + number of edges), as the algorithm must explore each edge at least once and maintains a queue for each node. Adding a node to the queue takes constant time, and doing so for every node contributes O(number of nodes) to the complexity. Also written as O(V + E).

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