Вы находитесь на странице: 1из 2

Course Code: CSCI2100B

Page 1 of 2

if- it. tf :;t

The Chinese University

*of Hong

M,.ff{pJf;ff ;r.1Jf""~1'

Kong

Copyright Reserved

Course Examinations Second Term, 2012-2013


Course Code & Title

CSCI2100B
Data Structures
...........................................................................................
, .................

Time allowed

............ ~............. hours

Student I.D. No.

.........................................

............. ~~.......... minutes

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

1. Heaps (12)
(a) (8) Show the result of inserting 10, 8, 16, 3, 2, 6, 20 one at a time, into an initially empty
binary heap (smaller number equals high priority). Show all intermediate steps and the final
configuration of the heap using the array data structure.
(b) (4) Show the result of performing two Delete..Min operations in the above heap. Show the
heap configuration after each Delete..Min operation clearly.

2. Hashing (10)
Given the input {38, 12, 16,48,108,36,60,96,84, 72} and a hash function hex) = x mod 10, show
what happens when each element in the list is inserted into the hash table of size lOusing the following
collision policy.
(a) (4) Open hash table. Explain what method of insertion you are using.
(b) (4) Closed hash table using quadratic probing (specify your probing function).
(c) (2) Which hash function is a better hash function for the above sequence: (1) hl (x) = x mod 11
or (2) h2(x)
x mod 121 Justify your answer. Note that the size of hash table will change
according to hash function.

3. Graph (29)

(a) (3) Draw the corresponding adjacency matrix for the graph.
(b) (3) Please list the depth-first search sequence started from vertex A.

Course Code: CSCI2100B

Page20f 2

(c) (3) Please list the breath-first search sequence started from vertex A.
(d) (10) Find the shortest weighed path from vertex D to all other vertices for the graph above.
Illustrate intermediate steps with a table or figures.
(e) (10) Assuming that you have access to the sorted weight list in an ascending order in 0(1),
which of the minimum cost spanning tree algorithms (Prim or Kruskal) would you use to achieve
a better running time performance? Justify why is your selected algorithm better suited for the
above special graph. Show the intermediate steps of the algorithm and the final result of the
minimum cost spanning tree that you have obtained.
4. Sorting (32)
(a) (4) Given the following element list, {I, 2, 3,4, 5} and the following inversion list, { (5,4), (5,3),
(2,1), (5,1), (3,1), (5,2) }, what is the original order of the list?
(b) (2) Given n unique elements in a list, what is the maximum number of inversion possible for
this list? Justify your answer.
(c) (4) A permutation with the most inversions may not necessary be the worst possible input to
sorting algorithms. Give a sorting algorithm in which the performance of the number of com
parisons and swap is independent of the number of inversions. Justify your answer.
(d) (6) Given the sequence (5,3,1,8,4,6,7,2), sort the sequence using Mergesort. Illustrate the
result after each pass. How many comparisons have you performed?
(e) (6) Given the sequence (4, 6, 1, 8, 3,7,2,5), sort the sequence using the Selection Sort algorithm.
Illustrate the result after each pass. How many comparisons and swap have you performed?
Justify your answer by using a table with a column for comparison and swap performed in each
pass.
(f) (4) You have a list of elements that could either be borwto be sorted, e.g., (b, b, w, b, w, b, w, w, b).
Demonstrate that you can short them in O( n) time. What type of sorting algorithm are you us
ing?

(g) (6) Without any checking about whether the input is already in order, what would be the time
for Quick Sort algorithm to sort an ordered list if one uses:
i. (2) First element of the array as pivot.
ii. (2) Last elements of the array as pivot.
iii. (2) Use the median of the first, middle, and last element of the array as pivot.
5. Short Answers (17) (Please give only concise and short answers!)
(a) (3) A time complexity function G was formulated for a program. What term asymptotically
dominates G ifG(x) = 9999gx -0.OOOlx2 + x log(log(x)) +x 2 /(x - 999) + l.OOOl x Justify
your answer.
(b) (6) The followings are the partial results of a binary trees traversals in pre-order, in-order and

post-order (X represents UNKNOWN). Please draw the corresponding tree.


Pre-order: XBXFXICEHXG In-order: DXKFIAXEJCX Post-order: XKXFBHJXGXA
(c) (8) What is the Best- and Worst-case runtimes of a single find 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.

I Best-Case I Worst-Case I
Sorted Linked List
Unsorted Array
Binary Search Tree
AVLTree
End

Вам также может понравиться