CSCI 256
Design and analysis of algorithms
Assignment 4

Due Wednesday, 2/28/2001


Numbered problems are from Cormen, Leiserson, and Rivest. You should do all of the problems, but only turn in those from the second section.

Practice problems:

  1. Prove that any binary tree with height d has at most 2d leaves.

  2. Suppose you are given 12 coins, exactly one of which is counterfeit. The counterfeit coin is either lighter or heavier than the other coins, which all weigh the same amount. Using only a balance scale, please show how to find the counterfeit coin using only 3 weighings. Please express your algorithm as a decision tree. This problem will be discussed in lecture on Friday.

  3. In class, we found an iterative algorithm to find the min and max of an array in ceiling(3n/2)-2 comparisons. Find a recursive divide and conquer algorithm (i.e., start by making recursive calls to the first and second halves of the list and then ...) to find the min and max. Write down a recurrence relation for the number of comparisons, T(n), and show that T(n) <= ceiling(3n/2) - 2 for n >= 2. You need only show the bound holds for n a power of 2 (which means you can ignore the ceiling).

  4. Design an algorithm to determine whether two arrays of real numbers are disjoint (i.e., there is no overlap between the elements of the first and the second). State the complexity of your algorithm in terms of the sizes m and n of the given sets. Be sure to consider the case where m is substantially smaller than n.

Problems to be turned in:

  1. Prove that any comparison based search algorithm must have running time at least Omega(lg n), even if the input is held in a sorted array! Hint: Emulate the proof for comparison based sorts. Of course, binary search is an example of a comparison-based search with running time Theta(lg n)

  2. The input to the following problems is an array S containing n real numbers, and a separate real number x.

    1. Design an algorithm to determine whether there are two elements of S whose sum is exactly x. The algorithm should run in time O(n lg n) (and you should provide an argument that it does!).

    2. Suppose now that the set S is given in a sorted order. Design an algorithm to solve the problem in time O(n). Again argue that it works in that time.

  3. Problem 8-4 on page 168 of CLR. For part a, an informal argument as to why the algorithm works the same as recursive quicksort is fine. I'd like a convincing argument for part c (and be sure to maintain the Theta( n lg n ) expected running time).


Back to:

  • CS256 home page
  • Kim Bruce's home page
  • CS Department home page
  • kim@cs.williams.edu