![]() ![]() Topic: Divide and ConquerĪnalysis: Worst-Case for MergeSort is: Best-Case & Average-Case? Merge sort pays no attention to the original order of the list, it will keep divide the list into half until sub-lists of length 1, then start merging. Procedure Merge (low, mid, high) begin while (i mid and j high) if A(i) mid) move A(j) through A(high) to U(k) through U(high) else move A(i) through A(mid) to U(k) through U(high) for p low to high A(p) U(p) end Spring-2005 Young CS 331 D&A of Algo. The algorithm: procedure MergeSort (low, high) begin if then call MergeSort (low, mid) call MergeSort (mid+1, high) call Merge (low, mid, high) end Spring-2005 Young CS 331 D&A of Algo. Merge Sort The problem: Given a list of n numbers, sort them in non-decreasing order idea: Split each part into 2 equal parts and sort each part using Mergesort, then merge the two sorted sub-lists into one sorted list.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |