Algorithms Sample Test 2

Question 1. (30 points)

a) Outline (in English) a greedy algorithm that takes a CNF (conjunctive normal form) Boolean expression and determines a truth assignment of Boolean variables that makes the expression true. For example, a Boolean expression in CNF is

and the truth assignment of satisfies it.

(NOTE: Your greedy algorithm does not need to find this particular true assignment for this example.)

b) Will your greedy algorithm in part (a) above always find a truth assignment if one exists? (Justify your answer)

Question 2. (30 points)

Design a backtracking algorithm that takes a positive integer C as input and outputs all of the ways that a group of ascending positive numbers can be summed to give C. For example, if C = 10, the output should be











a) What should the search-space tree look like for this backtracking algorithm?

b) Describe in English how a promising function should decide if a node is to be pruned or not.

c) What state information is needed at each node in the search-space tree?

d) What information in your answer to part (c) could be kept global?

e) What information does the promising function need?

f) Write the promising function (pseudo-code) for this backtracking algorithm.

f) Below is a template for a backtracking algorithm.

Customize the above template for this problem.

Question 3. (30 points) Longest Common Substring

Let us consider two sequences of characters S1 and S2. For example, we could have S1 = A$CMA*MN and S2 = AXMC4ANB. Assuming that a subsequence of a sequence can be constructed by deleting any number of characters from any position, use the dynamic programming approach to create an algorithm that finds the longest common subsequence of S1 and S2. Your algorithm should return the maximum-length common subsequence of each sequence (and not just its length).

Question 4. (10 points)

Consider the following best-first search Branch-and-Bound template.

a) Describe in English what the bound value represents?

b) Suppose a student was customizing the above branch-and-bound template for the problem of making change with the fewest number of coins. For a node's bound calculation, they decided to use the following:

bound := (number of coins already returned) + greedy(remaining change to be returned),

where "greedy" returned the number of coins bases on a greedy algorithm that repeatedly gives back the highest denomiation coin possible.

For example, suppose that the initial problem was to return 78 cents using coins with denominations 1, 5, 10, 12, 25, and 50. For the node representing the partial solution of returning one 50 cent and one 12 cent coin, the bound calculated is 7, where 2 is from the partial solution and 5 is from calling greedy(16) (16 = 12 + 1 + 1 + 1 + 1).

i) After extensive testing, the student discovered that this branch-and-bound algorithm did not always find the globally optimal solution. What is the problem with this branch-and-bound algorithm?

ii) Describe a modification to the algorithm so that it will always give a globally optimal solution.