当前位置:网站首页>[combinatorial mathematics] recursive equation (example of recursive equation 2 Hanoi Tower | example of recursive equation 3 insertion sequencing)
[combinatorial mathematics] recursive equation (example of recursive equation 2 Hanoi Tower | example of recursive equation 3 insertion sequencing)
2022-07-03 16:48:00 【Programmer community】
List of articles
- One 、 Examples of recursive equations 2 Hanoi
- Two 、 Examples of recursive equations 3 Insertion sort
One 、 Examples of recursive equations 2 Hanoi
Hanoi problem :
- The recurrence equation is :
T
(
n
)
=
2
T
(
n
−
1
)
+
1
T(n) =2 T(n-1) + 1
T(n)=2T(n−1)+1
- initial value :
T
(
1
)
=
1
T(1) = 1
T(1)=1
- Explain :
T
(
n
)
=
2
n
−
1
T(n) = 2^n - 1
T(n)=2n−1
The recurrence equation represents , take
n
n
n The number of times a plate moves
T
(
n
)
T(n)
T(n) , And
n
−
1
n-1
n−1 The number of times a plate moves
T
(
n
−
1
)
T(n-1)
T(n−1) The relationship between ;
Solution reference : 【 Combinatorial mathematics 】 Recurrence equation ( Examples of special solutions ) One 、 Special solution example 1 ( Hanoi )
Two 、 Examples of recursive equations 3 Insertion sort
W
(
n
)
W(n)
W(n) Indicates the number of times to insert a sort in the worst case ;
Ahead
n
−
1
n-1
n−1 The number has been arranged , In the worst case, the number of insertion sorts is
W
(
n
−
1
)
W(n-1)
W(n−1) Time ,
The first
n
n
n A number should be inserted here
n
−
1
n-1
n−1 Of the numbers , The worst case scenario is The number to be inserted should be the same as all the sorted numbers
n
−
1
n-1
n−1 Compare two numbers , The number of comparisons is
n
−
1
n-1
n−1 Time ,
So the recurrence equation can be written as :
W
(
n
)
=
W
(
n
−
1
)
+
n
−
1
W(n) = W(n-1) + n-1
W(n)=W(n−1)+n−1
Initial value of recurrence equation :
W
(
1
)
=
0
W(1) = 0
W(1)=0 , If there is only one number , No sorting , The number of comparisons is
0
0
0 ;
The final solution is :
W
(
n
)
=
O
(
n
2
)
W(n) = O(n^2)
W(n)=O(n2) , The exact value is
W
(
n
)
=
n
(
n
−
1
)
2
W(n) = \cfrac{n(n-1)}{2}
W(n)=2n(n−1)
边栏推荐
- (Supplement) double pointer topic
- Pointcut expression
- CC2530 common registers for port initialization
- Characteristic polynomial and constant coefficient homogeneous linear recurrence
- Kindeditor editor upload image ultra wide automatic compression -php code
- Meituan side: why does thread crash not cause JVM crash
- Client does not support authentication protocol requested by server; consider upgrading MySQL client
- What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material
- Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
- Interviewer: how does the JVM allocate and recycle off heap memory
猜你喜欢
[combinatorics] non descending path problem (number of non descending paths with constraints)
UCORE overview
word 退格键删除不了选中文本,只能按delete
8 cool visual charts to quickly write the visual analysis report that the boss likes to see
(Supplement) double pointer topic
Mysql database DDL and DML
斑馬識別成狗,AI犯錯的原因被斯坦福找到了
NLP四范式:范式一:非神经网络时代的完全监督学习(特征工程);范式二:基于神经网络的完全监督学习(架构工程);范式三:预训练,精调范式(目标工程);范式四:预训练,提示,预测范式(Prompt工程)
NLP four paradigms: paradigm 1: fully supervised learning in the era of non neural networks (Feature Engineering); Paradigm 2: fully supervised learning based on neural network (Architecture Engineeri
智慧之道(知行合一)
随机推荐
Overview of satellite navigation system
Necessary ability of data analysis
MySQL converts comma separated attribute field data from column to row
utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
Custom plug-in construction and use of QT plug-in
PHP secondary domain name session sharing scheme
于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日
8 tips for effective performance evaluation
Add color to the interface automation test framework and realize the enterprise wechat test report
线程池执行定时任务
Register in PHP_ Globals parameter settings
Svn usage specification
CC2530 common registers for watchdog
What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
UCORE overview
NLP four paradigms: paradigm 1: fully supervised learning in the era of non neural networks (Feature Engineering); Paradigm 2: fully supervised learning based on neural network (Architecture Engineeri
[combinatorics] polynomial theorem (polynomial coefficients | full arrangement of multiple sets | number of schemes corresponding to the ball sub model | polynomial coefficient correlation identity)
一台服务器最大并发 tcp 连接数多少?65535?
What is the maximum number of concurrent TCP connections for a server? 65535?
14 topics for performance interviews between superiors and subordinates (4)