Merge sort by using recursive strategy, i.e. divide and conquer.

def merge(left,right):
result = []
i,j =,
while i < len(left) and j < len(right):
if left[i]<right[j]:
result.append(left[i])
i +=
else:
result.append(right[j])
j +=
result += left[i:]
result += right[j:]
return result def merge_Sort(seq):
if len(seq)<=:
return seq
mid = len(seq)/
left = merge_Sort(seq[:mid])
right = merge_Sort(seq[mid:])
return merge(left,right) seq = [, , , , , , , , , , , , , , , , , , , , ]
merge_Sort(seq)
def ins_sort_rec(seq,i):
if i==: return
ins_sort_rec(seq,i-)
j = i
while j > and seq[j - ] > seq[j]:
seq[j -],seq[j] = seq[j], seq[j-]
j -=
return seq seqq = [,,,,,,,,,,,,,] a = ins_sort_rec(seqq,len(seqq)-)
a def insertsort(seq):
for i in range(,len(seq)):
j = i
while seq[j] <seq[j-] and j>:
seq[j],seq[j-] = seq[j-],seq[j]
j -=
return seq b = insertsort(seqq)
b def changesort(seq):
count = True
while count:
count = False
for i in range(,len(seq)):
if seq[i]<seq[i-]:
seq[i],seq[i-] = seq[i-],seq[i]
count =True
return seq ls = [,,,,,,,,,,,,,]
c = changesort(ls)
c seqq = [,,,,,,,,,,,,,] def selectsort(ls):
for i in range(len(ls)-):
k = i
for j in range(i,len(ls)):
if ls[k] >ls[j]:
k = j
if k !=i:
ls[i],ls[k]=ls[k],ls[i]
return ls
selectsort(seqq)

 

Sorting Algorithms的更多相关文章

  1. JavaScript 排序算法(JavaScript sorting algorithms)

    JavaScrip 排序算法(JavaScript Sorting Algorithms) 基础构造函数 以下几种排序算法做为方法放在构造函数里. function ArrayList () { va ...

  2. [Algorithms] Sorting Algorithms (Insertion Sort, Bubble Sort, Merge Sort and Quicksort)

    Recently I systematicall review some sorting algorithms, including insertion sort, bubble sort, merg ...

  3. Summary: sorting Algorithms

    Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item a ...

  4. Basic Sorting Algorithms

    *稳定指原本数列中相同的元素的相对前后位置在排序后不会被打乱 快速排序(n*lgn 不稳定):数组中随机选取一个数x(这里选择最后一个),将数组按比x大的和x小的分成两部分,再对剩余两部分重复这个算法 ...

  5. 算法的稳定性(Stability of Sorting Algorithms)

    如果具有同样关键字的纪录的在排序前和排序后相对位置保持不变.一些算法本身就是稳定的,如插入排序,归并排序,冒泡排序等,不稳定的算法有堆排序,快速排序等. 然而,一个本身不稳定的算法通过一点修正也能变成 ...

  6. 1306. Sorting Algorithm 2016 12 30

    1306. Sorting Algorithm Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One of the f ...

  7. [zt]Which are the 10 algorithms every computer science student must implement at least once in life?

    More important than algorithms(just problems #$!%), the techniques/concepts residing at the base of ...

  8. Top 10 Algorithms for Coding Interview--reference

    By X Wang Update History:Web Version latest update: 4/6/2014PDF Version latest update: 1/16/2014 The ...

  9. 转:Top 10 Algorithms for Coding Interview

    The following are top 10 algorithms related concepts in coding interview. I will try to illustrate t ...

随机推荐

  1. 2、iptables基本应用

    iptables:规则管理工具 添加.修改.删除.显示等: 规则和链有计数器: pkts:  由规则或链所匹配到的报文的个数: bytes:由规则或链匹配到的所有报文大小之和: iptables命令: ...

  2. 【译】第44节---EF6-存储过程映射

    原文:http://www.entityframeworktutorial.net/entityframework6/code-first-insert-update-delete-stored-pr ...

  3. linux golang

    wget -c http://www.golangtc.com/static/go/go1.3.linux-386.tar.gz #下载32位Linux的够源码包 tar -zxvf go1.1.li ...

  4. 小米MAX开发者选项 以及如何连接MAC开发RN

    打开开发者选项:设置--我的设备---全部参数-- 多次点击MiUI版本 打开开发者选项 然后返回到设置的主页面里面的更多设置就可以看到开发者选项了 在开发者选项中打开 USB调试/USB安装 将启动 ...

  5. GYM 101064 2016 USP Try-outs G. The Declaration of Independence 主席树

    G. The Declaration of Independence time limit per test 1 second memory limit per test 256 megabytes ...

  6. tornado关于AsyncHTTPClient的使用笔记

    先来一段同步的httpclient使用代码 url = 'https://www.baidu.com/' http_client = HTTPClient() response = http_clie ...

  7. ThreadPoolExecutor最佳实践--如何选择线程数

    去年看过一篇<ThreadPoolExecutor详解>大致讲了ThreadPoolExecutor内部的代码实现. 总结一下,主要有以下四点: 当有任务提交的时候,会创建核心线程去执行任 ...

  8. Spring @Configuration 和 @Bean 注解

    @Configuration 和 @Bean 注解 带有 @Configuration 的注解类表示这个类可以使用 Spring IoC 容器作为 bean 定义的来源.@Bean 注解告诉 Spri ...

  9. 力扣(LeetCode)476. 数字的补数

    给定一个正整数,输出它的补数.补数是对该数的二进制表示取反. 注意: 给定的整数保证在32位带符号整数的范围内. 你可以假定二进制数不包含前导零位. 示例 1: 输入: 5 输出: 2 解释: 5的二 ...

  10. SpringBoot 文件上传、下载、设置大小

    本文使用SpringBoot的版本为2.0.3.RELEASE 1.上传单个文件 ①html对应的提交表单 <form action="uploadFile" method= ...