当前位置:网站首页>[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)
边栏推荐
- 远程办公之如何推进跨部门项目协作 | 社区征文
- Custom plug-in construction and use of QT plug-in
- Simulink oscilloscope data is imported into Matlab and drawn
- Kotlin学习快速入门(7)——扩展的妙用
- CC2530 common registers for timer 1
- QT serial port UI design and solution to display Chinese garbled code
- 一台服务器最大并发 tcp 连接数多少?65535?
- [Jianzhi offer] 64 Find 1+2+... +n
- Register in PHP_ Globals parameter settings
- 关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
猜你喜欢

爱可可AI前沿推介(7.3)
![[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](/img/9d/6118b699c0d90810638f9b08d4f80a.jpg)
[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

Zebras are recognized as dogs, and Stanford found the reason why AI made mistakes

Explore Netease's large-scale automated testing solutions see here see here

8个酷炫可视化图表,快速写出老板爱看的可视化分析报告

8 cool visual charts to quickly write the visual analysis report that the boss likes to see

Record windows10 installation tensorflow-gpu2.4.0

2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises

CC2530 common registers for port initialization

Processing strategy of message queue message loss and repeated message sending
随机推荐
Summary of three methods of PHP looping through arrays list (), each (), and while
Golang anonymous function use
Custom plug-in construction and use of QT plug-in
Extraction of the same pointcut
Caching mechanism of Hibernate / session level caching mechanism
RF Analyze Demo搭建 Step by Step
Mysql 单表字段重复数据取最新一条sql语句
关于视觉SLAM的最先进技术的调查-A survey of state-of-the-art on visual SLAM
IDEA-配置插件
Central South University | through exploration and understanding: find interpretable features with deep reinforcement learning
How to delete a specific line from a text file using the SED command?
[Jianzhi offer] 64 Find 1+2+... +n
13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties
Meituan side: why does thread crash not cause JVM crash
UCORE overview
Pointcut expression
CC2530 common registers for serial communication
function overloading
LeetCode 1656. Design ordered flow
"The NTP socket is in use, exiting" appears when ntpdate synchronizes the time