当前位置:网站首页>Time complexity and space complexity
Time complexity and space complexity
2022-06-13 06:13:00 【A strong foam】
Time complexity
First calculate the number of code executions T(n), Then the time complexity is estimated O(n).( The total number of lines of code executed × Time required for each code sentence , Here, the time required for each code sentence is considered the same )
Common time complexity :
- O(1)、O(logn)、O(n)、O(nlogn)、O(n^2)
How to calculate :
1)for、while loop
for(var i=0; i<n; i++){
for(var j=0; j<n; ){
j=j*2;
}
}
Time complexity :O(nlogn)
2) recursive
The number of recursions × The number of operations in each recursion
Spatial complexity
Amount of memory space occupied , Space complexity is used to express .
Common spatial complexity :
- O(1)、O(n)、O(n^2)
How to calculate :
- Variable : How many variables are there , Then how many memory spaces have been opened up , Generally for arrays 、 Stack or something , How many values are stored takes up how much memory space
- recursive
边栏推荐
- 2021-11-04 implementation of binary search
- 万能播放器 PotPlayer 的下载与安装,直播流 m3u8 导入
- After clicking the uniapp e-commerce H5 embedded applet, the page prompts "the page iframe does not support referencing non business domain names"
- Leetcode minimum absolute difference of binary search tree simple
- 微信小程序:全局状态变量的使用
- Printf function
- After MySQL is installed, enter the "net start MySQL" command, and an error is reported that "net" is neither an internal or external command nor a runnable program
- Minimum spanning tree (prim+kruskal) learning notes (template +oj topic)
- Echart折线图:当多条折线图的name一样时也显示不同的颜色
- Leetcode- distribute cookies - simple
猜你喜欢

php 分布式事务 原理详解

Sqlplus connection failure

Echart柱状图:x轴显示value,y轴显示类别

自定义View —— 可伸展的CollapsExpendView

Hbuilderx: installation of hbuilderx and its common plug-ins
![[turn] explain awk (2)_ Combining formatted output with built-in variables to realize requirements](/img/65/a214d137e230b1a1190feb03660f2c.jpg)
[turn] explain awk (2)_ Combining formatted output with built-in variables to realize requirements
![[DP 01 backpack]](/img/be/1e5295684ead652eebfb72ab0be47a.jpg)
[DP 01 backpack]

AI realizes "Resurrection" of relatives | old photo repair | old photo coloring, recommended by free app

You should consider upgrading via

Echart histogram: echart implements stacked histogram
随机推荐
Leetcode- key formatting - simple
Wechat applet: basic review
Recommend a capacity expansion tool to completely solve the problem of insufficient disk space in Disk C and other disks
Self summarizing
USB debugging assistant (20191028)
Alibaba cloud OSS file download cannot be resumed at a breakpoint
2021-11-04 implementation of binary search
Software testing - Summary of common interface problems
Custom view - extensible collapsexpendview
Using async await in applets
【MySQL】基础知识小复习
Leetcode- string addition - simple
Regular verification of mobile phone number, landline email ID card
MySQL stored procedure
The boys x pubgmobile linkage is coming! Check out the latest game posters
Swift--function
Leetcode- minimum number of operations to make array elements equal - simple
安全基线检查脚本—— 筑梦之路
Leetcode perfect number simple
Wechat applet (function transfer parameters, transfer multiple parameters, page Jump)