当前位置:网站首页>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)
边栏推荐
- Configure an encrypted web server
- Routing strategy of multi-point republication [Huawei]
- 基于NeRF的三维内容生成
- Airserver automatically receives multi screen projection or cross device projection
- [Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
- SQL blind injection (WEB penetration)
- The IDM server response shows that you do not have permission to download the solution tutorial
- 利用栈来实现二进制转化为十进制
- How to use PS link layer and shortcut keys, and how to do PS layer link
- 【统计学习方法】学习笔记——支持向量机(上)
猜你喜欢

Several methods of checking JS to judge empty objects

Day-16 set

跨域问题解决方案

Inverted index of ES underlying principle

浅谈估值模型 (二): PE指标II——PE Band
![[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer](/img/5f/75549fc328d7ac51f8b97eef2c059d.png)
[play RT thread] RT thread Studio - key control motor forward and reverse rotation, buzzer

Session

2022聚合工艺考试题模拟考试题库及在线模拟考试

Connect to blog method, overload, recursion
![[deep learning] image multi label classification task, Baidu paddleclas](/img/dd/6f213a396e8bb240a6872e4c03afab.png)
[deep learning] image multi label classification task, Baidu paddleclas
随机推荐
Ctfhub -web SSRF summary (excluding fastcgi and redI) super detailed
解密GD32 MCU产品家族,开发板该怎么选?
对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景
(to be deleted later) yyds, paid academic resources, please keep a low profile!
Static comprehensive experiment
BGP actual network configuration
Several ways to clear floating
[疑难杂症]pip运行突然出现ModuleNotFoundError: No module named ‘pip‘
Vxlan 静态集中网关
Is it safe to open an account in Ping An Securities mobile bank?
【统计学习方法】学习笔记——第四章:朴素贝叶斯法
Simple implementation of call, bind and apply
Day-20 file operation, recursive copy, serialization
GCC compilation error
【统计学习方法】学习笔记——逻辑斯谛回归和最大熵模型
【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试
Multi row and multi column flex layout
利用棧來實現二進制轉化為十進制
Idea 2021 Chinese garbled code