Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS260 Algorithms

Standard Examination:  Summer 2022

Time allowed:  2 hours.

Answer ONE question from Section A and TWO questions from Section B. USE SEPARATE ANSWERBOOKS for Sections A and B

Indicate clearly which three questions you have answered. Among the questions attempted, only the first one in Section A and the first two in Section B (in their order of appearance in the answer book) will be marked.

Read carefully the instructions on the answer books.

Calculators are not allowed.

Section A

Answer ONE question from this section.

1. Imagine that you are preparing for a canoeing trip going from the source of a river to the sea.  There are n villages along the river, numbered from n (at the source of the river) to 1 (on the sea).  In every village you can rent a canoe which can be returned at any other village downstream.  For every pair of villages i and j  (such that i > j , that is, such that j is downstream from i) we know the price p[i,j] of renting a canoe in village i and returning it in village j .

A schedule from n to 1 is a list of villages whose rental shops you should use on your way down the river from village n to village 1. For example, if n = 4 then (4, 3, 1) is a schedule in which you rent a canoe from village 4 to village 3, and then you rent one from village 3 to village 1.

(a)  [7 marks] Let n = 4 and consider the following array p of rental prices:   1  2  3  4

1

 

 

 

 

2

5

 

 

 

3

7

4

 

 

4

8

2

3

 

that is, assume that the cost of renting a canoe from 3 to 2 is 4, the cost of renting a canoe from 4 to 1 is 8, etc.

The total rental cost of a schedule is defined as the sum of all the individual rental prices; for example the total rental cost of the schedule (4, 3, 1), for the above array of prices, is p[4, 3] + p[3, 1] = 3 + 7 = 10.

How many schedules are there for a canoe trip from 4 to 1? List all of them and calculate their total rental costs.

What is the total rental cost of the optimal schedule—the schedule that minimises the total rental cost? Which schedule is optimal?

(b)  [5 marks] For every n ≥ 2, how many schedules are there from n to 1 as a function

of n?

(c)  [13  marks] Design a polynomial-time algorithm that—given an array p[i,j] of prices, for n ≥ i > j ≥ 1, as input—computes the total rental cost of an optimal schedule from n to 1.

(d)  [5 marks] Illustrate the behaviour of your algorithm on the example from part (a).

2. Suppose that you are consulting for a company that wants to organize an annual party for its employees. You have agreed with the management that a good party is such that both of the following two conditions hold:

❼ for each participant, there are at least two other participants whom she knows;

❼ for each participant, there are at least two other participants whom she doesn’t

know.

We assume throughout, that the acquaintance relation is symmetric, that is, any two employees either both know each other, or they both don’t know each other.

(a)  [5 marks] Consider a company with six employees:

❼ employees 1, 2, and 3 who all know each other; and

❼ employees 4, 5, and 6 who all know each other;

and nobody in the first group knows anybody in the other group (and vice versa).

Draw the (undirected) graph in which the vertices correspond to the six employees, and there is an edge between two of them if and only if they know each other.

Argue that if you invite all six employees to the party then it will be a good party.

(b)  [7 marks] Consider a company with eight employees: the six that we have con-

sidered in part (a), as well as employees 7 and 8, such that:

❼ employee 7 knows only employee 1; and

❼ the only people that employee 8 does not know are employees 6 and 7.

Explain why inviting employee 7 to a party (of any size) at this eight-person com- pany would prevent it from being a good party.

Can any party to which employee 8 is invited be a good party?

What is the size of the biggest possible good party at this company? Who should be invited to it?

(c)  [14 marks] Design a polynomial-time algorithm that—given an (undirected) graph G = (V,E) in which vertices correspond to employees, and edges join employees who know each other—computes the size of the largest possible good party, and lists the employees who should be invited to it.

You may assume that the graph is given as an adjacency lists data structure. For maximum credit, the running time of your algorithm should be linear in |V |+|E|.

(d)  [4 marks] Illustrate the behaviour of your algorithm on the example from part (b) that is, explain how your algorithm computes the list of employees who should be invited to the biggest possible good party.

Section B

 Answer TWO questions from this section.

 

3.   (a)  [4 marks] Consider the following 3-SAT instance:

(x1 ^ x2 ^ x4 ) ∧ (x1 ^ x3 ^ x4 ) ∧ (x1 ^ x2 ^ x3 ) ∧ (x2 ^ x3 ^ x4 ).

