給定:n個項目,每個項目含值與重量,及總重限制
目標:找價值最大,且不超過總重
NP-complete
(1-1)What strategy can solve the Convex Hull Problem and the One-Center Problem, respectively?
(3-5)What is the optimal solution for the following knapsack problem?
O(1) < O(log n) < O(n) < O(n log n) < O(n^2 ) < O(n^3 ) < O(2^n ) < O(n!) < O(n^n )
(1-2-1)Please compare the following complexity values: O(n), O(n!), O(2 ? ), O(log n), O(? ? )
best case:O(n)
worst case:O(n^2)
average case:O(n^2)
(1-3-2) Straight Insertion Sort Algorithm to sort 8, 5, 4, 9, 1, 3
best case:O(1)
worst case:O(log n)
average case:O(log n)
(1-4-1) What is the number of comparisons we need at most to find a number in 2048 numbers by Binary search?
best case:O(n log n)
worst case:O(n^2)
average case:O(nlog n)
(1-4-2)What is the number of comparisons we need at least to sort 2048 numbers?
(1-2-2)What are complexity values of the Binary Search and the Straight Selection Sort in worst case, and which one is better?
(1-5)Give the following pairs of functions, what is the smallest value of n such that the first function is larger than the second one?
(1) 2 ? , 6? 2 (2) ? 2 ,32?log2
O(n2)
切中線為A B
找出A B各自Rank
根據A B點排序,更新B的值
O(n log2n)
log(n!) = Ω(n log n)
lower bound for sorting: Ω(n log n)
(2-1)What is the number of comparisons we need at least to sort 6 numbers?
Worst case:O(n log n)
Average case:O(n log n)
Average case lower bound:O(n log n)
Heap sort is optimal in the average case.
(2-2)Please construct and output a max heap for the input data A(1) = 40, A(2) = 48, A(3) = 26, A(4) = 29, and A(5) = 4. Draw every tree for your heap construction and sorting output procedures.
(2-3-1)What are complexity values of the Straight selection sort, the Quick sort and, the Heap sort in worst case?
(2-3-2)Which algorithms is optimal in worst case? Why?
Problem A reduces to problem B (A ∞ B)
if A can be solved by using any algorithm which solves B
If A∞B, B is more difficult
T(tr1 ) + T(tr2 ) < T(B) T(A) <= T(tr1 ) + T(tr2 ) + T(B) <= O(T(B))
Sorting ∞ Convex hull(lower bound:Ω(n log n)
Sorting ∞ Euclidean MST(lower bound:Ω(n log n)
(2-4)If problem A can reduce to problem B, which problem is more difficult? Why?
(2-5)What is the lower bound of the Euclidean Minimal Spanning Tree problem? Why
O(n2)
optimal
(3-4)What is the time complexity of Dijkstra’s algorithm? Why?
(3-3)For the seven messages (M1, M2, …, M7) with access frequencies (q1, q2, …, q7) =(3, 6, 7, 9, 12, 13, 16), please obtain a set of optimal Huffman codes and draw itsdecode tree
maxima:滿足不被其他點支配
支配:x1 > x2 and y1 > y2
Given a set S of n points, find a pair of points which are closest together.
設定x中線之x+d與x-d的範圍,記錄所有點的y值,若有點距離小於d則取代
(4-3)Give a set S = {(7, 1), (5, 8), (2, 6), (1, 2), (6, 5), (5, 3), (8, 7), (10, 5)} of planar points, please use the Divide-and-Conquer method to find a pair of points which are closest together and calculate its distance. Please explain each step of your solution
The convex hullof a set of planar points is the smallest convex polygon containing all of the points.Concave polygon: Convex polygon:
T(n) = 2T(n/2)+O(n) = O(nlogn)
找出每個點之間的中線
邊的數量<=3n-6(n:點)
頂點數量<=2n-4
(4-2)Please take a graphic example to show how to merge two Voronoi Diagrams, and explain the graph
(4-4)Give a set S = {(7, 1), (5, 8), (2, 6), (1, 2), (6, 5), (5, 3)} of planar points, please draw the Voronoi Diagram and indicate its Voronoi points, Voronoi edges, and Voronoi polygons
T(n) = 2T(n/2) + O(n) = O(n log n)
(4-5)How to find the convex hull in a set S of planar points and a Voronoi diagram, respectively
藉由DFT反轉,可得複雜度 O(n log n)