当前位置:网站首页>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)
边栏推荐
- 聊聊Redis缓存4种集群方案、及优缺点对比
- [statistical learning methods] learning notes - improvement methods
- 利用棧來實現二進制轉化為十進制
- Preorder, inorder and postorder traversal of binary tree
- SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
- opencv的四个函数
- Tutorial on principles and applications of database system (007) -- related concepts of database
- Cryptography series: detailed explanation of online certificate status protocol OCSP
- 浅谈估值模型 (二): PE指标II——PE Band
- SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
猜你喜欢
对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景
Day-15 common APIs and exception mechanisms
Configure an encrypted web server
基于NeRF的三维内容生成
[爬虫]使用selenium时,躲避脚本检测
Solve server returns invalid timezone Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
Solutions to cross domain problems
idm服务器响应显示您没有权限下载解决教程
SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
Polymorphism, final, etc
随机推荐
Decrypt gd32 MCU product family, how to choose the development board?
Using stack to convert binary to decimal
Day-18 hash table, generic
leetcode刷题:二叉树27(删除二叉搜索树中的节点)
对话PPIO联合创始人王闻宇:整合边缘算力资源,开拓更多音视频服务场景
Inverted index of ES underlying principle
gcc 编译报错
【从 0 开始学微服务】【00】课程概述
【深度学习】图像多标签分类任务,百度PaddleClas
leetcode刷题:二叉树26(二叉搜索树中的插入操作)
NGUI-UILabel
Static routing assignment of network reachable and telent connections
BGP third experiment report
SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
静态Vxlan 配置
The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作
leetcode刷题:二叉树19(合并二叉树)
Day-14 common APIs
[learn micro services from 0] [02] move from single application to service