0% found this document useful (0 votes)
45 views8 pages

Exam CO March 2022 Final

This document contains summaries of exam questions from CO exam 31-03-2022 authored by C. Jagtenberg and read by R. Sitters. It includes questions on Big-O notation, graph theory, flows, greedy algorithms, dynamic programming, scheduling, vertex cover, complexity theory, knapsack problems, and Dijkstra's algorithm. The answers provided indicate the level of understanding of algorithms and optimization problems demonstrated by the student.

Uploaded by

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

Exam CO March 2022 Final

This document contains summaries of exam questions from CO exam 31-03-2022 authored by C. Jagtenberg and read by R. Sitters. It includes questions on Big-O notation, graph theory, flows, greedy algorithms, dynamic programming, scheduling, vertex cover, complexity theory, knapsack problems, and Dijkstra's algorithm. The answers provided indicate the level of understanding of algorithms and optimization problems demonstrated by the student.

Uploaded by

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

CO exam 31-03-2022. Author: C. Jagtenberg. Second reader: R. Sitters.

Big O-Q1
Let f(n) = (log n)n and g(n) = n2. Then

A) f(n) = O(g(n)) but not f(n) = Ω(g(n))


B) f(n) = Ω(g(n)) but not f(n) = O(g(n))
C) f(n) = Ω(g(n)) and f(n) = O(g(n))

Answer: B

Big-O Q2
Let f(n) = n99 and g(n) = 3n. Then

A) f(n) = O(g(n)) but not f(n) = Ω(g(n))


B) f(n) = Ω(g(n)) but not f(n) = O(g(n))
C) f(n) = Ω(g(n)) and f(n) = O(g(n))

Answer: A

Graph theory
Which of the following propositions are true?

Proposition I: A graph of which each vertex has degree at least k, has a path of length k.
Proposition II: A graph with 13 vertices and each degree >= 5, must be connected.

Reminder: a path is defined as a walk where all vertices are distinct.

A) Proposition I is true, Proposition II is true


B) Proposition I is true, Proposition II is false
C) Proposition I is false, Proposition II is true
D) Proposition I is false, Proposition II is false

Answer: B
I is true: see tutorial 1

II is false. You can construct a counterexample with two components: 6 vertices on one side, and 7 on
the other. All nodes within one cluster have an edge between them, but no edges exist between the
two components. This graph is not connected.

Flow
Consider a flow network, represented by a directed graph with set of arcs A. Let fa denote the flow
going through arc a.

An arc a is called upwards critical if increasing the capacity of a increases the value of the maximum
flow.
Which of the following propositions are true?
Proposition I: Every network possesses an upwards critical arc.
Proposition II: If all arc capacities are odd, then there is maximum flow in which fa is odd for all a ∈
A

A) Proposition I is true, Proposition II is true


B) Proposition I is true, Proposition II is false
C) Proposition I is false, Proposition II is true
D) Proposition I is false, Proposition II is false

Answer: D

I is false, consider a graph with three nodes on a line. There is just one path (s,v,t) and let that have
capacity 1 on each of the two arcs.
II: false, see tutorial 1 flow exc 6

Greedy for SCP

Consider the Set Covering Problem (SCP) in the special case where each set has cost 1.
There is a greedy algorithm that chooses sets as follows: at each stage, choose the set that contains the
largest number of uncovered elements.

The figure above is a SCP instance, where the dots represent items and the rectangles represent sets.
For this instance, what is the objective value of the greedy algorithm? …
What is the optimal objective value? …

Conclude: the greedy method has an approximation ratio of at least / at most …..
Answer:
3
2
at least 1.5

Dijkstra
Consider Dijkstra’s algorithm in relation to the following graphs F and G.
Dijkstra gives the correct shortest path in:
A) G, but not in F
B) F, but not in G
C) both F and G
D) neither F nor G
Answer: A. In G Dijkstra find A-B-E, while the shortest is A-D-C-E.
In F Dijkstra finds A-D-C-E, which is the shortest.

DP2
Dynamic Programming. You are entering a Grand Festival where each day you can participate in a competition,
like archery, sword fighting, hunting, riding, etc. (Exactly one competition is held every day, the days are
numbered 1 to N.)
However, you realize that after playing some tournaments on consecutive days, you need to rest a day. The prize
money available on each day is known in advance. You win every competition that you participate in. The goal
is to get the maximum total prize money.

