Fundamentals of Computer Science II (CSC-152 97F)

[News] [Basics] [Syllabus] [Outlines] [Assignments] [Examples] [Readings] [Bailey Docs]


Assignment Ten: Miscellaneous Problems

Summary: In this assignment, you will work on a number of non-coding problems.

Collaboration: Each student must turn in his or her own set of answers to this assignment. However, you may discuss the problems in any size group. Once you have come up with solutions, each student should write the answers by him or herself.

What to Include: Make sure you have an answer to each question. You need not show your work. However, if you do not show your work on a problem and your answer to that problem is incorrect, you will receive no credit. If your work is available and it is clear that you understood most of the problem, you will most likely receive at least some partial credit.

Problems

A. Priority Queues

Do problems 12.1 and 12.2 on page 230 of Bailey.

B. Search Trees

Recall that a search tree is a binary tree with the property that all the elements in the left subtree are less-than or equal to the root, and all elements in the right subtree are greater-than or equal to the root. We can build a search tree by repeatedly inserting an element at the place "where it belongs".

B.1. Construction

Show the search tree that results from inserting the elements

100, 22, 11, 5, 9, 7, 10, 30, 15, 25
in that order.

B.2. Intelligent Construction

Show a more balanced search tree that uses the same elements.

B.3. Reconstruction

Henry and Hermione Hacker suggest that one might improve the balance of search trees by removing the deepest elements in the tree and reinserting them. Does their heuristic work?

C. Collisions in Hash Tables

We saw in class that there are a number of ways to handle collisions in hash tables, including:

Assume we start with a size ten hash table, and that we hash words using the "sum of values of letters" hash function. For our purposes, the value of a is 0, the value of b is 1, the value of z is 25. Show the final hash table for each of the three design decisions mentioned above, assuming that we hash the following words (in order):

adrian, andrew, jared, scott, sarah, tomonori, yuriy

For the "rehashing" method, simply increment the hash value by one until you find an empty cell. For the "enlarging" method, enlarge the hash table by one space each time there's a collision.

D. Nearly-Balanced Trees

In many of our discussions, we saw that trees are most useful when they are complete. In complete (or nearly complete) trees, the depth of the tree grows logarithmically with the number of nodes in the tree. Unfortunately, it may be difficult to maintain completeness if a search tree.

As an alternative, many have suggested almost balanced trees. In an almost balanced binary tree, the height of the two subtrees of a node can differ by at most one and the two subtrees must also be almost balanced. Here are a few small almost balanced subtrees:

A    A    A       A       A        A
    /    / \     / \     / \      / \
   B    B   C   B   C   B   C    B   C
               /       / \      /     \
              D       D   E    D       E
Here are a few subtrees that aren't almost balanced
     A   A
    /   /
   B   B
  /   / \
 C   C   D

For each d between one and eight, determine the minimum number of nodes that you can have in an almost balanced tree of depth d.

For a small bit of extra credit, see if you can determine a formula that bounds the depth of an almost balanced tree based on the number of nodes in the tree.

E. Graphs in Practice

At rare times, Grinnell needs to quickly convey messages to all faculty members. They often do so by means of a telephone tree. The originator of the message calls a few faculty members, each of whom calls a few faculty members and so on and so forth. The "who calls who" connections are decided upon in advance, so that everyone gets called, and no one gets called twice.

You have been given the task of designing Grinnell's telephone tree. The college has assigned a cost to each faculty-to-faculty call, based on the locations of the faculty, the salaries of the faculty, and the desire of the administration to have particular faculty members make fewer or more calls.

For example, they might provide you with a matrix like the following:

                  Callee
      A   B   C   D   E   F   G   H   I
    +------------------------------------
  A | 5   3   2   1   1   1   4   3   2
C B | 2   4   3   1   5   1   3   2   5
a C | 4   4   4   4   4   4   4   4   4
l D | 2   3   4   5   2   3   4   5   3
l E | 6   6   6   6   6   6   6   6   6
e F | 3   4   5   3   4   5   3   4   5 
r G | 3   4   2   3   4   2   3   4   2
  H | 6   6   1   6   6   6   6   6   6

From this, it is clear that H should call C (since that's the cheapest way to get information to C) and that H should make no other calls (since it is more expensive for H to call anyone else).

E.1. This Instance

Give an optimal phone tree for the table above.

E.2. Generalizing

What general graph problem does developing the phone tree seem most like? Would your answer be different if we decided that each faculty member should only have to make one call? If so, what problem is the "one call only" most like?

E.3. Algorithm

Write an algorithm that finds an optimal phone tree for a cost matrix like the one given above. You should, of course, be able to handle different size matrices. What is the running time of your algorithm?


[News] [Basics] [Syllabus] [Outlines] [Assignments] [Examples] [Readings] [Bailey Docs]

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Wed Dec 10 22:06:11 1997.

This page generated on Fri Dec 12 10:17:23 1997 by SiteWeaver.

Contact our webmaster at rebelsky@math.grin.edu