$24
Submit through OWL a pdf file or an image file with your answers to the following questions. No hard copy of your answers is required for this assignment. Remember that no late concept assignments will be accepted.
(2 marks) Consider a hash table of size M = 7 where we are going to store integer key values. The hash function is H(K) = K MOD 7. Draw the table that results after inserting, in the given order, the following key values: 18, 11, 12, 47, 22. Assume that collisions are handled by separate chaining.
(2 marks) Show the result of the previous exercise, assuming collisions are handled by linear probing.
(2 marks) Repeat exercise (1) assuming collisions are handled by double hashing, using secondary hash function H′(K) = 5 − (K MOD 5).
(3.5 marks) Consider the following algorithm.
Algorithm F OO(N)
if n = 0 then return 1
else {
X ← 0
for I ← 1 to N do X ← X + X/I
←X+FOO(N−1) return X
}
The time complexity of this algorithm is given by the following recurrence equation:
(0) = C1
(N) = F (N − 1) + C2N + C3, for N 0
where C1, C2, and C3 are constants. Solve the recurrence equation and give the value of F (N) and its order using big-Oh notation. You must explain how you solved the recurrence equation.
5.(I) (7 marks) Write in pseudocode an algorithm MAXVALUE(R) that receives as input the root R of a tree (not necessarily binary) in which every node stores an integer value and it outputs the largest value stored in the nodes of the tree. For example, for the following tree the algorithm must output the value 9.
5
写一个找node最大数值的
程序
−1
8
3
−7
4
9
−4
7
1
−2
3
1
For a node V use V.VALUE to denote the value stored in V; V.ISLEAF has value true if node V is a leaf and it has value false otherwise. To access the children of a node V use the following pseudocode:
for each child C of V do
5.(II) (3.5 marks) Compute the worst case time complexity of your algorithm as a function of the total number N of nodes in the tree. You must
explain how you computed the time complexity
give the order of the time complexity of the algorithm
2