当前位置:网站首页>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)
边栏推荐
- 2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
- 什么是ESP/MSR 分区,如何建立ESP/MSR 分区
- Customize the web service configuration file
- Charles: four ways to modify the input parameters or return results of the interface
- Learning and using vscode
- AirServer自动接收多画面投屏或者跨设备投屏
- 【PyTorch实战】用RNN写诗
- (to be deleted later) yyds, paid academic resources, please keep a low profile!
- Preorder, inorder and postorder traversal of binary tree
- [爬虫]使用selenium时,躲避脚本检测
猜你喜欢

Tutorial on principles and applications of database system (009) -- conceptual model and data model

ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型

What if does not match your user account appears when submitting the code?
![[deep learning] image multi label classification task, Baidu paddleclas](/img/dd/6f213a396e8bb240a6872e4c03afab.png)
[deep learning] image multi label classification task, Baidu paddleclas

leetcode刷题:二叉树21(验证二叉搜索树)

Vxlan static centralized gateway

【统计学习方法】学习笔记——提升方法

【统计学习方法】学习笔记——支持向量机(下)
![[爬虫]使用selenium时,躲避脚本检测](/img/3a/85ea729be2aa76c3de4a822ca6939b.png)
[爬虫]使用selenium时,躲避脚本检测

leetcode刷题:二叉树25(二叉搜索树的最近公共祖先)
随机推荐
Sort out the garbage collection of JVM, and don't involve high-quality things such as performance tuning for the time being
VSCode的学习使用
(待会删)yyds,付费搞来的学术资源,请低调使用!
ip2long与long2IP 分析
(to be deleted later) yyds, paid academic resources, please keep a low profile!
Decrypt gd32 MCU product family, how to choose the development board?
图像像素读写操作
【统计学习方法】学习笔记——逻辑斯谛回归和最大熵模型
利用栈来实现二进制转化为十进制
How to use PS link layer and shortcut keys, and how to do PS layer link
Day-20 file operation, recursive copy, serialization
对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景
Is it safe to open an account in Ping An Securities mobile bank?
leetcode刷题:二叉树24(二叉树的最近公共祖先)
Aike AI frontier promotion (7.7)
解决 Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
leetcode刷题:二叉树26(二叉搜索树中的插入操作)
SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)
[learn micro services from 0] [02] move from single application to service
Multi row and multi column flex layout