CISC 320 Algorithms and Advanced Programming, Spring 2001

Homework set #1

Handed out: March 6, 2001
Due date: March 20, 2001

Note: This assignment is worth 8% of the course grade. It is due in class on March 20, since sketches of the solutions will be handed out on that day.

  1. Textbook exercise 4.38 (heap construction)

    Answer part a with respect to the code in the text.

    Option: You may take inspiration, even code, from the heapsort implementation in ~saunders/320/sort/heapSort.h on the composers. Note that downHeap there is a version of fixheap.

  2. (a) Textbook exercise 5.7 (third largest)

    (b) In a heap of size 26, how many positions are possible locations of the third largest element? Draw the heap as a tree and mark the positions where the third largest might reside.

    (c) Extra credit: Implement your third-largest function of part (a).

    (d) Extra credit contest: Of those who implement the function, get a prize for winning the contest by using the fewest comparisons. To win, your program must first be correct on all inputs, then must have fewest comparisons on the test case.

    About extra credit: Extra credit points add to your score but not beyond points taken off on other homework problems.

  3. Textbook exercise 6.9 (red-black depth)
    Option: You may build your example online using the implementation of red-black trees on the composers in ~saunders/320/red-black/. The implementation is in rbt.h and the program dictMain allows you to use it interactively to build and display red-black trees. It is acceptable to simply submit the tree displayed after the appropriate 15 insertions using this program.

  4. Textbook exercise 11.18 (Boyer Moore tables and comparisons)

saunders@cis.udel.edu