Insertion Sort and Merge Sort
来源:互联网 发布:jquery easing.js下载 编辑:程序博客网 时间:2024/05/17 08:43
Analysis of Algorithms
The theoretical study of computer-program performance and resource usage.
What is more important than performance?
user-friendliness
stability
security
……
Why study algorithms and performance?
1.measures the line between the feasible and infeasible.
real-time requirement
2.algorithm is a language for talking about program behavior.
Java is slower than C
universal
3.fun
Problem:Sorting
Input:sequence
Ouput:permutation
increasing
Insertion sort
running time
- depends on input(eg.already sortd)
- depends on input size(6 elements vs 6 billion)
- parameterize in input size
- upper bounds of the time
- guarantee for the users
Kinds of analysis
Worst-case (usually)
T(n)=max time on any input of size n
Average-case (sometimes)
T(n)=expected time over all inputs of size n
Need a assumption of statistical distribution
Best-case (bogus)
Cheat
What is insertion sorts worst-case time?
Depends on the computer.
- relative speed (on same machine)
- absolute speed(on different machines)
Big Idea!
Asymptotic Analysis
- Ignore machine-dependent constants
- Look a t the growth of T(n) as n→∞
Asymptotic notation
θ notation:Drop low-order terms Ignore leading constants.
It’s a weak notation.
Ex.
As n→∞
Insertion sort analysis
worst-case:input reverse sorted
arithmetic series
Is insertion sort fast?
- Moderately fast for small n.
- Not at all for large n.
Merge sort
1. T(n)=
2.
3.
Recurrence
T(n)=
Recursion tree:T(n)=2T(n/2)+cn, constant c >0
Code for Insertion Sort:
Insertion Sort code in github
Code for Merge Sort:
Merge Sort code in github
- Insertion Sort and Merge Sort
- Insertion sort and Merge sort
- Insertion Sort and Merge Sort
- Insertion sort, select sort, Quick sort and Merge sort
- Insertion Sort, Merge Sort
- Sort List (merge & Insertion)
- Bubble sort, Insertion sort, merge sort, quick sort, heap sort
- Merge Sort Array --> Merge Sort Linked List --> Insertion Sort Array --> Insertion sort Linked List
- Merge Sort and Inversion
- Introduction: Analysis of Algorithms, Insertion Sort, Merge Sort
- 排序算法:Insertion Sort和Merge Sort in GoLang
- Insertion Sort
- Insertion Sort
- insertion sort
- insertion sort
- Insertion Sort
- insertion sort
- insertion sort
- 我推荐的好资源
- 前端开发第一天学习内容总结
- 文件内容的简单比较(C++)
- jQuery22(替换元素,包裹元素)
- 设计模式六大原则
- Insertion Sort and Merge Sort
- jQuery23(获取radiobuttomvalue及选中)
- OpenvSwitch Port Mirror in OpenStack Neutron
- HDU 1358 Period
- NHibernate的几种查询方式
- 那年声明理解不了定义与初始化(一)
- 01背包问题一维空间优化的理解
- 开头很艰难,但也要写下去
- apache commons io 2.2(二)Filter部分