CS 210 December 2007
Some of these questions will be on the final exam. (perhaps with
slight modifications)
SORTING
fill in the table.
name of alg.
|
simple | adv?
|
approx. big-O
|
fast if alrdy inorder?
|
recursive?
|
needs xtra space
|
key term
|
i__
|
|
|
|
|
|
|
s__
|
|
|
|
|
|
|
m__
|
|
|
|
|
|
|
S__
|
|
|
|
|
|
|
q__
|
|
|
|
|
|
|
a "key term" would be something like: "variant of xxx
sort",
"partition", "similar to binary search", "find minimum"
Does the sort have a worst case situation? (think about binary
search: does it have a worst case scenario?)
Chose one simple sort and one advanced
sort:
Describe how to move ahead one step in the operation of the sort.
(This is like explaining the algorithm in pseudo-code). For
instance,
^ j
"find the smallest element to the right of "j"; swap it with
element
at j.
move j one position to right. Repeat until done (j==N-1)
(this is supposed to be easier than actually writing the program.)
Note that we've spent more time on some sorts than on others ...
clearly, you should know more about those.
LISTS
Create a class List<E> which is a simple linked-list class to
hold objects of any reference type. Provide two routines,
add() and
remove(). If the list is empty, remove() should return null.
Let's create a full program. Here's a little bit to get
you started.
class List<E> {
void add(...
.... remove(...
}
class ListElt....
}
class ListTest {
public static void main(String args[]) {
List .... L = new List ....;
L.add("world");
L.add("hello");
System.out.println(L.remove());
System.out.println(L.remove());
System.out.println(L.remove());
}
}
What will this print when run? (What other kind of data structure
behaves like this?)
BINARY [SEARCH] TREES
What is the invariant for a binary tree?
|
10
/ \
5 20
/'x'
What is the immediate (primary) invariant describing nodes on arc "x"?
What is the full (derived) invariant condition for nodes on "x" and
below? (hint: could 7 be placed there?)
Place (insert) the following values in order: 7
11 6
Here's another tree
|
18
/ \
/ \
13 36
/ \ / \
7 35 38
\
12
Remove the node containing 13. Then remove the one
containing 18.
(you don't need to write the Java program. Show which
nodes move
where and why)
Write a Java program to traverse a binary search tree and count how
many nodes have 2 children.
|
E
/ \
B L
/ \
J M
\
U
Indicate the following components: root; root of
subtree; leaves.
How many nodes are there? How many edges?
Show the result of doing a "postorder" walk of the tree.
What kind of helper data structure would be needed to do a
breadth-first walk of the tree?
HASH TABLES
Consider a hash table with "separate chaining", table size 7.
We'll be
storing data of type "int", and the hash function is %tablesize.
Show the table after the insertion of 10, 9, 36, 23
Do the same, but for an open addressing table with linear
probing
(the simplest overflow scheme).
(note: you are not required to know all about the various overflow
schemes)
What is the "load factor"? How high can it reasonably be for open
addressing? For separate chaining?
Given a hash table with array HTA[], and hash function htfunc()..
What three main steps need to occur in order to find the entry
corresponding to a key value "kv"?
Which of these need to be repeated in the event of a collision?