CmSc360 Algorithms

advertisement
CmSc360 Algorithms
Homework 03 due 09/22
1. Based on the class discussion, refine the solutions of all non-programming
problems from homework 2.
2. Consider the partition problem: given n positive integers, partition them into two
disjoint subsets with the same sum of their elements. (Of course, the problem does
not always have a solution.) Design an exhaustive search algorithm for this
problem. Try to minimize the number of subsets the algorithm needs to generate.
(p.119, #6)
Hints:
Assume that there is a procedure subset(k,n)  b that generates
successively all subsets of length k of a set of n elements. Each subset can be
represented as a binary string b of length n. Use this procedure is a loop
while there are subsets of length k
Assume also that b[m] returns the value of the m-th bit of b, with m in the
range 0 – (n – 1).
Think how to use the binary string to represent both the partition and to
indicate whether a solution was found or not
3. Consider the clique problem: given a graph G and a positive integer k, determine
whether the graph contains a clique of size k, i.e., a complete subgraph of k
vertices. Design an exhaustive-search algorithm for this problem. (p. 119, #7)
Hint: use the procedure subset(k,n) from the previous problem
Represent the algorithms in pseudocode, use the pseudocode examples in the
textbook as guidelines.
Please follow the instructions how to turn in your assignments posted on the web.
1
Download