Ytl's Java Blog

          厚積而薄發(fā)---每一天都是一個全新的開始

          Algorithm to merge sorte

          Posted on 2011-05-06 17:05 ytl 閱讀(324) 評論(0)  編輯  收藏 所屬分類: Algorithms and programming concepts
          Merge sort is an O(n log ncomparison-based sorting algorithm. Most implementations produce a stable sort, meaning that the implementation preserves the input order of equal elements in the sorted output. It is a divide and conquer algorithm. Merge sort was invented by John von Neumann in 1945. A detailed description and analysis of bottom-up mergesort appeared in a report byGoldstine and Neumann as early as 1948
           divide and conquer algorithm: 1, split the problem into several subproblem of the same type. 2,solove independetly. 3 combine those solutions



          Python Implement
            
            def mergeSort(L):
                 
                   if len(L) < 2 :
                         return  L
                   middle = len(L)/2
                   left = mergeSort(L[:mddle])
                   right = mergeSort(L[middle:])
                   together = merge(left,right)
                   return together
          主站蜘蛛池模板: 临沭县| 霍林郭勒市| 潮州市| 东方市| 东辽县| 莒南县| 溆浦县| 司法| 萨嘎县| 永寿县| 信阳市| 景德镇市| 四平市| 华宁县| 渝中区| 高青县| 鄂托克前旗| 洛阳市| 盐山县| 长岛县| 永清县| 无为县| 和硕县| 张家港市| 林甸县| 萨迦县| 晋州市| 无为县| 白玉县| 库尔勒市| 桐城市| 开封县| 长寿区| 贵南县| 右玉县| 秦皇岛市| 黄浦区| 嫩江县| 兰坪| 岗巴县| 太康县|