0% found this document useful (0 votes)
47 views4 pages

Comp3121 9101-3.18

Uploaded by

Albert Yan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views4 pages

Comp3121 9101-3.18

Uploaded by

Albert Yan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Budget Holiday I

This is a regular task. You must submit a PDF, which can be produced using the LATEX template
on Moodle, exported from a word processor, hand-written or any other method.
This is a checkpoint task. Instructors will set the task status to ‘Discuss’ if they are satisfied with
your work. The task will only be upgraded to ‘Complete’ once you have discussed at least one of the
checkpoint tasks of this module at this grade level with an instructor in person.

In this task, we’ll look at the following problem:

You are going on a holiday to to Austria, but are on a limited budget. Austria has n
towns, each with an airport.
Each town t has a cost of Arrive(t) to enter Austria via that airport, and a cost of
Depart(t) to leave from there.
There are also m roads between the towns.
• Each road r has an associated cost Toll(r).
• It is possible to reach any town from any other town by a sequence of roads. In
other words, if a graph is constructed with vertices and edges corresponding to
towns and roads, the graph is guaranteed to be connected.
A holiday is a path through Austria where you arrive at a town by plane, visit zero
or more other towns connected by roads, then leave by plane (possibly from the town
where you started). You want to determine the cheapest cost of a holiday to Austria.

c d
A = 10 A = 100
D=1 D = 100
5 2 100
a b
A=2 A=5
D=8 1
D=5

In this example, the cheapest holiday is to enter Austria at town a, travel to b then c,
and leave via c. The total cost is Arrive(a) + Toll(a ↔ b) + Toll(b ↔ c) + Depart(c) =
2 + 1 + 2 + 1 = 6.
It is very expensive to arrive in or depart from town d, and also to visit it by road. A
holiday does not have to include all towns.

1
The difficulty in this problem comes from the fact that we can start and end at any vertex, so we
can’t immediately apply a single-source shortest path algorithm such as Dijkstra.
(a) A simple way to solve this problem is to just apply Dijkstra’s algorithm multiple times.
Analyse the time complexity of this method.
By cleverly constructing a modified version of the graph, we can turn the problem into a single-
source shortest path problem!
• Create a vertex ‘Start’, connected to each town t with an edge with weight Arrive(t)
• Create a vertex ‘End’, connected to each town t with an edge with weight Depart(t)
• Use Dijkstra’s algorithm to find the single-source shortest path from Start to End. The
length of this path is the cost of the cheapest holiday.
For example, given the graph above, we would construct this new graph. The red vertices and
edges correspond to the arrival costs, and the blue ones correspond to the departure costs.

Start
2
10 100

c 5 d

5 1 2 100

a 1 b

8 5
100
End

2
This is the shortest path from Start to End:

Start
2
10 100

c 5 d

5 1 2 100

a 1 b

8 5
100
End

To justify this solution, we should show that every path from Start to End in our modified graph
corresponds to a holiday in the original graph, and vice versa.
(b) Show that there is a holiday of cost c if and only if there is a Start to End path of length
c in the modified graph, and hence conclude that the shortest path in the modified graph
gives the cheapest possible holiday.
(c) Compare the efficiency of this method to the simple method from part (a).
Constructing a new graph so that we can apply a known algorithm is a common technique, so
keep it in mind for future problems!

Rubric.
(a) State the time complexity of the algorithm with a brief justification.
Expected length: two or three sentences.
(b) Prove the given statements. The first is an if and only if statement, so you need to prove
both directions, i.e. every holiday corresponds to a Start–End path and every Start–End path
corresponds to a holiday.
Note that you must prove that the solution is correct for all given graphs of Austria, not
just the provided example.
Expected length: three short paragraphs - one for each direction of the proof, and a conclu-
sion.

3
(c) Determine the time complexity of the construction method and compare it to (a).
Expected length: one or two sentences.

You might also like