Algorithm Final Presentation

347 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
347
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Algorithm Final Presentation

  1. 1. 演算法分析與設計 期末報告
  2. 2. 銘傳大學資訊工程所 一年級周家聖 E-mail : johnsonchou1129@hotmail.com
  3. 3. 指導老師徐熊健老師
  4. 4. PruneandSearch 刪減搜尋 法
  5. 5. Literal字面
  6. 6. Prune 刪減
  7. 7. 搜尋 Search
  8. 8. Recursive遞迴
  9. 9. 範例Example
  10. 10. SelectionProblem 選擇 問題
  11. 11. Selection ProblemInput : A set elements S and k. Output : The k-th smallest element in S.
  12. 12. Step 1. Divide Elements into [n/5] subsets
  13. 13. Step 2. Sort each subset
  14. 14. Each 5-element subset is sorted in non-decreasing sequence.
  15. 15. Step 3. Find a element P which is the median of the medians of the n/5 subsets.
  16. 16. P M
  17. 17. Step 4. S intoPartitionS1, S2 and S3,which contain the elementsless than, equal to, and greater than p,respectively.
  18. 18. Step 5. Case IIf |S1| > k, thendiscard S2 and S3 andsolve the problem that S1selects the k-th smallest element fromduring the next iteration
  19. 19. P M At least 1/4 of S known to be greater than or equal to P.
  20. 20. Step 5. Case IIif|S1| + |S2| > kthen P is the k-th smallest element of S
  21. 21. P M
  22. 22. Step 5. Case IIIotherwise,let k = k - |S1| - |S2|,solve the problem that selects the k-th smallestelement from S3 during the next iteration.
  23. 23. At least 1/4 of S known to be less than or equal to P. P M
  24. 24. Time complexity: T(n) = O(n)step 1: O(n)step 2: O(n)step 3: T(n/5)step 4: O(n)step 5: T(3n/4) => T(n) = T(3n/4) + T(n/5) + O(n)
  25. 25. LetT(n) = a0 + a1n + a2n2 + … , a1 != 0T(3n/4) = a0 + (3/4)a1n + (9/16)a2n2 + …T(n/5) = a0 + (1/5)a1n + (1/25)a2n2 + …T(3n/4 + n/5) = T(19n/20) = a0 + (19/20)a1n + (361/400)a2n2 + …thus,T(3n/4) + T(n/5) <= a0 + T(19n/20)
  26. 26. T(n) = T(3n/4) + T(n/5) + O(n)<= cn + T(19n/20) = cn + (19/20)cn + T((19/20)2n) = cn + (19/20)cn + (19/20)2cn + …+ (19/20)pcn + T((19/20)p+1n) , (19/20)p+1n <= 1 <= (19/20)pn 19 p + 1 1− ( ) 20 = 19 cn + b 1− 20 <= 20cn +b = ...
  27. 27. O(n)
  28. 28. Prune and Search定義
  29. 29. Many Iterations很多回合
  30. 30. Prunes away a fraction, each iteration刪除部分 每回合
  31. 31. so small,solved directly in constant time c 量少 常數時間內 解決
  32. 32. 所以 ... T(n) <= T((1 - f ) n) + cnk for sufficiently large n.  <= T((1 - f )2n) + cnk + c(1 - f )knk ...  <= c’+ cnk + c(1 - f )knk + c(1 - f )2knk + ... + c(1 - f )pknk = c’+ cnk(1 + (1 - f )k + (1 - f )2k + ... + (1 - f ) pk). Since 1 - f < 1, as n , T(n) = O(nk)Thus, the whole time-complexityis as the same order as the time-complexityeach iteration.
  33. 33. 1-Center Problem
  34. 34. Given n planar points, find a smallest circle to cover these n points.
  35. 35. Constrained 1-Center Problem
  36. 36. The center is restricted to lying on a straight line. Lij Pi Pj y=0 xij x* xm
  37. 37. Constrained 1-Center ProblemInput :n points and a straight line y = y Output : The constrained center on the line y = y
  38. 38. Step 1: If n is no more than 2, solve this problem by abrute-force method.Step 2: Form disjoint pairs of points (p1, p2),(p3, p4), …,(pn-1, pn). If there are odd number of points, just letthe final pair be (pn, p1).Step 3: For each pair of points, (p , p ), find the point i i+1xi,i+1 on the line y = y’ such that d(pi, xi,i+1) = d(pi+1, xi,i+1).Step 4: Find the median of the all x i,i+1 ’s. Denote it as x m.
  39. 39. Step 5 :Calculate the distance between p and x i m for all i. Let pj bethe point which is farthest from xm. Let xj denote the projectionof pj onto y = y.If xj is to the left (right) of xm, then the optimal solution, x* ,must be to the left (right) of xm.Step 6:If x* < xm, for each xi,i+1 > xm, prune the point piif pi is closer to xm than pi+1, otherwise prune the point pi+1;If x* > xm, do similarly.Step 7: Go to Step 1.
  40. 40. By the constrained 1-center algorithm, we can determine the center(x ,0) on the line y=0. * Time complexity : O(n)
  41. 41. We can do more不只這樣
  42. 42. Let (xs, ys) be the center of the optimum circle.We can determine whether ys > 0, ys < 0 or ys = 0.Similarly, we can also determine whether xs > 0, xs < 0 or xs = 0.
  43. 43. Sign of The Optimal yLet I be the set of points which are farthest from (x*, 0).
  44. 44. Case 1:I contains one point P = (x , y ). p p ys has the same sign as that of yp.
  45. 45. Case 2 : I contains more than one point.Find the smallest arc spanning all points in I. Let P1 = (x1, y1) and P2 = (x2, y2) be the two end points of the arc.
  46. 46. If this arc >= 180 o , then ys = 0. P1 (x*, 0) y=0 P3 P2 (a)
  47. 47. y1 + y2else ys has the same sign as that of 2 . P1 P3 P4 P2 y=0 (x*, 0) (b)
  48. 48. 1-Center Problem
  49. 49. 1-Center ProblemInput: A set S = {p , p , …, p } of n points. 1 2 nOutput: The smallest enclosing circle for S.
  50. 50. Step 1: If S contains no more than16 points, solve the problem by a brute-force method.
  51. 51. Step 2: Form disjoint pairs of points, (p1, p2), (p3, p4), …,(pn-1, pn). For each pair of points, (pi, pi+1),find the perpendicular bisector of line segment p i p i + 1 . Denote them as Li/2, for i = 2, 4, …, n, and compute their slopes. Let the slope of Lk be denoted as sk , for k = 1, 2, 3, …, n/2.
  52. 52. Step 3: Compute the median of s ’s, and k denote it by s . m Step 4: Rotate the coordinate system so that the x-axis coincide with y = smx .Let the set of Lks with positive (negative) slopes be I+ (I-). (Both of them are of size n/4.)
  53. 53. Step 5: Construct disjoint pairs of lines, (Li+, Li-) for i = 1, 2, …, n/4, ¿ where Li+ in I+ and Li- in I-.Find the intersection of each pair and denote it by (ai, bi), for i = 1, 2, …, n/4.
  54. 54. Step 6: Find the median of b ’s. i Denote it as y*. Apply the constrained 1-center subroutineto S, requiring that the center of circle be located on y=y*. Let the solution of this constrained 1-center problem be (x, y*).
  55. 55. Step 7: Determine whether (x, y*) is the optimal solution. If it is, exit;otherwise, record ys > y* or ys < y*.
  56. 56. Step 8: If y > y*, find the median of a ’s for s i those (a , b )’s where bi < y*. i i If ys < y*, find the median of ais of those t hose (ai, bi)’s where bi > y*. Denote the median as x* .Apply the constrained 1-center algorithm to S, requiringthat the center of circle be located on x = x*. Let the solution of this contained 1-center problem be (x*, y).
  57. 57. Step 9: Determine whether (x*, y) is the optimal solution. If it is, exit;otherwise, record xs > x* or xs < x*.
  58. 58. Step 10: Case 1: xs > x* and ys > y* . Find all (ai, bi)s such that ai < x* and bi < y*. Let (ai, bi) be the intersection of Li+ and Li-. Let Li- be the bisector of pj and pk.Prune away pj(pk) if pj(pk) is closer to (x*, y*) than pk(pj). Case 2: xs < x* and ys > y*. Do similarly. Case 3: xs < x* and ys < y*. Do similarly. Case 4: xs > x* and ys > y*. Do similarly.Step 11: Let S be the set of the remaining points. Go to Step 1.
  59. 59. Time complexityT(n) = T(15n/16)+O(n) = O(n)
  60. 60. Thanks for your listening 感謝 聆聽End

×