Professional Documents
Culture Documents
Part 2 - Time Complexity of Recursive Algorithms
Part 2 - Time Complexity of Recursive Algorithms
( ) +cn 𝑛
T(n)¿ 𝟑 𝑇 ( )+ c n
2
( )cn +cn 2 𝑛
¿𝟑𝑇 ( )+ ( )
( )] 23
( )cn+cn
( ) ( )cn+cn
¿𝟑𝟑𝑇 ( ) ( )cn+cn
𝑛
23
3
Time Complexity of Recursive Algorithms
¿𝟑𝟑𝑇 ( ) ( )cn+cn
𝑛
23
3
-------------------------------
-------------------------------
¿𝟑𝒌𝑇 ( )
𝑛
2𝑘
k
Time Complexity of Recursive Algorithms
¿𝟑𝟑𝑇 ( ) ( )cn+cn
𝑛
23
3
-------------------------------
𝟑
------------------------------- ( )𝟎
𝟐
¿𝟑𝒌𝑇 (2𝑘)
𝑛 ( )+ k
¿𝟑𝒌𝑇 (
2𝑘)
𝑛
+ c n( )+]
Time Complexity of Recursive Algorithms
¿𝟑𝒌𝑇 (
2𝑘)
𝑛
+ c n ]
𝟏((
𝟑
)𝒌 − 𝟏) 𝟑𝒌 ¿
. −𝟏 ¿
¿𝟑𝒌𝑇 ( )
𝟐
𝑛
2𝑘
+ c . n
(
𝟑
)− 𝟏
¿ 𝟑 𝒌 𝑇 ( 𝑛
2𝑘 )
+ c n𝟐𝒌 𝟏
𝟐 𝟐
¿
¿𝟑𝒌𝑇
𝑛
2𝑘 ( ) .
+ 2 c n𝟑𝒌−𝟐𝒌¿
𝟐𝒌
Time Complexity of Recursive Algorithms
. + 2 c 𝟑𝒌−𝟐 c 𝒏 =c
𝑛=2 𝑘
(+2) −𝟐 c 𝒏 𝑙𝑜𝑔 𝑛=𝑙𝑜𝑔 2𝑘
¿ 𝟑 𝒍𝒐𝒈 𝒏 (c + 2 c−𝟐 ) c𝒏 𝑙𝑜𝑔 𝑛=k 𝑙𝑜𝑔 2 2
¿ 𝒏 𝒍𝒐𝒈 𝟑 (c + 2 c−𝟐
) c𝒏 a= k
Time Complexity of Recursive Algorithms
¿ 𝒏 𝒍𝒐𝒈 𝟑 ( c + 2 c−𝟐
) c𝒏
¿ 𝒏𝟏 . 𝟓𝟖 (c + 2 c−𝟐
) c𝒏
¿ ( c + 2 c )𝒏 𝟏. 𝟓𝟖
− 𝟐 c𝒏 O (n1.58)
Practice Question
T(n) = 4 T( n / 5 ) + n for n > 1
T(n) = 1 for n = 1
Solution
1-10