| Overview | Schedule | Resources | Assignments | Home |
This exam is open-book and open-note. Please allow some time to check your work. If you need extra space, write on the back.
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | |
| input: | E | A | S | Y | O | N | E |
| pass 1: | A | E | |||||
| pass 2: | S | ||||||
| pass 3: | Y | ||||||
| pass 4: | O | S | Y | ||||
| pass 5: | N | O | S | Y | |||
| pass 6: | E | N | O | S | Y |
k % m). Let
m = 10 and give an example of a sequence of five distinct keys that will require
the maximum amount of probing to insert in an initially empty
table.
What is the big-O running time of the worst case for inserting N values in an open-addressed hash table of size 2N?
37,55
/ | \
/ | \
19 42,49,51 65
37
/ \
19 55*
/ \
49 65
/ \
42* 51*
49
/ \
37* 55*
/ \ / \
19 42 51 65
\
45*
The easiest way to see this is to work with the corresponding 2-3-4 tree, where
the 49 had to split up into the root node:
37,49,55
/ | \ \
19 42,45 51 65
19
/ \
42 37
/ \ / \
65 55 49 51
(This was unintentionally easy...)
37
/ \
42 49
/ \ /
65 55 51
19
/ \
42 37
/ \ / \
65 55 49 51
(again, this was supposed to be more interesting, and different from the result of
individual insertions; sorry.)
*
0 / \ 1
/ \
* *
0 / \ 1 0 / \ 1
S I M P
10010000
*
0 / \ 1
S *
0 / \ 1
I *
0 / \ 1
M P
(other tries are possible, depending on the order in which equal-frequency items come off the queue.)110100010001011111110,
which is only 21 bits.
| 42 | 19 | 37 | 65 | 55 | 49 | 51 | Choose 42 as pivot |
| 37 | 19 | 42 | 65 | 55 | 49 | 51 | Partitioned around 42; median is in right partition |
| 65 | 55 | 49 | 51 | Ignore left partition and pivot; choose 65 as pivot | |||
| 51 | 55 | 49 | 65 | Partitioned around 65; median is in left partition | |||
| 51 | 55 | 49 | Ignore pivot and right partition; choose 51 as pivot | ||||
| 49 | 51 | 55 | Partitioned around 51; median is in left partition | ||||
| 49 | Ignore pivot and right partition; 49 is the median |
| Overview | Schedule | Resources | Assignments | Home |
![]()
DePauw University,
Computer Science Department,
Fall 2008
Maintained by Brian Howard
(bhoward@depauw.edu).
Last updated