当前位置:网站首页>[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)
边栏推荐
- mysql用户管理
- CC2530 common registers
- RF analyze demo build step by step
- MySQL user management
- (Supplement) double pointer topic
- CC2530 common registers for port initialization
- Preventing/catching “IllegalArgumentException: parameter must be a descendant of this view” error
- Alibaba P8 painstakingly sorted it out. Summary of APP UI automated testing ideas. Check it out
- What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material
- Overview of satellite navigation system
猜你喜欢
Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day
Explore Netease's large-scale automated testing solutions see here see here
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
CC2530 common registers for crystal oscillator settings
What is the pledge pool and how to pledge?
2022.02.14_ Daily question leetcode five hundred and forty
IDEA-配置插件
arduino-esp32:LVGL项目(一)整体框架
13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties
随机推荐
數據分析必備的能力
CC2530 common registers
MySQL converts comma separated attribute field data from column to row
Mysql database DDL and DML
8个酷炫可视化图表,快速写出老板爱看的可视化分析报告
A survey of state of the art on visual slam
CC2530 common registers for port initialization
Develop team OKR in the way of "crowdfunding"
Simulink oscilloscope data is imported into Matlab and drawn
CC2530 common registers for watchdog
arduino-esp32:LVGL项目(一)整体框架
What is the pledge pool and how to pledge?
The way of wisdom (unity of knowledge and action)
[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
Top k questions of interview
LeetCode 1658. Minimum operand to reduce x to 0
2022爱分析· 国央企数字化厂商全景报告
Preventing/catching “IllegalArgumentException: parameter must be a descendant of this view” error
什么是质押池,如何进行质押呢?
【剑指 Offer】58 - I. 翻转单词顺序