The Chinese University of Hong Kong: Course Code: CSCI 2100A Final Examination 10f 2
The Chinese University of Hong Kong: Course Code: CSCI 2100A Final Examination 10f 2
*-
~
The Chinese University of Hong Kong
-j-
3:
M..*If~,r~
;r-~Jf-tll~p
Copyright Reserved
Time allowed
2
...........................
hours
00
.
........................... minutes
1. Hashing (20)
Given the input {84, 12,48,16,38,108,36,60,72, 63} and a hash function h(x) = x mod 10, show
what happens when each element in the list is inserted into the hash table of size 10 using the following
collision policy.
(a) (4) Open hash table. Explain what method of insertion you are using.
(b) (4) Closed hash table using linear probing (assuming that the increment is 1).
(c) (4) Closed hash table with second hash function h2(X)
=3- x
mod 3.
(d) (4) What are the advantages and disadvantages of the various collision strategies in the first two
questions? Justify your answer.
(e) (4) Which hash function is a better hash function for the above sequence: (1) hi (x) = x mod 12
or (2) h2(X) = x mod 11? Justify your answer. Note that the size of hash table will change
according to hash function.
2. Graph (27)
(a) (3) Draw the corresponding adjacency matrix for the graph.
(b) (3) Please list the depth-first search sequence started from vertex D.
(c) (3) Please list the breath-first search sequence started from vertex A.
(d) (6) Find the shortest weighed path from vertex A to G. Illustrate intermediate steps with a table
or figures.
Page 2 of 2
(e) (8) Use Kruskal's algorithm to find the minimum cost spanning tree of the graph. Show the
intermediate steps of the algorithm and the final result of the minimum cost spanning tree that
you have obtained.
(f) (4) Find the maximum flow in the network above assuming that the source is node A and the
cutoff of 3, demonstrate ONLY the process of partition the sequence, (7,6,1,4,8,2,3,5), into
two parts of the Quicksort (do not show the whole Quicksort algorithm!). Note that assume the
1 and
size of array is n, the middle element index is nj2, where index starts from to n
the first step in the Partition algorithm is to swap the selected pivot (median of 3) with the first
element, Le. after this step, it is the same as the code introduced in the lecture notes where using
the first element as the pivot, after partition, the left half elements is less or equal to the pivot,
the right half is greater than the pivot. Illustrate intermediate steps clearly.
4. Short Answers (26) (Please give only concise and short answers!)
(a) (6) How many different stack-permutable final sequences are there if the input sequence is
{1,2,3,4,5}? E.g., {5,4,3,2,1} and {1,3,2,5,4} are both valid final sequences.
(b) (6) The followings are the partial results of a binary tree's traversals in pre-order, in-order and
post-order (X represents UNKNOWN). Please draw the corresponding tree. Note that the tree
has 9 nodes in total, which are from A to 1.
Pre-order: XAXIXXBXC In-order: XDXAHXFXC Post-order: XEDXBXGFH
(c) (14) What is the Average- and Worst-case runtimes of a single DeleteMin operation on the
following types of data structures? The answers should be expressed in the big-Oh notation in
terms of, n, the number of elements stored in the data structure.
Data Structure
I Average-Case I Worst-Case I
Unsorted Array
Ascending-Sorted Array
AVL Tree
Max-Heap
Min-Heap
-End