Give a valuation of the variables that satisfies the formula.

(b)  [6 marks] Consider the 3-SAT instance from part (a).  Draw the undirected bi-

partite graph with eight vertices:

vertices C1 ,C2 ,C3 ,C4  corresponding to the four clauses, and  vertices x1 ,x2 ,x3 ,x4  corresponding to the four variables,

and with edges (Ci ,xj ) for all i and j, such that 1 ≤ i,j ≤ 4 and the variable xj (negated or not) occurs in clause Ci .

Give a perfect matching in the graph.

(c)  [9  marks] We say that a 3-SAT instance is regular if every variable occurs in exactly three different clauses (and at most once per clause).

Prove that every regular 3-SAT instance is satisfiable.

Hint: Apply Halls Marriage Theorem.

(d)  [7 marks] Design a polynomial-time algorithm that—given a regular 3-SAT in- stance as input—returns a satisfying assignment.

(e)  [9 marks] The 4DEG-INDEPENDENT-SET decision problem isgiven an undi-

rected graph G in which every vertex has degree at most 4, and given a number k to determine if there is an independent set of size k in the graph G.

The 2LIT-3SAT decision problem is—given a CNF boolean formula with at most three literals per clause, in which each literal occurs at most twice in the formula— to determine if the formula is satisfiable.

Prove that 4DEG-INDEPENDENT-SET is NP-complete; you may assume that 2LIT-3SAT is NP-complete.

4. A path in a graph is simdle if it does not visit any vertex more than once.

The HAMILTONIAN-PATH decision problem is—given an undirected graph G—to determine if there is a simple path that visits every vertex in the graph G.  It is well- known that the HAMILTONIAN-PATH problem is NP-complete, and you may assume this fact below.

For a fixed integer k, the k-SPANNING-TREE decision problem is—given an undirected graph G—to determine if there is a spanning tree of G in which every vertex has degree no larger than k .

(a)  [8 marks] Draw the graph G = (V,E) where V = {1, 2, 3, 4, 5, 6, 7, 8} and    E = {{1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 7}, {2, 4}, {2, 7}, {3, 4}, {4, 6}, {4, 8}}.

Give a spanning tree of G in which every vertex has degree no larger than 3.     Is there a spanning tree of G in which every vertex has degree no larger than 2?

(b)  [8 marks] Prove that for every fixed integer k, the k-SPANNING-TREE decision

problem is in NP.

(c)  [9 marks] Prove that the 2-SPANNING-TREE decision problem is NP-complete.

(d)  [10 marks] Prove that the 3-SPANNING-TREE decision problem is NP-complete.

5.   (a)  [4 marks] Consider the following flow network. The numbers labelling the edges are their capacities, and s and t are the source and sink vertices.

 

 

Find a flow of value 17 in the flow network.

State the flow conservation constraint for vertex b, and the capacity constraint for edge (d,b), and argue that they are satisfied for the flow that you have found.

(b)  [8 marks] Find a flow f of maximum value in the flow network from part (a).

Draw the residual graph Gf   of the flow f that you have found, indicating the residual capacities of its edges.

Note: you do not need to show intermediate flows or their residual graphs.

(c)  [7 marks] Prove that the flow that you have given in part (b) is indeed a flow of maximum value by showing an s-t cut in the network whose capacity is equal to the value of the flow.

(d)  [8 marks] Let G = (V,E,c) be a flow network with integer edge capacities, and let f be a flow of maximum value in G. Provide an efficient algorithm that—given G, f, and an edge e in G—computes a flow of maximum value in the flow network obtained from G by decreasing the capacity of edge e by 1.

In order to obtain significant credit, your algorithm should run in time linear in |V | + |E|.

(e)  [8  marks] You are organizing a party and you want it to be as much fun as

possible. You have n friends to choose from, but the maximum number of people that you can invite into your flat—its capacity—is C .  The fun at a party stems from pairwise interactions between guests, and you have the n × n “fun table” F , such that for every pair (i,j) of your friends, F[i,j] is a number between 0 and 1 that specifies how much fun their mutual presence at the party would contribute. The DECENT-PARTY decision problem is—given an n × n array F representing the fun table, a number C and a number T as inputs—to determine if there is a selection of C guests such that the total fun contributed by all pairwise interactions between them is at least T.

Prove that if there is a polynomial-time algorithm for solving DECENT-PARTY then there is also one for the INDEPENDENT-SET decision problem.