当前位置:网站首页>[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)
边栏推荐
- 2022.02.14_ Daily question leetcode five hundred and forty
- CC2530 common registers for watchdog
- CC2530 common registers for port initialization
- CC2530 common registers for serial communication
- What material is sa537cl1? Sa537cl1 corresponds to the national standard material
- CC2530 common registers
- Unreal_ Datatable implements ID self increment and sets rowname
- 一台服务器最大并发 tcp 连接数多少?65535?
- Add color to the interface automation test framework and realize the enterprise wechat test report
- Mysql 将逗号隔开的属性字段数据由列转行
猜你喜欢

什么是质押池,如何进行质押呢?

(补)双指针专题

MySQL Basics

13mnnimo5-4 German standard steel plate 13MnNiMo54 boiler steel 13MnNiMo54 chemical properties

网络安全web渗透技术

MySQL converts comma separated attribute field data from column to row

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

Daily code 300 lines learning notes day 10

Mysql 将逗号隔开的属性字段数据由列转行

爱可可AI前沿推介(7.3)
随机推荐
【剑指 Offer】58 - I. 翻转单词顺序
Custom plug-in construction and use of QT plug-in
Golang anonymous function use
utfwry. Dat PHP, about ThinkPHP's method of IP location using utfwry address Library
关于学习Qt编程的好书精品推荐
消息队列消息丢失和消息重复发送的处理策略
RF analyze demo build step by step
How programming apes grow rapidly
为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”
Web crawler knowledge day03
面试之 top k问题
How to promote cross department project collaboration | community essay solicitation
Explore Netease's large-scale automated testing solutions see here see here
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
CC2530 common registers for ADC single channel conversion
mysql用户管理
Characteristic polynomial and constant coefficient homogeneous linear recurrence
What material is 13crmo4-5 equivalent to in China? 13crmo4-5 chemical composition 13crmo4-5 mechanical properties
CC2530 common registers for serial communication
PHP CI (CodeIgniter) log level setting