当前位置:网站首页>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)
边栏推荐
- Typescript interface inheritance
- SQL Lab (41~45) (continuous update later)
- Master公式。(用于计算递归的时间复杂度。)
- About web content security policy directive some test cases specified through meta elements
- IPv6 experiment
- Attack and defense world ----- summary of web knowledge points
- 普乐蛙小型5d电影设备|5d电影动感电影体验馆|VR景区影院设备
- OSPF exercise Report
- [statistical learning method] learning notes - support vector machine (Part 2)
- 【从 0 开始学微服务】【03】初探微服务架构
猜你喜欢

Charles: four ways to modify the input parameters or return results of the interface

In the small skin panel, use CMD to enter the MySQL command, including the MySQL error unknown variable 'secure_ file_ Priv 'solution (super detailed)
![[statistical learning method] learning notes - logistic regression and maximum entropy model](/img/f7/857d053cc2cee81c24919aafab3c6e.png)
[statistical learning method] learning notes - logistic regression and maximum entropy model
![[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

Day-18 hash table, generic

Experiment with a web server that configures its own content

Tutorial on the principle and application of database system (011) -- relational database

Decrypt gd32 MCU product family, how to choose the development board?

Learning and using vscode

On valuation model (II): PE index II - PE band
随机推荐
聊聊Redis缓存4种集群方案、及优缺点对比
ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
"Series after reading" my God! It's so simple to understand throttling and anti shake~
File upload vulnerability - upload labs (1~2)
【统计学习方法】学习笔记——逻辑斯谛回归和最大熵模型
Typescript interface inheritance
leetcode刷题:二叉树22(二叉搜索树的最小绝对差)
Aike AI frontier promotion (7.7)
Object. Simple implementation of assign()
Day-18 hash table, generic
Solve server returns invalid timezone Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
Customize the web service configuration file
Error in compiling libssl
对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景
[statistical learning method] learning notes - support vector machine (Part 2)
【统计学习方法】学习笔记——提升方法
Will the filing free server affect the ranking and weight of the website?
Vxlan static centralized gateway
[learn micro services from 0] [02] move from single application to service
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