0% found this document useful (0 votes)
313 views

Solution To Recurrence Relation

The document summarizes the process of solving the recurrence relation T(n) = 2T(n/2) + n - 1 using repeated substitution. It shows that after k steps of substitution, the relation can be expressed as T(n) = n log n - n + 1. Since the leading term is n log n, the solution of the given recurrence relation is O(n log n).

Uploaded by

Mudit Nawani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
313 views

Solution To Recurrence Relation

The document summarizes the process of solving the recurrence relation T(n) = 2T(n/2) + n - 1 using repeated substitution. It shows that after k steps of substitution, the relation can be expressed as T(n) = n log n - n + 1. Since the leading term is n log n, the solution of the given recurrence relation is O(n log n).

Uploaded by

Mudit Nawani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Solving a Recurrence Relation using Repeated Substitution

𝒏𝒏
Solution of recurrence relation: 𝑻𝑻(𝒏𝒏) = 𝟐𝟐𝑻𝑻 �𝟐𝟐� + 𝒏𝒏 − 𝟏𝟏, given T(1) = 1
[Note that this is the recurrence relation that we get for merge sort]

𝑛𝑛
𝑇𝑇(𝑛𝑛) = 2𝑇𝑇 � � + 𝑛𝑛 − 1 ----- (1)
2
𝑛𝑛 𝑛𝑛
We can write 𝑇𝑇 � � as follows by replacing 𝑛𝑛 by in Equation (1) above
2 2

𝑛𝑛 𝑛𝑛 𝑛𝑛
𝑇𝑇 � � = 2𝑇𝑇 � 2 � + − 1
2 2 2
𝑛𝑛
Putting the value of 𝑇𝑇 � � in (1) we get
2
𝑛𝑛 𝑛𝑛
𝑇𝑇(𝑛𝑛) = 2 �2𝑇𝑇 � 2 � + − 1� + 𝑛𝑛 − 1
2 2
2 𝑛𝑛
= �2 𝑇𝑇 � 2 � + 𝑛𝑛 − 2� + 𝑛𝑛 − 1
2
2 𝑛𝑛
= 2 𝑇𝑇 � 2 � + (𝑛𝑛 + 𝑛𝑛) − (1 + 2) ----- (2)
2
𝑛𝑛 𝑛𝑛
Now, again using (1) we can write 𝑇𝑇 � 2 � as follows by replacing 𝑛𝑛 by
2 22
𝑛𝑛 𝑛𝑛 𝑛𝑛
𝑇𝑇 � 2 � = 2𝑇𝑇 � 3 � + 2 − 1
2 2 2
𝑛𝑛
Putting the value of 𝑇𝑇 � 2 � in (2) we get following
2

𝑛𝑛 𝑛𝑛
𝑇𝑇(𝑛𝑛) = 22 �2𝑇𝑇 � 3 � + − 1� + 𝑛𝑛 + 𝑛𝑛 − (1 + 2)
2 22
𝑛𝑛
= 23 𝑇𝑇 � 3 � + 𝑛𝑛 − 22 + 𝑛𝑛 + 𝑛𝑛 − (1 + 2)
2
𝑛𝑛
= 23 𝑇𝑇 � 3 � +
(𝑛𝑛 + 𝑛𝑛 + 𝑛𝑛) − (1 + 2 + 22 )
2
…. …..
………
Continue like this for k steps after which T(n) can be expressed as follows
𝑛𝑛
𝑇𝑇(𝑛𝑛) = 2𝑘𝑘 𝑇𝑇 � 𝑘𝑘 � + �����������
(𝑛𝑛 + 𝑛𝑛 + ⋯ . +𝑛𝑛) − (1 + 2 + 22 +. . +2𝑘𝑘 )
2
𝑘𝑘 times
𝑛𝑛
Let 2𝑘𝑘 = 𝑛𝑛, then =1
2𝑘𝑘
𝑛𝑛
So 𝑇𝑇(𝑛𝑛) = 2𝑘𝑘 𝑇𝑇 � 𝑘𝑘 � + �����������
(𝑛𝑛 + 𝑛𝑛 + ⋯ . +𝑛𝑛) − (1 + 2 + 22 +. . +2𝑘𝑘 )
2
𝑘𝑘 times
= 𝑛𝑛𝑛𝑛(1) + (𝑛𝑛 + 𝑛𝑛 + ⋯ . +𝑛𝑛) − (1 + 2 + 22 +. . +2𝑘𝑘 )
�����������
𝑘𝑘 times
1×�2𝑘𝑘+1 −1� 𝑎𝑎�𝑟𝑟 𝑛𝑛 +1 −1�
= 𝑛𝑛 × 1 + 𝑛𝑛𝑛𝑛 − 2−1
[Since sum of geometric progression: 𝑎𝑎 + 𝑎𝑎𝑎𝑎 + 𝑎𝑎𝑟𝑟 2 +. . +𝑎𝑎𝑟𝑟 𝑛𝑛 = 𝑟𝑟−1
]
𝑘𝑘+1
= 𝑛𝑛 + 𝑛𝑛𝑛𝑛 − �2 − 1�
= 𝑛𝑛 + 𝑛𝑛𝑛𝑛 − �2 × 2𝑘𝑘 − 1�
= 𝑛𝑛 + 𝑛𝑛𝑛𝑛 − 2𝑛𝑛 + 1
= 𝑛𝑛𝑛𝑛 − 𝑛𝑛 + 1 … (3)

Since 2𝑘𝑘 = 𝑛𝑛, we get k = log n


So from Equation (3) 𝑇𝑇(𝑛𝑛) = 𝑛𝑛 log 𝑛𝑛 − 𝑛𝑛 + 1
= 𝑂𝑂(𝑛𝑛 log 𝑛𝑛)
Hence solution of given recurrence relation is 𝑶𝑶(𝒏𝒏 𝐥𝐥𝐥𝐥𝐥𝐥 𝒏𝒏)
Exercise problems:

Solve following recurrence relations using repeated substitution. [Assume n = 2k]

1. T(n) = T(n-1) + c , given T(1) = 1 and c is a constant [Ans: O(n)]

2. T(n) = T(n/2) + c , given T(1) = 1 [Ans: O(log n)]

3. T(n)=T(n−1)+n, given T(1)=0 [Ans: O(n2)]

4. T(n) = 2 T(n-1) + c , given T(1) = 1 and c is a constant [Ans: O(2n)]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy