【MIT 公开课】Computer Science and Programing Lession 9
来源:互联网 发布:edg那个知恩是谁 编辑:程序博客网 时间:2024/06/07 04:45
第九课讲的是搜索和排序。
1.复习了第八课的四种算法:
线性算法:逐步减小固定值
对数算法:每次除以固定值
平方算法:嵌套调用,递归迭代调用时
指数算法:汉诺塔
2.二分法查找的思想:
(1)查找中点
(2)是否是需要找的值
(3)若不是,重复
3.二分法假设的是我们拥有的列表为有序列表。当只有一个无序列表需要进行搜索时,先排序再二分法搜索的复杂度为nlogn+logn;使用遍历法进行搜索时,复杂度为n。
一般意义来说,nlogn+logn>n。
当需要进行k次搜索时,先排序再二分法搜索的最小复杂度为nlogn+klogn;使用遍历法进行搜索时,复杂度为kn。则kn<nlogn+klogn。
即分摊开销原则。
4.如何进行排序:
(1)单元排序/选择排序:
def selSort(L): for i in range(len(L) - 1): print L minIndx = i minVal= L[i] j = i + 1 while j < len(L): if minVal > L[j]: minIndx = j minVal= L[j] j = j + 1 temp = L[i] L[i] = L[minIndx] L[minIndx] = temp
O(n^2)
(2)冒泡排序
def bubbleSort(L): for j in range(len(L)): print L for i in range(len(L) - 1): if L[i] > L[i+1]: temp = L[i] L[i] = L[i+1] L[i+1] = temp
O(len(L)^2)
0 0
- 【MIT 公开课】Computer Science and Programing Lession 9
- 【MIT 公开课】Computer Science and Programing Lession 8
- 【MIT 公开课】Computer Science and Programing Lession 12
- 【MIT 公开课】Computer Science and Programing Lession 13
- 【MIT 公开课】Computer Science and Programing Lession 14
- 【MIT 公开课】Computer Science and Programing Lession1
- 【MIT 公开课】Computer Science and Programing Lession2
- 【MIT 公开课】Computer Science and Programing Lession3
- 【MIT 公开课】Computer Science and Programing Lession7
- MIT《Introduction to Computer Science and Programming》: Testing and Debugging
- MIT Electrical Engineering and Computer Science 参考书整理
- http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/
- Computer and Computer Science
- computer science and technology
- MIT 6.042 mathematics for computer science
- 看后总结(Introduction to Computer Science and Programming,MIT 600)
- Computer and computer Science(计算机与计算机科学)
- 6.00 Introduction to Computer Science and Programming Lec 9: Set
- 直接插入排序
- 《剑指Offer》从尾到头打印链表
- 二叉树的遍历
- [PAT][GPLT][CCCC]L1-025.正整数A+B
- 分治与递归
- 【MIT 公开课】Computer Science and Programing Lession 9
- linux之线程属性(分离线程)
- 关于listview上下滑动imageview图片混乱问题
- 单例设计模式
- 个人静态blog
- shell中的命令替换
- 异常处理——异常处理简介之UnhandledExceptionFilter(1)
- 贪心算法
- 通过反射访问构造方法(学习笔记)