当前位置:网站首页>[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)
边栏推荐
- A survey of state of the art on visual slam
- [combinatorics] polynomial theorem (polynomial theorem | polynomial theorem proof | polynomial theorem inference 1 item number is the number of non negative integer solutions | polynomial theorem infe
- 13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties
- 为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”
- CC2530 common registers for port interrupts
- Learn from me about the enterprise flutter project: simplified framework demo reference
- Extraction of the same pointcut
- MySQL single table field duplicate data takes the latest SQL statement
- 【剑指 Offer】58 - II. 左旋转字符串
- Central South University | through exploration and understanding: find interpretable features with deep reinforcement learning
猜你喜欢
One article takes you to understand machine learning
A survey of state of the art on visual slam
Learn from me about the enterprise flutter project: simplified framework demo reference
Thread pool executes scheduled tasks
TCP congestion control details | 3 design space
斑馬識別成狗,AI犯錯的原因被斯坦福找到了
Network security web penetration technology
Mysql 将逗号隔开的属性字段数据由列转行
美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
What material is 12cr1movr? Chemical property analysis of pressure vessel steel plate 12cr1movr
随机推荐
Central South University | through exploration and understanding: find interpretable features with deep reinforcement learning
中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
Recommendation of good books on learning QT programming
Acwing game 58
面试之 top k问题
IDEA-配置插件
To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
Mysql 将逗号隔开的属性字段数据由列转行
CC2530 common registers for port interrupts
Explore Netease's large-scale automated testing solutions see here see here
LeetCode 1656. Design ordered flow
【剑指 Offer】58 - I. 翻转单词顺序
Basis of target detection (IOU)
(Supplement) double pointer topic
Caching mechanism of Hibernate / session level caching mechanism
How to set up SVN server on this machine
Interpretation of several important concepts of satellite antenna
Client does not support authentication protocol requested by server; consider upgrading MySQL client
【剑指 Offer 】57 - II. 和为s的连续正数序列
Golang anonymous function use