Last updated: 2026-03-04 01:47:16
Exam
Instructions
- The exam is composed of 10 multiple-choice questions
- There is exactly one right answer to each question
- Exam duration is 2 hours
- Permitted exam equipment: a calculator
- The exam takes place in a regular class, with pen and paper (not in front of a computer!)
- Each question contains a short code section. The code section is not identical to the ones that appeared in the course materials, but they combine functions and methods which were learned. You need to choose the right code output out of 4 options.
Material for exam
The material for the exam is chapters 2–11:
- Data in Python
- Spatial data
- Networks with networkx
- Spatial networks
- Directions and weights
- Routing
- Custom locations
- Accessibility
- OpenStreetMap and osmnx
- Multiple locations
The following topics from the above chapters will not appear in the exam:
- Geocoding
- Reprojection
- Rasters (package
rasterio)
Examples of exam questions
import matplotlib.pyplot as plt
import networkx as nx
import shapelyQuestion 1
What is the result of the following code section?
H = nx.Graph()
H.add_nodes_from([1, 2])
nx.number_connected_components(H)1234
Question 2
What is the result of the following code section?
G = nx.Graph()
G.is_directed()TrueFalse01
Question 3
What is the result of the following code section?
G = nx.Graph()
G.add_nodes_from([1,2,3,4])
for i in G.nodes:
G.add_edge(1, i)
G.degree[1]1234
Question 4
What is the result of the following code section?
G = nx.Graph()
G.add_node(1)
G.nodes[1]['items'] = ['1','2','3']
type(G.nodes[1]['items'][1])intdictstrlist
Question 5
What is the result of the following code section?
G = nx.DiGraph()
G.add_nodes_from(['a', 'b', 'c'])
G.add_edge('a', 'b')
G.add_edge('b', 'c')
G.add_edge('c', 'a')
G.edges['a', 'b']['weight'] = 1
G.edges['b', 'c']['weight'] = 5
G.edges['c', 'a']['weight'] = 10
nx.path_weight(G, ['a','b','c','a'], weight='weight')1234
For questions 6-10, we define a network G, as follows:
# Network
G = nx.DiGraph()
G.add_nodes_from(list(range(1, 7)))
G.nodes[1]['geometry'] = shapely.Point(8, 15)
G.nodes[2]['geometry'] = shapely.Point(0, 12)
G.nodes[3]['geometry'] = shapely.Point(15, 10)
G.nodes[4]['geometry'] = shapely.Point(20, 10)
G.nodes[5]['geometry'] = shapely.Point(0, 0)
G.nodes[6]['geometry'] = shapely.Point(15, 0)
G.nodes[6]['geometry'] = shapely.Point(15, 0)
G.add_edge(1, 4)
G.add_edge(2, 5)
G.add_edge(3, 2)
G.add_edge(4, 6)
G.add_edge(5, 6)
G.add_edge(5, 3)
G.add_edge(6, 3)
G.add_edge(5, 2)
G.add_edge(2, 3)
for u,v in G.edges:
line = shapely.LineString([G.nodes[u]['geometry'], G.nodes[v]['geometry']])
G.edges[u, v]['geometry'] = line
G.edges[u, v]['length'] = round(line.length, 1)# Plot
pos = {i: [G.nodes[i]['geometry'].x, G.nodes[i]['geometry'].y] for i in G.nodes}
edge_labels = nx.get_edge_attributes(G, 'length')
fig, ax = plt.subplots()
nx.draw(G, with_labels=True, pos=pos, arrowsize=20, connectionstyle='arc3,rad=0.03')
plt.axis('on')
ax.set_aspect('equal')
nx.draw_networkx_edge_labels(G, pos, edge_labels)
ax.tick_params(left=True, bottom=True, labelleft=True, labelbottom=True);
Question 6
What is the result of the following code section?
G.degree[6]1234
Question 7
What is the result of the following code section?
G.edges[5,2]['length'] = G.edges[5,2]['length'] / 10
x = nx.shortest_path(G, 5, 3, weight='length')
G.edges[5,2]['length'] = G.edges[5,2]['length'] * 10
print(x)[6][5, 6, 3][5, 3][5, 2, 3]
Question 8
What is the result of the following code section?
H = nx.Graph()
H.add_nodes_from([1, 2, 3])
nx.number_connected_components(H)1234
Question 9
What is the result of the following code section?
def check_node(node):
return G.nodes[node]['geometry'].x > 5
nx.subgraph_view(G, filter_node=check_node).number_of_nodes()1234
Question 10
What is the result of the following code section?
H = nx.DiGraph()
H.add_nodes_from([1,2,3])
for i in [1,2]:
for j in [1, 2]:
if i != j:
H.add_edge(i, j)
H.number_of_edges()1234