Example - Instance 1: There are 10 tournaments, and you are able to play 4 days consecutively.
The prizes (in the order of the days) are 13, 2, 15, 17, 19, 33, 2, 2, 2, 2.
Then, it is optimal to play on days 1, 3, 4, 5, 6, 8, 9, 10
Thus, the maximum prize money will be 103.

Instance 2: There are 6 tournaments, and you are able to play 3 days consecutively (instead of 4).
The prizes (in the order of the days) are 2, 8, 9 10, 11, 4.
So, this instance, it is optimal to play on days ….
Answer: 1, 2, 4, 5, 6
Enter the day numbers separated by a comma (like in the solution of instance 1).

Instance 3: There are N tournaments, and you are able to play 2 days consecutive (instead of 4).
The prizes (in the order of the days) are p1, p2, …. pN.
To define this as a dynamic program, we can use a function f(i,r) which represents the maximum prize money
that can be earned on the first i days of the festival, where r \in {0,1,2} is the number of consecutive days played
at the end of these i days. (So if the last day of those i days was a rest day then r = 0).
Set the initial values:
f(1,0) = 0
f(1,1) = p1
f(1,2) isn’t very sensible, but the DP works if we define it as p1 as well.

Give the recursive formulas for f(i,0), f(i,1) and f(i,2).


f(i,0) =…
f(i,1) = …
f(i,2) = ...

Answer:
f(i,0) = max { f(i-1,2), f(i-1,1), f(i-1,0)}
f(i,1) = pi + f(i-1,0)
f(i,2) = pi + f(i-1,1)

Other formulas also counted as correct if they would work. Sometimes half points awarded if answer was in the
right direction.

Scheduling 1

Find an optimal schedule for P5 || Cmax with the following 11 jobs.

jo 1 1
b 1 2 3 4 5 6 7 8 9 0 1
pj 9 9 8 8 7 7 6 6 5 5 5

What is the optimal objective value?

Answer: 15. Total time is 75. Can you create a Cmax of 75/5=15? Then that would be guaranteed
optimal. Yes you can:

9+6
9+6
8+7
8 +7
5+5+5

Vertex cover

In this course we have seen that the vertex cover problem can be formulated as an Integer linear
program (ILP). Consider the following graph G:
The optimal value of this vertex cover instance is …
The number of variables in the ILP for this instance is …
The optimal value of the LP-relaxation for this instance is ….

Answer: 3, 6, 3

Complexity

The minimum spanning tree (MST) problem is an easy problem, that means, it can be solved in
polynomial time. The Rudrata path (or Hamiltonian path) problem is NP-hard.

Consider the following two problems.

Problem 1: Given a graph, find a spanning tree for which the maximum degree (over all vertices) is at
most 2.
Problem 2: Given a graph, find a spanning tree for which the average degree (over all vertices) is at
most 2.

Which statement below is correct?

A) Problem 1 is easy. Problem 2 is easy.


B) Problem 1 is easy. Problem 2 is NP-hard.
C) Problem 1 is NP-hard. Problem 2 is easy.
D) Problem 1 is NP-hard. Problem 2 is NP-hard.

(Hint: The average degree for a graph on n verices and m edges is equal to 2m/n ).

Answer: C

Knapsack
This question compares a fractional knapsack with a binary knapsack (KP01) problem. In both cases,
the knapsack has a capacity of 6. Moreover, the items have the following profits (p) and weights (w):

What is the optimal objective value for the fractional knapsack?


Answer: First compute efficiency of each item, defined as profit/weight:
Optimum for fractional knapsack takes item 1 and 2 and three quarters of item 3. This gives
objective value 4+8+0.75*11 = 20.25

What is the value attained by the greedy approach for binary knapsack?
Answer: It takes item 1 and 2. Value 4+8=12

In this course we have seen an ‘improved greedy’ method for binary knapsack. What is its
objective value?
Answer: 12. it compares taking only item 3 (with a value of 11), with the greedy that we just saw had
value 12. The best is 12.

