【MIT 公开课】Computer Science and Programing Lession 10
2017-03-28 23:21
239 查看
一.分治算法:不断缩小问题的规模的算法。如二分法查找,归并排序。
如下是归并排序算法,主要思想为:先将一个列表分成左右两个列表,再左右分别继续分,直至分成每个列表中只有一个元素,再将两个列表进行归并排序,层层merge到最后左右两个列表进行merge。
复杂度为O(nlogn)
二.哈希算法:复杂度为常数的一个搜索算法,python实现字典的算法。是一种以空间换时间的算法
哈希表就是一种以 键-值(key-indexed) 存储数据的结构,我们只要输入待查找的值即key,即可查找到其对应的值。在构造这种特殊的“查找表” 时,需要选择一个“好”(尽可能少产生冲突)的哈希函数。
哈希算法的更多内容参考http://blog.csdn.net/tanggao1314/article/details/51457585
三.python的异常和断言
异常:try...except
断言:assert 断言是一句必须等价于布尔真的判定
如下是归并排序算法,主要思想为:先将一个列表分成左右两个列表,再左右分别继续分,直至分成每个列表中只有一个元素,再将两个列表进行归并排序,层层merge到最后左右两个列表进行merge。
def merge(left,right): """Assumes left and right are sorted lists. Returns a new sorted list containing the same elements as (left + right) would contain.""" result = [] i,j = 0, 0 while i < len(left) and j < len(right): if left[i] <= right[j]: result.append(left[i]) i = i + 1 else: result.append(right[j]) j = j + 1 while (i < len(left)): result.append(left[i]) i = i + 1 while (j < len(right)): result.append(right[j]) j = j + 1 return result
def mergesort(L): """Returns a new sorted list with the same elements as L""" print L if len(L) < 2: return L[:] else: middle = len(L) / 2 left = mergesort(L[:middle]) right = mergesort(L[middle:]) together = merge(left,right) print 'merged', together return together
复杂度为O(nlogn)
二.哈希算法:复杂度为常数的一个搜索算法,python实现字典的算法。是一种以空间换时间的算法
哈希表就是一种以 键-值(key-indexed) 存储数据的结构,我们只要输入待查找的值即key,即可查找到其对应的值。在构造这种特殊的“查找表” 时,需要选择一个“好”(尽可能少产生冲突)的哈希函数。
哈希算法的更多内容参考http://blog.csdn.net/tanggao1314/article/details/51457585
三.python的异常和断言
异常:try...except
断言:assert 断言是一句必须等价于布尔真的判定
相关文章推荐
- 【MIT 公开课】Computer Science and Programing Lession 12
- 【MIT 公开课】Computer Science and Programing Lession 11
- 【MIT 公开课】Computer Science and Programing Lession 9
- 【MIT 公开课】Computer Science and Programing Lession 14
- 【MIT 公开课】Computer Science and Programing Lession 8
- MIT《Introduction to Computer Science and Programming》: Testing and Debugging
- MIT Electrical Engineering and Computer Science 参考书整理
- MIT Computer Science And Artificial Intelligence Laboratory
- MIT 6.00 Introduction to Computer Science and Programming, Fall 2008
- 10 most In-demand job titles for computer science majors and their salaries:
- MIT Introduction to Computer Science and Programming (Lesson one )
- MIT 6.00 Introduction to Computer Science and Programming, Fall 2008
- Some Personal Feelings and Suggestions for Taking Math Courses as a Computer Science Major Student
- mit课程electrical-engineering-and-computer-science/
- Computer and computer Science(计算机与计算机科学)
- How do you explain Machine Learning and Data Mining to non Computer Science people?
- computer science and technology
- mit课程electrical-engineering-and-computer-science/
- 斯坦福大学公开课 :机器学习课程(Andrew Ng)——10、无监督学习:Mixture of Gaussians and the EM Algorithm
- Queueing Networks and Markov Chains : Modeling and Performance Evaluation with Computer Science Appl