G6017 Program Analysis Exam Paper January 2023
G6017 Program Analysis Exam Paper January 2023
G6017 Program Analysis Exam Paper January 2023
PROGRAM ANALYSIS
G6017
You must start this exam at the time published in your Sussex Direct
Timetable, as indicated below.
Once started you will have a set exam duration in which to complete it, if you
have not completed it before the end of the duration the exam will close.
If you have extra time due to Reasonable Adjustments this is additional to the
exam duration below and has been added to your assessment on Canvas.
If all three questions are attempted only the first two answers will be marked.
Write or type your answers on A4 paper, scan and save as a single PDF file
and upload to Canvas
Your candidate number (Do not put your name on your paper)
The title of the module and the module code
You MAY access online materials, including lecture notes during this examination.
You must complete this assessment on your own and in your own words. DO
NOT discuss this assessment with others during the exam. By submitting this
assessment you confirm that your assessment includes no instances of academic
misconduct, for example plagiarism or collusion. Any instance of academic
misconduct will be thoroughly investigated in accordance with our academic
misconduct regulations.
G6017 Program Analysis
1.
(a) Precisely specify the conditions under which the following algorithm returns
true, and then discuss, in detail, the running time of the algorithm. If you think
it has different best- and worst-case running times then these should be
considered separately, and you should explain the conditions under which
best and worst-cases arise. You must fully explain your answer and use O,
and appropriately to receive full marks.
𝑘𝑘 ← 0
𝑗𝑗 ← 1
while 𝑗𝑗 ≤ 𝑛𝑛 do
If 𝑎𝑗𝑗 == 𝑏𝑏𝑛𝑛−𝑗𝑗+1
𝑘𝑘 ← 𝑘𝑘 + 1
𝑗𝑗 ← 𝑗𝑗 + 1
return 𝑘𝑘 == 𝑛𝑛
[10 marks]
(b) Precisely specify the conditions under which the following algorithm returns
true, and then discuss, in detail, the running time of the algorithm. If you think
it has different best- and worst-case running times then these should be
considered separately, and you should explain the conditions under which
best and worst-cases arise. You must fully explain your answer and use O,
and appropriately to receive full marks.
for 𝑗𝑗 ← 0 𝑡𝑡𝑠𝑠 2 do
𝑠𝑠𝑠𝑠𝑏𝑏𝑠𝑠𝑠𝑠𝑡𝑡𝑎𝑎𝑠𝑠 ← 𝑠𝑠𝑠𝑠𝑏𝑏𝑠𝑠𝑠𝑠𝑡𝑡𝑎𝑎𝑠𝑠 + 𝑎𝑎𝑖 +𝑗𝑗
If 𝑠𝑠𝑠𝑠𝑏𝑏𝑠𝑠𝑠𝑠𝑡𝑡𝑎𝑎𝑠𝑠 == 0
𝑞𝑞 ← 𝑓𝑓𝑎𝑎𝑠𝑠𝑠𝑠𝑡𝑡
𝑖𝑖 ← 𝑖𝑖 + 1
return 𝑞𝑞
[10 marks]
2
G6017 Program Analysis
(c) Precisely specify the conditions under which the following algorithm returns
true, and then discuss, in detail, the running time of the algorithm. If you think
it has different best- and worst-case running times then these should be
considered separately, and you should explain the conditions under which
best and worst-cases arise. You must fully explain your answer and use O,
and appropriately to receive full marks.
𝑛𝑛𝑠𝑠𝑛𝑛𝑡𝑡 ← 𝑡𝑡𝑠𝑠𝑠𝑠𝑡𝑡(𝑠𝑠)
return 𝑓𝑓𝑎𝑎𝑠𝑠𝑠𝑠𝑡𝑡
[10 marks]
(d) A data pattern analyser is to be built that can detect and count up the number
of occurrences of strictly increasing and strictly decreasing sequences of
three numbers in an input sequence. So for the sequence (1,2,3,4) there are
two strictly increasing sequences (1,2,3) and (2,3,4).
The analyser should stop if it encounters 0 in the input sequence and return
the number of occurrences found up to that point in the form of a 2-tuple
(#𝑖𝑖𝑛𝑛𝑠𝑠𝑡𝑡𝑡𝑡𝑎𝑎𝑠𝑠𝑖𝑖𝑛𝑛𝑔𝑔, #𝑛𝑛𝑡𝑡𝑠𝑠𝑡𝑡𝑡𝑡𝑎𝑎𝑠𝑠𝑖𝑖𝑛𝑛𝑔𝑔).
3
G6017 Program Analysis
[10 marks]
To ensure that the file remains sufficiently secure, we need to ensure that
there is no more than a 2% chance over 30 days that the password is
guessed by a hacker program utilizing brute force working 24 hours a day, 7
days a week. How many bits should be specified for the password?
[10 marks]
4
G6017 Program Analysis
2.
(a) A student has been asked to put some parcels on a shelf. The parcels all
weigh different amounts, and the shelf has a maximum safe loading weight
capacity of 100 Kg. The weight of parcels are as follows (in Kg):
𝒑𝒑𝒑𝒑𝒑𝒑𝒑𝒑𝒑𝒑𝒑𝒑 𝒘𝒘𝒑𝒑𝒘𝒘𝒘𝒘𝒘𝒘𝒘𝒘
(𝑲𝑲𝒘𝒘)
1 10
2 5
3 2
4 42
5 50
6 25
7 1
The student has been asked to load the maximum weight possible parcels on
the shelf subject to the maximum safe loading weight.
State two possible approaches for a greedy algorithm solution to solve this
problem. In each case, state clearly the result you would get from applying
that approach to this problem, stating whether the solution is optimal or not. If
your answer does not produce an optimal solution, what algorithm could be
employed to find one?
[10 marks]
(b) One example of a greedy algorithm is the Kruskal algorithm for finding a
Minimum Spanning Tree. The algorithm is shown below.
Kruskal(G,w)
5
G6017 Program Analysis
Consider the graph below with a set 𝑉𝑉 of 8 vertices and a set of weighted
edges 𝐸𝐸:
At the outset, each graph vertex is assigned to its own cluster, so each cluster
is distinct and has exactly one element. So initially vertex 𝑣𝑣1 is assigned to
cluster 𝐴𝐴, 𝑣𝑣2 to cluster 𝐵𝐵 and so on.
Complete the table below showing which vertices belong to which clusters at
each point in the algorithm where clusters are joined. You should assume that
when a union of two clusters is formed, the new cluster takes the earliest
letter applicable. For example, if cluster 𝐹𝐹 = {𝑣𝑣6 } i.e. 𝑙𝑙(𝑣𝑣6 ) = 𝐹𝐹, and cluster
𝐺𝐺 = {𝑣𝑣7} i.e. 𝑙𝑙(𝑣𝑣7) = 𝐺𝐺, then the union of clusters 𝐹𝐹 and 𝐺𝐺 would become
cluster 𝐹𝐹 = {𝑣𝑣6, 𝑣𝑣7} and thus 𝑙𝑙(𝑣𝑣6) = 𝐹𝐹 and 𝑙𝑙(𝑣𝑣7) = 𝐹𝐹. This is shown in the
second row completed below.
[10 marks]
6
G6017 Program Analysis
(c) A message of length 𝑥𝑥 symbols is made from a set of 8 symbols drawn from
a vocabulary shown below, with each symbol being coded using 3 binary bits:
So, the message BADGE (x = 5) would be coded as 001, 000, 011, 110,100.
This message requires a constant 3 bits/symbol. Analysis shows that in
general usage, the symbols appear with the relative frequency as shown also
in the table.
(e) A student wishes to solve the Minimum Spanning Tree problem using a new
algorithm they have devised. They decide to test their new algorithm against
the well-known Kruskal and Prim algorithms. Discuss whether the new
algorithm is guaranteed to produce an identical tree output as the Kruskal
algorithm when provided with the same input graph.
{5 marks]
7
G6017 Program Analysis
3.
(a) The subset sum problem can be reliably solved optimally using the dynamic
programming algorithm shown below:
SubsetSum(𝑛𝑛, 𝑊𝑊)
You are given a set of requests and their corresponding weights. The
maximum weight constraint 𝑊𝑊 is 12.
𝒘𝒘 𝒘𝒘𝒘𝒘
1 2
2 1
3 6
4 7
5 1
6 10
Complete the solution space table to determine the optimal subset sum.
𝒘𝒘
0 1 2 3 4 5 6 7 8 9 10 11 12
6
5
4
3
𝒘𝒘 2
1
0
[10 marks]
8
G6017 Program Analysis
𝑓𝑓𝑠𝑠𝑠𝑠(𝐴𝐴)
if length(𝐴𝐴) == 1
return 𝑎𝑎1
State what problem this algorithm solves and write down the two recurrence
equations that characterise this recursive algorithm.
[10 marks]
(c) Define what is meant by the term “topological sort” when applied to a Directed
Acyclic Graph (DAG).
[5 marks]
.
(d) Enumerate all possible topological sorts for the DAG shown below.
[5 marks]
9
G6017 Program Analysis
(e) The Ford-Fulkerson algorithm is used to determine network flow. The diagram
below represents a data network that connects a Data Service Provider (DSP)
connected to 𝑣𝑣1 (s) to a customer connected to 𝑣𝑣6 (t). Each edge represents a
single data transmission link.
The notation 𝑝𝑝/𝑞𝑞 indicates a current actual forwards flow 𝑝𝑝 measured in Gb/s in a
cable with a maximum capacity of 𝑞𝑞 also measured in Gb/s.
i. Show the residual graph that will be created from the initial empty flow. When
drawing the residual graph, show a forward edge with capacity 𝑥𝑥 and a
backward edge with flow 𝑦𝑦 by annotating the edge
�𝑥
�⃗ ;
�𝑦
�⃖ .
[2 marks]
i. What is the bottleneck edge of the path (𝑠𝑠, 𝑣𝑣3 , 𝑣𝑣2 , 𝑣𝑣5 , 𝑡 ) in the residual graph
you have given in answer to part (i) ?
[2 marks]
ii. Show the residual graph after incorporating the simple path (𝑠𝑠, 𝑣𝑣3 , 𝑣𝑣2 , 𝑣𝑣5 , 𝑡 )
that results from augmenting the flow based on the residual graph you have
given in answer to part (i).
[4 marks]
iv. Repeat the process outlined above incorporating additionally the simple paths
(𝑠𝑠, 𝑣𝑣3 , 𝑣𝑣4 , 𝑣𝑣5 , 𝑡 ) , (𝑠𝑠, 𝑣𝑣3 , 𝑣𝑣4 , 𝑣𝑣2, , 𝑣𝑣5 𝑡 ), (𝑠𝑠, 𝑣𝑣2 , 𝑣𝑣4 , 𝑡 ) and (𝑠𝑠, 𝑣𝑣3 , 𝑣𝑣4 , 𝑡 ) showing each residual
graph, to determine the maximum flow between 𝑠𝑠 and 𝑡 , and thus the
maximum data bandwidth that can be achieved between the DSP and the
customer. Remember to check whether you are following a forwards or
backwards edge in the residual graph.
[12 marks]
10
G6017 Program Analysis
End of paper
11