# Chapter 1

Problems

- 1.1. Show that can be less than .

- 1.2. Show that can be less than .

- 1.3. Design/draw a road network with two points and such that the fastest route between and is not the shortest route.

- 1.4. Design/draw a road network with two points and such that the

shortest route between and is not the route with the fewest turns.

- 1.5.The
*knapsack problem*

is as follows: given a set of integers , and a target number , find a subset of which adds up exactly to . For example, there exists a subset within that adds up to but not . Find counterexamples to each of the following algorithms for the knapsack problem. That is, giving an and such that the subset is selected using the algorithm does not leave the knapsack completely full, even though such a solution exists.

- Put the elements of in the knapsack in left to right order if they fit, i.e. the first-fit algorithm.
- Put the elements of in the knapsack from smallest to largest, i.e. the best-fit algorithm.
- Put the elements of in the knapsack from largest to smallest.

- 1.6. The
*set cover problem*

is as follows: given a set of subsets of the universal set , find the smallest subset of subsets such that . For example, there are the following subsets, , , , and The set cover would then be and . Find a counterexample for the following algorithm: Select the largest subset for the cover, and then delete all its elements from the universal set. Repeat by adding the subset containing the largest number of uncovered elements until all are covered.

- 1.7. The
*maximum clique problem*in a graph*G*= (*V*,*E*) asks for the largest subset*C*of vertices*V*such that there is an edge in*E*between every pair of vertices in*C*. Find a counterexample for the following algorithm: Sort the vertices of*G*from highest to lowest degree. Considering the vertices in order of degree, for each vertex add it to the clique if it is a neighbor of all vertices currently in the clique. Repeat until all vertices have been considered.

- 1.8. Prove the correctness of the following recursive algorithm to multiply two natural numbers, for all integer constants
*c*≥ 2.- Multiply(
*y, z*)*if z*= 0*then*return(0)*else*- return(Multiply(
*cy*, [*z/c*]) +*y*· (*z*mod*c*))

- Multiply(

- 1.9. Prove the correctness of the following algorithm for evaluating a polynomial
*anxn + an−1xn−1 + · · · + a1x + a0*.- Horner(
*a, x*)*p*=*an*- for
*i*from*n*− 1 to 0*p*=*p · x*+*ai*

- return
*p*

- Horner(

- 1.10

- 1.12

- 1.14

- 1.16

- 1.18

- 1.20

- 1.22

- 1.24

- 1.26

- 1.28

- 1.30

- 1.32

- 1.34

- 1.36

- 1.38

Back to Chapter List