![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
基础算法
文章平均质量分 68
楠楠暖暖
这个作者很懒,什么都没留下…
展开
-
Fibonaci线性复杂度
def fib(n): sum=1 first = 1 second = 1 count = 3 while count<=n: sum = first+second first = second second = sum count+=1 return sumb = fib(6...转载 2018-03-15 08:31:20 · 276 阅读 · 0 评论 -
二插搜索
前提:数据是有序复杂度分析:最好为1次,最坏和平均复杂度为O(logn)。def binarySearch(target,sortedLyst): left = 0 right = len(sortedLyst)-1 while left<=right: midpoint = (left+right)//2 if target == s...转载 2018-03-15 08:33:39 · 162 阅读 · 0 评论 -
快速排序
import randomdef swap(lyst,i,j): lyst[i],lyst[j]=lyst[j],lyst[i]def quicksort(lyst): quicksortHelper(lyst,0,len(lyst)-1)def quicksortHelper(lyst,left,right): if left<right: p...原创 2018-03-10 21:00:14 · 103 阅读 · 0 评论 -
冒泡排序
def swap(lyst,i,j): lyst[i],lyst[j]=lyst[j],lyst[i]def bubbleSort(lyst): n = len(lyst) while n>1: i = 1 while i<n: if lyst[i]<lyst[i-1]: ...原创 2018-03-10 21:02:07 · 101 阅读 · 0 评论 -
插入排序
def insertionSort(lyst): i = 1 while i<len(lyst): itemToInsert=lyst[i] j = i-1 while j>=0: if itemToInsert<lyst[j]: lyst[j+1]=lyst[...原创 2018-03-10 21:04:22 · 195 阅读 · 0 评论 -
选择排序
def swap(lyst,i,j): lyst[i],lyst[j]=lyst[j],lyst[i]def selectionSort(lyst): i = 0 while i<len(lyst)-1: minIndex = i j = i+1 while j<len(lyst): if...原创 2018-03-10 21:05:30 · 114 阅读 · 0 评论 -
合并排序
from numpy import *def mergeSort(lyst): copyBuffer = arange(len(lyst)) mergeSortHelp(lyst,copyBuffer,0,len(lyst)-1)def mergeSortHelp(lyst,copyBuffer,low,high): if low<high: mi...原创 2018-03-13 10:26:33 · 132 阅读 · 0 评论