Course topics 10, 11 and 12

Course topic 10

Self-study

The topics for this week are the following: (i) Graphs (ii) Breadth first search, (iii) Depth first search, (iv) Implementing a graph in C++

The following links will take you to the video-lectures and the accompanying slides:

Graphs and Trees

The following three lecture videos were already part of the course topic on trees. However, since they also cover graphs, they are included here as well.

Implementing graphs in C++

Which of the following statements are true? (More than 1 statement may be true.)
Which of the following statements are true regarding connected graphs? (More than 1 statement may be true.)
Given a directed graph, in which of the following situations would a breadth first search (BFS) be useful?
Suppose a directed graph has 4 nodes \(s\), \(a\), \(b\) and \(c\). Suppose in addition the graph has all possible edges except 2: the edge from \(s\) to \(a\) and the edge from \(a\) to \(b\). What are the distances from \(s\) to each of the other nodes?
Suppose a BFS algorithm starts from node \(s\). Suppose \(x\) is some other node and a path from \(s\) to \(x\) exists. Why does the BFS algorithm assign different colors to \(x\)?
Suppose a directed graph is input to a BFS algorithm. In addition suppose that BFS starts from node \(s\) and that a path from \(s\) to each other node exists. When BFS has finished executing, which of the following are true? (Note: more than one statement might be true.)
Given a directed graph, in which of the following situations would a depth first search (DFS) be useful?
In the DFS algorithm a stack is used. Suppose \(x\) and \(y\) are two different nodes in a directed graph. According to what rule does the DFS stack operate?
Suppose we are storing a graph in C++ and we have a node struct, in which we store all the adjacent nodes in either a vector container or an unordered_set container. In what situtation would it make sense to prefer an unordered_set over a vector?
When implementing a graph in C++, which of the following is true?

Extra links on the topic:

Week10 - Glossary

Submit weekly exercises

Questions to be submitted this week

Self-study

The topics for this week are (i) Weighted graphs and their implmentation in C++, (ii) Dijkstra’s algorithm, (iii) The A-star algorithm and (iv) The efficiencies of graph search algorithms

The following links will take you to the video-lectures and the accompanying slides:

Weighted graphs and their implmentation in C++

Dijkstra’s algorithm

There is a mistake in section 4 of the slides used in the video. This mistake is corrected in the slides that you can download.

The efficiency of three graph algorithms

Weighted graphs

A weighted graph differs from a normal graph in that …

Suppose in C++ for each node \(x\) in a connected weighted graph we use the following vector to contain the adjacent nodes to \(x\) and the weight of each edge.

std::vector< std:pair<Node*,Weight>> to_neighbours;

Suppose we are accessing vector to_neighbours for node \(N\). What does a contain after the following line is executed?

auto a = to_neighbours[0].second;

Dijkstra’s algorithm

Dijkstra’s algorithm is most similar to which of the following algorithms?
Suppose Dijkstra’s algorithm uses node \(s\) as the starting node. When, in Dijkstra’s algorithm, a node \(v\) having priority \(v.prior\) is extracted from the priority queue, what is the significance of \(v.prior\)?
Suppose Dijkstra’s algorithm uses node \(s\) as the starting node. What is the purpose of the Relax procedure?
In Dijkstra’s algorithm many quantities or variables are associated with each node \(x\). Which of the following will not change during the execution of Dijkstra’s algorithm?

The A-star algorithm

Suppose we have a directed weighted graph and a starting node \(s\). Which of the following describes one way in which the A-star algorithm and Dijkstra’s algorithm differ?
In the A-star algorithm something is computed that is not computed in Dijkstra’s algorithm. What is it?
What is a central question, related to this course, whose answer can be found in this week’s videos?
Of the following topics, which do you think deserves further discussion/explanation during the weekly consultation session?
Were there any parts of the video lectures that were particularly difficult? Particularly interesting? Something about which you wish to learn more?

Extra links on the topic:

A site where you can visualize the progress of different graph search algorithms

Week11 - Glossary

Submit weekly exercises

Questions to be submitted this week