Without computing the optimal solution, we can already say something about the optimal value. By
using only the previous answer and knowing the approximation ratio of the `improved greedy’
method, we can conclude that the optimal value for this instance of binary knapsack is At least/at
most …. ?

Answer: KP01 is a maximization problem and improved greedy has an approximation ratio of 1/2, so
the answer is at most 24

DP1
Dynamic Programming.

You are on a long journey where you have to catch n busses in a row. At every stopover location, you
can get some food. Assume that each stopover has an infinitely short duration and you’ll eat the food
immediately after buying it: exactly at the moment the next bus departs.

Ideally you want 60 minutes between snacks, but this may not be exactly possible. If you go x
minutes without food, this incurs a penalty of (60-x)4 .

Input: The departure time of each bus that you need to catch (measured in minutes from the start of
the first bus trip) t0 …. tn-1, followed by the arrival time at the final destination (t n).
So the input it [t0, t1, t2, … tn] , for example, [0, 35, 41, 66, 102, 130, 141].

You will certainly have a snack before you start, at time t0=0, and you will also certainly have a snack
when the last bus arrives, at time tn. You want to plan your intermediate snack moments so as to
minimize the total penalty – that is, the sum over all snack intervals.

Formulate this problem as a DP. (You don’t have to enter the formulas in testvision, but you do need
them to subsequently work out the space and time complexity).
Hint: Define f(i) as the minimum cost of travelling with the first i busses and introduce an index j
which is your last snack moment before catching bus i.

This DP requires space:

A) O(1)
B) O(n)
C) O(n^2)
D) O(n^3)

 Choose the most appropriate answer, so if it is possible in O(1), then O(n) won’t be counted as correct.

Answer: B. The size of the table is n and you cannot drop anything from memory before the
DP finishes.

This DP requires time:


A) O(1)
B) O(n)
C) O(n^2)
D) O(n^3)

Answer: C . Each value takes O(n) to compute and you need to compute n values.

Define the recursion as f(i) = min0 <= j < i { f(j} + (60 - (ti-tj)3 }
Define f(i) the min cost of travelling with the first i busses. The optimum is then f(n). Set
f(0)=0

Please see exercise 2 from week 3 for a more elaborate answer, as it is essentially the same
question.

Optimization versus search.

This problem is about a complete graph G=(V,E) where all distances are integers.

The traveling salesman problem is defined as follows:


TSP:
Input: A matrix of distances; a budget b
Output: A tour which passes through all the cities and has length ≤b, if such a tour exists.

The optimization version of this problem asks directly for the shortest tour.
TSP-OPT:
Input: A matrix of distances
Output: The shortest tour which passes through all the cities.

The following aims to prove that if TSP can be solved in polynomial time, then so can TSP-OPT. Is
the proof correct?
1. We can compute an upper bound U on the optimal TSP length, for example: summing the
lengths of all edges in E is a valid upper bound.
2. Run the (supposedly existing, polynomial-time) algorithm that solves TSP for a budget b
several times, for b = 0, 1, 2, 3, ....
3. Upon the first value b for which the TSP algorithm is able to find a tour, stop and save that
tour.
4. This tour is the solution to TSP-OPT.
5. This method is guaranteed to run in at most U+1 iterations (attempted values for b in step 2).
6. This is a polynomial-time method.

Does the proof contain a mistake? Denote the first line that contains a mistake and follow with a short
explanation of what is wrong. If you think no mistake has been made, enter 0.
Open question
Answer: 6: This algorithm would work perfectly, it is just not polynomial because U depends on
magnitude of edge lengths, which is NOT allowed: the definition of polynomial must be polynomial
in the input size (m,n) of a graph. See also the related exercise in week 2.
7. Potentially other answers could also be counted as correct if the reasoning is okay-
ish.

Scheduling 2
This question is about the scheduling problem Pm |rj,pmtn| Σ Cj .

Consider SRPT: At any moment in time, process the m jobs with smallest remaining processing time
(or all jobs if there are less than m jobs available at that time).

SRPT is not optimal, and one can prove this by giving a counterexample. Consider the following
instance:

jobs 1 2 3 4 5
rj 0 0 0 2 2
pj 1 1 2 1 1

Which of the following statements is true?


A) This instance is a counterexample for m=2, but not for m=3
B) This instance is a counterexample for m=3, but not for m=2
C) This instance is a counterexample for m=2 and also for m=3
D) This instance is not a counterexample for m=2 and neither for m=3

answer: A. For m=2 this happens:

For m=3 SPRT finds the optimum.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy