当前位置:网站首页>[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)
边栏推荐
- Central South University | through exploration and understanding: find interpretable features with deep reinforcement learning
- What material is sa537cl2? Analysis of mechanical properties of American standard container plate
- Capacités nécessaires à l'analyse des données
- 数据分析必备的能力
- arduino-esp32:LVGL项目(一)整体框架
- Data driving of appium framework for mobile terminal automated testing
- What is the difference between 14Cr1MoR container plate and 14Cr1MoR (H)? Chemical composition and performance analysis of 14Cr1MoR
- 中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
- Pointcut expression
- Necessary ability of data analysis
猜你喜欢

Cocos Creator 2. X automatic packaging (build + compile)

(Supplement) double pointer topic

MySQL Basics

CC2530 common registers for port initialization

TCP congestion control details | 3 design space

What is the material of 13mnnimor? 13mnnimor steel plate for medium and low temperature pressure vessels

Unreal_ Datatable implements ID self increment and sets rowname

What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material

Add color to the interface automation test framework and realize the enterprise wechat test report

MySQL single table field duplicate data takes the latest SQL statement
随机推荐
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
QT serial port UI design and solution to display Chinese garbled code
远程办公之如何推进跨部门项目协作 | 社区征文
2022爱分析· 国央企数字化厂商全景报告
Explore Netease's large-scale automated testing solutions see here see here
A survey of state of the art on visual slam
MySQL Basics
Everyone in remote office works together to realize cooperative editing of materials and development of documents | community essay solicitation
arduino-esp32:LVGL项目(一)整体框架
Capacités nécessaires à l'analyse des données
utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
Caching mechanism of Hibernate / session level caching mechanism
MySQL converts comma separated attribute field data from column to row
[sword finger offer] 58 - I. flip the word order
关于学习Qt编程的好书精品推荐
【LeetCode】94. Middle order traversal of binary tree
QT串口ui设计和解决显示中文乱码
MySQL single table field duplicate data takes the latest SQL statement
Develop team OKR in the way of "crowdfunding"
深入理解 SQL 中的 Grouping Sets 语句