0% found this document useful (0 votes)
230 views2 pages

The Chinese University of Hong Kong: Course Code: CSCI 2100A Final Examination 10f 2

CSCI2100A

Uploaded by

energy0124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
230 views2 pages

The Chinese University of Hong Kong: Course Code: CSCI 2100A Final Examination 10f 2

CSCI2100A

Uploaded by

energy0124
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Page 10f 2

Course Code: CSCI 2100A Final Examination

*-

~
The Chinese University of Hong Kong

-j-

3:

M..*If~,r~

;r-~Jf-tll~p

Copyright Reserved

Course Examinations Second Term, 2014-2015

Course Code & Title

Time allowed

Student LD. No.

CSCI 2100A Final Examination

2
...........................
hours

00
.
........................... minutes

Seat No. : .......................... .

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.

Course Code: CSCI 2100A Final Examination

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

sink is node G . No intermediate steps are required.


3. Sorting (27)
(a) (3) Show all the inversion pairs in the list (4,1,5,2, 3)? List them out in an organized manner,
i.e., sort them in an ascending order by the first element and then by the second element.
(b) (5) Given the sequence (4,6,1,8,3,7,2,5), sort the sequence using the Insertion Sort algorithm.
Illustrate the result after each pass. How many positions moved have you performed at each
pass? Justify your answer by using a table like in the lecture notes.
(c) (5) Given the sequence (5,2,8,4,1,6,3,7), sort the sequence using Mergesort. Illustrate the
result after each pass. How many comparisons have you performed?
(d) (6) You have a list of elements with only three different elements, e.g. 0,1.2. For example, the
list can be {0,1,1,0,2,},0,0,2}.
a) (3)Please give an algorithm whose time complexity is O(n).
b) (3)Please give an algorithm whose time complexity is O(n) while space complexity is 0(1).
(e) (4) Given an array with n elements to sort, what is the best and worst time complexity when
using Bubble sort, Selection sort, Insertion sort and Mergesort in terms of Big-O notation.
(f) (4) Quicksort with the median of the first, middle, and last element of the array as pivot and a

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

Descending-Sorted Double Linked List

Unsorted Array

Ascending-Sorted Array

Binary Search Tree

AVL Tree

Max-Heap

Min-Heap

-End

You might also like