Analysis of Algorithm 2: Master theorem & Math induction
来源:互联网 发布:航测内页成图软件 编辑:程序博客网 时间:2024/05/18 15:07
Using Master theorem to get Running time of Algorithm T(n)
- For Divided-and-Conquer to get Running time T(n)
Here is the Master theorem
Ex.1 Merge sort
according to Master theorem:
∴T(n)=Θ(nlogab⋅logn) according to Math induction:
T(n)={1,n=12T(n/2)+n,n>1 =2(2T(n/4)+n/2)+n =2(2T(2T(n/8)+n/4)+n/2)+n =......... =n⋅logn+n ∴T(n)=n⋅logn
- The fullyexpanded tree in part (d) has
logn + 1 levels (i.e., it has height lg n, as indicated), and each level contributes a total cost ofc⋅n (for merge cost: each level will costc⋅n to merge all sub-problems ). The total cost, therefore, iscn⋅logn+cn , which isΘ(nlogn) .
Ex.2 Insertion Sort
Math induction:
In the Worst-case: T(n)=∑i=2ni≈∫ni=2i di≈12n2≈Θ(n2) We can express insertion sort as a recursive procedure as follows. In order to sort
A[1..n] , we recursively sortA[1..n−1] and then insertA[n] into the sorted arrayA[1..n−1] . Write a recurrence for the running time of this recursive version of insertion sort.T(n)={1 , n =1T(n−1)+n , n > 1 for the nth loop, it will cost n−1 moves and 1 time insertion in the worst-case ∴T(n)≈12n2≈Θ(n2) So, the O notation of Insertion Sort is: O(n2)
- Ex.3 Bubblesort
math method:T(n)=∑i=1n(i−1) Explanation: this equation represent that when there are i elements need to be sorted, it will take exchange i-1 times to place one element in worst-case ∴T(n)≈Θ(n2) So, the O notation of Bubblesort is: O(n2)
Refs.
http://blog.csdn.net/lanchunhui/article/details/52451362
阅读全文
0 0
- Analysis of Algorithm 2: Master theorem & Math induction
- Summary of Analysis of Algorithm
- the master theorem of divide-and-conquer
- Algorithm.Induction(归纳法)
- !!!Chapter 2 Algorithm Analysis
- Analysis and implement of Consistent Hashing Algorithm
- Week 1 Analysis of Algorithm(算法分析)
- Week1-6Analysis of Algorithm Introduction
- 主定理 Master Theorem
- MIT算法导论——第一讲.Analysis of algorithm
- Coursera Algorithms, Part 1 Week 1: Analysis of Algorithm
- MIT算法导论——第一讲.Analysis of algorithm
- MIT算法导论——第一讲.Analysis of algorithm
- (TODO)Empirical Analysis of Predictive Algorithm for Collaborative Filtering
- Algorithm Analysis 算法分析
- DataStructures:algorithm analysis
- Asymptotic Algorithm Analysis
- algorithm analysis 开坑1
- PhpStorm 激活方法(常期更新)
- 关于TP5使用GuzzleHttp发送请求遇到的问题解决
- 51nod1450 闯关游戏
- 【C语言】一维数组
- 高德地图WEB端,在所画的圆(Circle)内显示在圆(Marker)内的点
- Analysis of Algorithm 2: Master theorem & Math induction
- oracle之sqlldr命令数据导入
- java的八种基本数据类型
- java 动态代理
- Volley请求封装
- spring-boot入门学习笔记
- ios打LOG 打出函数调用详细堆栈
- java把大数据类型的包装类
- 移动硬盘数据丢失如何恢复