当前位置:网站首页>Master formula. (used to calculate the time complexity of recursion.)
Master formula. (used to calculate the time complexity of recursion.)
2022-07-07 12:45:00 【Kinght_ one hundred and twenty-three】

One 、Mster The formula

Prerequisite :
- The size of the recursive subproblem must be the same .
Now let me explain , The specific meaning of this formula .
First a Is the number of calls on the scale of a subproblem of a recursive problem ,d Is the number of subproblems , hinder N Of d The power is the call except for the recursive subproblem , The time complexity of the scale of other problems .
for instance :
def func(arr, l, r): # Again arr The largest value found in the array
if l == r:
return arr[l]
mid = l + ((r - l) >> 1)
l_max = func(arr, l, mid)
r_max = func(arr, mid + 1, r)
return max(l_max, r_max)
For example, the above code is a simple recursion .
Well, its T(N) = 2 * T(N / 2) + O(1)
Because every time you call the main function , You need to call the function of the subproblem with the same scale twice , So for 2 * T(N / 2), And because it calls functions of subproblems , Other time complexity is O(1). So this is the recursive Master The formula .
Two 、 Time complexity of calculation

According to this formula and our code above , The time complexity should be O(N)
边栏推荐
- 解密GD32 MCU产品家族,开发板该怎么选?
- gcc 编译报错
- 【从 0 开始学微服务】【03】初探微服务架构
- Day-20 file operation, recursive copy, serialization
- NPM instal reports agent or network problems
- [爬虫]使用selenium时,躲避脚本检测
- 2022危险化学品生产单位安全生产管理人员考题及在线模拟考试
- Tutorial on principles and applications of database system (009) -- conceptual model and data model
- 【统计学习方法】学习笔记——支持向量机(上)
- About web content security policy directive some test cases specified through meta elements
猜你喜欢

【深度学习】图像多标签分类任务,百度PaddleClas

VSCode的学习使用
![[pytorch practice] use pytorch to realize image style migration based on neural network](/img/20/8ed7113115709b6169be289b0c280a.png)
[pytorch practice] use pytorch to realize image style migration based on neural network

对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景

Minimalist movie website

【统计学习方法】学习笔记——支持向量机(上)

Several ways to clear floating

2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作

On valuation model (II): PE index II - PE band

How to use PS link layer and shortcut keys, and how to do PS layer link
随机推荐
图形对象的创建与赋值
通讯协议设计与实现
Cryptography series: detailed explanation of online certificate status protocol OCSP
Niuke website
Connect to blog method, overload, recursion
ip2long与long2IP 分析
广州市召开安全生产工作会议
About IPSec
Common knowledge of one-dimensional array and two-dimensional array
Several ways to clear floating
基于NeRF的三维内容生成
跨域问题解决方案
Solve server returns invalid timezone Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
【统计学习方法】学习笔记——支持向量机(上)
IPv6 experiment
利用棧來實現二進制轉化為十進制
visual stdio 2017关于opencv4.1的环境配置
浅谈估值模型 (二): PE指标II——PE Band
SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
[statistical learning methods] learning notes - Chapter 5: Decision Tree