next up previous


CSE 2320 Section 501/571 Fall 1999

Homework 3 Solution

1.
Show the hash table H after inserting the keys 30, 79, 8, 39, 11, 60, 16, 14, 19, 17, 44, 18 (in this order). H has m=13 slots and uses collision resolution by open addressing and the double hashing function $h(k,i) = (h_1(k) + ih_2(k)) \bmod m$, where $h_1(k) = k \bmod m$ and $h_2(k) = 1 + (k \bmod m^{\prime})$, $m^{\prime} = m-2$. Show all computations of hash table indices, including collisions (indicated by (X) below).

0 39 h(30,0)=4 h(17,0)=4 (X) h(18,3)=3 (X)
1 79 h(79,0)=1 h(17,1)=11 (X) h(18,4)=11 (X)
2 18 h(8,0)=8 h(17,2)=5 (X) h(18,5)=6 (X)
3 16 h(39,0)=0 h(17,3)=12 h(18,6)=1 (X)
4 30 h(11,0)=11 h(44,0)=5 (X) h(18,7)=9 (X)
5 14 h(60,0)=8 (X) h(44,1)=6 (X) h(18,8)=4 (X)
6 19 h(60,1)=1 (X) h(44,2)=7 (X) h(18,9)=12 (X)
7 60 h(60,2)=7 h(44,3)=8 (X) h(18,10)=7 (X)
8 8 h(16,0)=3 h(44,4)=9 h(18,11)=2
9 44 h(14,0)=1 (X) h(18,0)=5 (X)  
10   h(14,1)=5 h(18,1)=0 (X)  
11 11 h(19,0)=6 h(18,2)=8 (X)  
12 17      

2.
Show the binary-search tree whose post-order traversal is 1, 3, 5, 4, 2, 6, 9, 11, 13, 12, 10, 8, 7. Also, show the preorder traversal of your tree.


\psfig{figure=figures/hs32.ps,height=2in}

The preorder traversal is 7, 6, 2, 1, 4, 3, 5, 8, 10, 9, 12, 11, 13.

3.
See file hw33s.txt in class directory on omega.

4.
See file hw34s.txt in class directory on omega.

5.
See file hw35s.txt in class directory on omega.

6.
See file hw36s.txt in class directory on omega.


next up previous