Master theorem provides a solution in asymptotic terms to solve time complexity problem of most divide and conquer algorithms.

Recurrence relations of the form:

T(n) = a T(n/b) + f(n) where a >= 1 and b > 1

Case 1:

f(n) = O(nc) where c < loga

Then: T(n) = Θ(nlogb a)

Case 2:

f(n) = Θ(nlogkn) where c = logb a
Then: T(n) = Θ(nc logk+1n)

Case 3:

f(n) = Ω(nc) where c > logb a

a f(n/b) <= k f(n) for some constant k < 1 and sufficiently large n

Then: T(n) = Θ(f(n)) 

Examples


 1. T(n) = 2 T(n/2) + n2

 a = 2, b = 2, f(n) = n -> c = 2 > logb a

And 2 (n2 / 4) <= k n2, choosing k = 1/2

2. Binary Search

T(n) = T(n/2) + O(1)

T(n) = O(log n)

3. Merge Sort

T(n) = 2 T(n/2) + O(n)

T(n) = O(n log n)

Notes


There are some conditions where we cannot apply master theorem.

1. a < 1 or b < 1

2. f(n) is not positive

3. f(n) = n / (log n)

Because 1/(log n) < nε for any constant ε > 0.

Master Theorem的更多相关文章

  1. 对主定理(Master Theorem)的理解

    前言 虽说在学OI的时候学到了非常多的有递归结构的算法或方法,也很清楚他们的复杂度,但更多时候只是能够大概脑补这些方法为什么是这个复杂度,而从未从定理的角度去严格证明他们.因此借着这个机会把主定理整个 ...

  2. 重新粗推了一下Master Theorem

    主定理一般形式是T(n) = a T(n / b) + f(n), a >= 1, b > 1.递归项可以理解为一个高度为 logbn 的 a 叉树, 这样 total operation ...

  3. 主定理(Master Theorem)与时间复杂度

    1. 问题 Karatsuba 大整数的快速乘积算法的运行时间(时间复杂度的递推关系式)为 T(n)=O(n)+4⋅T(n/2),求其最终的时间复杂度. 2. 主定理的内容 3. 分析 所以根据主定理 ...

  4. 算法设计与分析 - 主定理Master theorem (分治法递推时间复杂度)

    英文原版不上了 直接中文 定义 假设有递推关系式T(n)=aT(n/b)+f(n) 其中n为问题规模 a为递推的子问题数量 n/b为每个子问题的规模(假设每个子问题的规模基本一样) f(n)为递推以外 ...

  5. Heapsort 堆排序算法详解(Java实现)

    Heapsort (堆排序)是最经典的排序算法之一,在google或者百度中搜一下可以搜到很多非常详细的解析.同样好的排序算法还有quicksort(快速排序)和merge sort(归并排序),选择 ...

  6. ACM 入门计划

    acm 本文由swellspirit贡献 ACM • I can accept failure. but I can't accept not trying. Life is often compar ...

  7. [Algorithm] 如何正确撸<算法导论>CLRS

    其实算法本身不难,第一遍可以只看伪代码和算法思路.如果想进一步理解的话,第三章那些标记法是非常重要的,就算要花费大量时间才能理解,也不要马马虎虎略过.因为以后的每一章,讲完算法就是这样的分析,精通的话 ...

  8. 【Python算法】递归与递归式

    该树结构显示了从1(根节点)到n(n个叶节点)的整个倍增过程.节点下的标签表示从n减半到1的过程. 当我们处理递归的时候,这些级数代表了问题实例的数量以及对一系列递归调用来说处理的相关工作量. 当我们 ...

  9. 某Facebook工程师写的攻略。

    Chapter 1 Interesting read, but you can skip it. Chapter 2 2.1 Insertion Sort - To be honest you sho ...

随机推荐

  1. UESTC_Dividing Numbers CDOJ 1156

    Dividing Numbers Time Limit: 9000/3000MS (Java/Others)     Memory Limit: 262144/262144KB (Java/Other ...

  2. Spring AOP应用实例demo

    AOP(Aspect-Oriented Programming.面向方面编程).能够说是OOP(Object-OrientedPrograming.面向对象编程)的补充和完好.OOP引入封装.继承和多 ...

  3. "a newer version of unity web player is required but the auto-update failed"

    问题背景描述: 项目采用winform调用unity web player作为播放器在客户端使用. 在有些环境会出现标题所示错误. 经过一翻研究后发现是插件在向服务器请求更新以下文件时报http 30 ...

  4. NFinal简介

    NFinalWeb框架是基于魔法糖语法思想创建的框架.本框架有两大特点.1.所有框架里最简单易学易配置的.2.所有框架里运行效率最快的. 相关介绍1.运行效率比任何php和java以及.net框架要快 ...

  5. 将集合类转换成DataTable

    /// <summary> /// 将集合类转换成DataTale /// </summary> /// <param name="list"> ...

  6. 0118——UIButtton

    1.Button的定义 UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; Button有六种类型 enum { UI ...

  7. (转) Name visibility

    Scopes Named entities, such as variables, functions, and compound types need to be declared before b ...

  8. C语言enum再学习

    通常来说我们使用enum是这样的: enum week{ Mon, Tue, ... Sun }; enum week w; w = Mon; 这里默认Mon~Sun的值为0~6 也可以自己定值 , ...

  9. Python中的Copy和Deepcopy

    一,Python的对象: Python存在大量的对象,我们一般提到的对象都是C中的结构体在堆中申请的一块内存(以CPython为例),每一个对象都有ID,可以通过ID(Object)获得.对象的范围包 ...

  10. UltraEdit v17.10.0,注册机,注册码

    1,UltraEdit注册机 :点击下载 2,断掉网络,进入UltraEdit软件,依次点击:帮助——注册/激活——激活,会提示你进行脱机激活,点击脱机激活后,将用户码1和用户码2 分别输入注册机的u ...