CSCI2100B
-
Upload
energy0124 -
Category
Documents
-
view
212 -
download
0
Transcript of CSCI2100B
-
8/17/2019 CSCI2100B
1/3
Course
Code: CSCI 2100B Final
Examination
Page 1 of 3
1I l.;j;jl1'lT:fi ; r : ; f l f i t 1 ~ J
.:t
Copyright Reserved
The Chinese University of Hong Kong
Course
Code & Title
Course Examinations
First
Term, 2013-2014
noLt
-
8/17/2019 CSCI2100B
2/3
Course Code: CSCI 21 B Final Examination
Page 2
o
3
(c) (4) What are the advantages and disadvantages
of
the various collision strategies in the first two
questions? Justify your answer.
(d) (4) Which hash function is a bette r hash function for the above sequence: 1) hI x) = x mod 11
or (2)
h2 x) x
mod 12? Justify your answer. Note that the size of hash table will change
according to hash function.
4. Graph (28)
(a) (3) Draw the corresponding adjacency matrix for the graph.
(b) (2) one node is removed, the graph will no longer be strongly connected.
Which
node is it?
(c) (3) Please list the breath-first search sequence started from vertex
D.
(d) (8) Find the shortest weighed path from vertex
E
to all other vertices for the graph above.
Illustrate intermediate steps with a table or figures.
(e) (8) Use Prim algorithm to find the minimum cost spanning tree of the graph. Show the interme
diate 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 D and the
sink is node G .
No
intermediate steps are required.
5. Sorting (21)
(a) (3) Show all the inversion pairs in the list (4,
1,2,5,
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 Bubble 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.
(c) (5) Given the sequence
(5,2,8,1,4,7,6,3),
sort the sequence using Mergesort. Illustrate the
result after each pass. How many comparisons have you performed?
(d) (4) Using the median
of
the first, middle, and last element
of
the array as pivot, demonstrate
ONLY the process
of
partition the sequence, (5,
7,8,4,
1, 2, 3, 6), into two parts of the Quicksort
(do not show the whole Quicksort algorithm!). Illustrate intermediate steps clearly.
(e) (4) while doing partition in the Quicksort, the loop invariant (a property that holds before each
iteration) can be illustrated as follows,
where ?,
represents unsorted elements.
Now you have an array which consists only
R
G and
B
to be sorted in alphabetical order from
left to right. You can use an algorithm similar with the partition process to solve t by using
only one pass (i.e., one for-loop). What is the loop invariant
of
this algorithm?
You
can either
describe it
or
draw
it
-
8/17/2019 CSCI2100B
3/3
CourseCode:
S I
2100B
Final
Examination
Page 3
of
3
6. Short Answers(18)(Pleasegiveonlyconciseandshortanswers!)
(a)
6)
Thefollowings arethepartialresultsof abinarytreestraversals
in
pre-order, in-orderand
post-order(X representsUNKNOWN).Pleasedraw thecorrespondingtree. Note thatthetree
has nodesintotal,whicharefromAtoK
Pre-order:XFXBXIHECXG In-order:DXKBIAXEJHX Post-order:XKXBFCJXGXA
(b) (12)Whatis theAverage- andWorst-caseruntimesof asingleFindMax operationonthefol
lowingtypesof data structures? Theanswers shouldbe expressedin thebig-Oh notation in
termsof,n thenumberof elementsstoredinthedatastructure.
IAverage-CaseIWorst-CaseI
Ascending-SortedSingleLinkedList
UnsortedArray
I
DecendingSortedArray
BinarySearchTree
AVL Tree
Max-Heap
-End