Lecture 3: part-and-Conquer Algorithms © ¢ ¨¦¤ §¥ ¢ £¡  We just derived an divide-and-conquer algorithmic rule for figure out the level best Contiguous Subarray problem. © ¢ ¦¤ §¥ ¢ £¡  In COMP171 you already adage Mergesort, an time divide-and-conquer form algorithm. Divide-and-Conquer is not a trick. It is a actually useful everyday purpose tool for designing ef?cient algorithms. 1 The Basic Divide-and-Conquer Approach Divide: Divide a apt(p) problem into both subproblems (ideally of approximately be size). Conquer: light up distributively subproblem (directly or recursively), and Combine: Combine the solutions of the two subproblems into a global solution. Note: the hard work and briskness is usually in the Combine step. 2 MERGESORT  ¨ © §¥¤¢ ¡¡ ¦¢£  Sort ¦ £ © Mergesort If Mergesort ©¦ © £ @ §¡ ¦ 20! $76( 5 0! $5 76( 2 ! 2 10 & ¦§¢ ()$ 9 6¢  8 ! 2 31 0 ( &$ ¢£ )%#¥¤¢  4 4  E ¦ §¢ 1 ¤¡ £ Mergesort Merge the two sorted lists and and pop off complete sorted list 0 ( &$ )% 9 FA 8  0 ( &$ £ )DCBA E 1  G The algorithm sorts an array of size by ripping it into two parts of (almost) equal size, recursively sorting all(prenominal) of them, and then get together the two sorted subarrays back together into a in full sorted list in time (how?).
¡  © H ¡  9 U© S V© 3 H T H ¡ S 4 R© H ¡ ¢ Q8 4 P H! I which we previously saw implies © H The running time of the algorithm satis?es H §¥ ¦¤ H ¡  © H ¡ 4 Mergesort Example 3 13 8 4 11 24 ¢ 12 23  ¢   13 8 £ ¤¢  ¡ 3 ¢ 12 23 ¢ split 4 11 24 sort each sublist ¥ ¥ 12 13 23 4 8 ¦ ¦ Merge   ¦ § ¨¦ ¡ ¦ 4  3 11 24  3 8 11 12 13 23 24 4...If you want to get a full essay, do it on our website: OrderCustomPaper.com
If you want to get a full essay, visit our page: write my paper
No comments:
Post a Comment