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

Lecture 10 11

The document discusses the design and analysis of algorithms, focusing on recurrence equations and methods for solving them, such as iteration, recursion-tree, master, and substitution methods. It emphasizes the importance of asymptotic notation in algorithm analysis and provides examples of solving recurrence relations using the iteration method. Key concepts include base cases, boundary conditions, and the distinction between exact and asymptotic solutions.

Uploaded by

infinitrix777
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)
23 views

Lecture 10 11

The document discusses the design and analysis of algorithms, focusing on recurrence equations and methods for solving them, such as iteration, recursion-tree, master, and substitution methods. It emphasizes the importance of asymptotic notation in algorithm analysis and provides examples of solving recurrence relations using the iteration method. Key concepts include base cases, boundary conditions, and the distinction between exact and asymptotic solutions.

Uploaded by

infinitrix777
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/ 36

Design and Analysis of Algorithm

Recurrence Equation
(Solving Recurrence using
Iteration Methods)

Lecture – 10 and 11
Overview
• A recurrence is a function is defined in terms of
– one or more base cases, and
– itself, with smaller arguments.
Examples:

Linear Decay Division

Changing Variable Decision Tree


Overview
• Many technical issues:
• Floors and ceilings
[Floors and ceilings can easily be removed and don’t affect
the solution to the recurrence. They are better left to a
discrete math course.]
• Exact vs. asymptotic functions
• Boundary conditions
Overview

In algorithm analysis, the recurrence and it’s solution are


expressed by the help of asymptotic notation.
• Example: 𝑇 (𝑛) = 2𝑇 (𝑛/2) + 𝛩(𝑛), with solution
𝑇 (𝑛) = 𝛩(𝑛 lg 𝑛).
• The boundary conditions are usually expressed as
𝑇 (𝑛) = 𝛰(1) for sufficiently small n..
• But when there is a desire of an exact, rather than
an asymptotic, solution, the need is to deal with
boundary conditions.
• In practice, just use asymptotics most of the time,
and ignore boundary conditions.
Recursive Function
• Example
𝐴(𝑛)
{
𝐼𝑓(𝑛 > 1)
𝑅𝑒𝑡𝑢𝑟𝑛(𝐴 𝑛 − 1 )
}
The relation is called recurrence relation
The Recurrence relation of given function is written as follows.
𝑇(𝑛) = 𝑇(𝑛 − 1) + 1
Recursive Function
• To solve the Recurrence relation the following methods
are used:
1. Iteration method
2. Recursion-Tree method
3. Master Method
4. Substitution Method
Iteration Method( Example 1)
• In Iteration method the basic idea is to expand the recurrence
and express it as a summation of terms dependent only on ‘n’
(i.e. the number of input) and the initial conditions.
Example 1:
Solve the following recurrence relation by using Iteration method.

𝑇 𝑛−1 +1 𝑖𝑓 𝑛 > 1
𝑇 𝑛 =ቊ
1 𝑖𝑓 𝑛 = 1
Iteration Method ( Example 1)
It means 𝑇 𝑛 = 𝑇 𝑛 − 1 + 1 𝑖𝑓 𝑛 > 1
𝑎𝑛𝑑 𝑇 𝑛 = 1 𝑤ℎ𝑒𝑛 𝑛 = 1 −−−−−−−−−−−− −(1)
𝑃𝑢𝑡 𝑛 = 𝑛 − 1 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
𝑇 𝑛−1 =𝑇 𝑛−2 +1
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇(𝑛 − 1) 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
𝑇 𝑛 = 𝑇 𝑛 − 2 + 2 −−−−−−−−−−−−−−−− −(2)
Iteration Method ( Example 1)
𝑃𝑢𝑡 𝑛 = 𝑛 − 2 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
𝑇 𝑛−2 =𝑇 𝑛−3 +1
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇(𝑛 − 2) 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 2, 𝑤𝑒 𝑔𝑒𝑡
𝑇 𝑛 = 𝑇 𝑛 − 3 + 3 −−−−−−−−−−−−−−−− −(3)
……….
𝑇 𝑛 = 𝑇 𝑛 − 𝑘 + 𝑘 −−−−−−−−−−−−−−−− −(𝑘)
Iteration Method ( Example 1)
𝐿𝑒𝑡 𝑇 𝑛 − 𝑘 = 𝑇 1 = 1
(𝐴𝑠 𝑝𝑒𝑟 𝑡ℎ𝑒 𝑏𝑎𝑠𝑒 𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛 𝑜𝑓 𝑟𝑒𝑐𝑢𝑟𝑟𝑒𝑛𝑐𝑒)
𝑆𝑜 𝑛 − 𝑘 = 1
⇒𝑘 =𝑛−1
𝑁𝑜𝑤 𝑝𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑘 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 𝑘
𝑇 𝑛 =𝑇 𝑛− 𝑛−1 +𝑛−1
𝑇 𝑛 =𝑇 1 +𝑛−1
𝑇 𝑛 =1+𝑛−1 [∴ 𝑇 1 = 1]
𝑇 𝑛 =𝑛
∴ 𝑇 𝑛 =Θ 𝑛
Iteration Method ( Example 2)
Example 2:
Solve the following recurrence relation by using Iteration method.

𝑛
2𝑇 + 3𝑛2 𝑖𝑓 𝑛 > 1
𝑇 𝑛 =ቐ 2
11 𝑖𝑓 𝑛 = 1
Iteration Method ( Example 2)
𝑛
𝐼𝑡 𝑚𝑒𝑎𝑛𝑠 𝑇 𝑛 = 2𝑇 + 3𝑛2 𝑖𝑓 𝑛 > 1 𝑎𝑛𝑑 𝑇 𝑛 = 11 𝑤ℎ𝑒𝑛 𝑛 = 1 − −(1)
2
𝑛
𝑃𝑢𝑡 𝑛 = 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
2
𝑛 𝑛 𝑛 2
𝑇 = 2𝑇 +3
2 4 2
𝑛 𝑛 𝑛 2
𝑇 = 2𝑇 2 + 3
2 2 2
𝑛
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
2
𝑛 𝑛 2
𝑇 𝑛 = 2 2𝑇 2 + 3 + 3𝑛2
2 2
𝑛 𝑛2
𝑇 𝑛 = 2 𝑇 2 + 2.3 + 3𝑛2
2
2 4
2
𝑛 𝑛
𝑇 𝑛 = 22 𝑇 2 + 3 + 3𝑛2 −−−−−−−−−−−−− −(2)
2 2
Iteration Method ( Example 2)
𝑛
𝑃𝑢𝑡 𝑛 = 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
4
𝑛 𝑛 𝑛 2
𝑇 = 2𝑇 +3
4 8 4
𝑛 𝑛 𝑛 2
𝑇 = 2𝑇 3 + 3
4 2 4
𝑛
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 2, 𝑤𝑒 𝑔𝑒𝑡
4
2 2
𝑛 𝑛 𝑛
𝑇 𝑛 = 22 2𝑇 +3 + 3 +3𝑛2
8 16 2
2
𝑛 𝑛 2 𝑛2
𝑇 𝑛 = 2 2𝑇 3 + 3 + 3 +3𝑛2
2 4 2
2 2
𝑛 𝑛 𝑛
𝑇 𝑛 = 23 𝑇 3 + 4.3 + 3 +3𝑛2
2 16 2
Iteration Method ( Example 2)
2 2
𝑛 𝑛 𝑛
𝑇 𝑛 = 23 𝑇 3 + 3 2 + 3 +3𝑛2 −−−−−−−−−−−−− −(3)
2 2 2
…….
𝑛 𝑛2 𝑛2
𝑇 𝑛 = 2 𝑇 𝑖 + ⋯ + ⋯ + ⋯ + 3 2 + 3 +3𝑛2 −−−−−−−− −(𝑖 𝑡ℎ 𝑡𝑒𝑟𝑚)
𝑖
2 2 2
𝑛
𝑎𝑛𝑑 𝑡ℎ𝑒 𝑠𝑒𝑟𝑖𝑒𝑠 𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑡𝑒 𝑤ℎ𝑒𝑛 𝑖 = 1
2
⇒ 𝑛 = 2𝑖
𝑇𝑎𝑘𝑖𝑛𝑔 log 𝑏𝑜𝑡ℎ 𝑠𝑖𝑑𝑒
⇒ log 2 𝑛 = 𝑖 log 2 2
⇒ 𝑖 = log 2 𝑛 (𝑏𝑒𝑐𝑎𝑢𝑠𝑒 log 2 2 = 1)
Iteration Method ( Example 2)
𝐻𝑒𝑛𝑐𝑒 𝑤𝑒 𝑐𝑎𝑛 𝑤𝑟𝑖𝑡𝑒 𝑡ℎ𝑒 𝑖 𝑡ℎ 𝑡𝑒𝑟𝑚 𝑎𝑠 𝑓𝑜𝑙𝑙𝑜𝑤𝑠
2 2
𝑛 𝑛 𝑛
⇒ 𝑇 𝑛 = 3𝑛2 + 3 + 3 2 + ⋯ + ⋯ + ⋯ + 2𝑖 𝑇 𝑖
2 2 2
2 2
𝑛 𝑛
⇒ 𝑇 𝑛 = 3𝑛2 + 3 + 3 2 + ⋯ + ⋯ + ⋯ + 2log2 𝑛 𝑇 1
2 2
𝑛2 𝑛2
⇒ 𝑇 𝑛 = 3𝑛 + 3 + 3 2 + ⋯ + ⋯ + ⋯ + 2log2 𝑛 . 11
2
2 2
2 2
𝑛 𝑛
⇒ 𝑇 𝑛 = 3𝑛2 + 3 + 3 2 + ⋯ + ⋯ + ⋯ + 𝑛log2 2 . 11 [ 𝐴𝑠 log 2 2 = 1]
2 2
2
𝑛2 𝑛2
⇒ 𝑇 𝑛 = 3𝑛 + 3 + 3 2 + ⋯ + ⋯ + ⋯ + 𝑛. 11
2 2
2 2
𝑛 𝑛
⇒ 𝑇 𝑛 = 3𝑛2 + 3 + 3 2 + ⋯ + ⋯ + ⋯ + 11. 𝑛
2 2
1 1
⇒ 𝑇 𝑛 = 3𝑛2 1 + + 2 + ⋯ + ⋯ + ⋯ + 11. 𝑛
2 2
Iteration Method ( Example 2)
𝐴𝑠 𝑤𝑒 𝑘𝑛𝑜𝑤 𝑡ℎ𝑎𝑡 𝑆𝑢𝑚 𝑜𝑓 𝑖𝑛𝑓𝑖𝑛𝑖𝑡𝑒 𝐺𝑒𝑜𝑚𝑒𝑡𝑟𝑖𝑐 𝑠𝑒𝑟𝑖𝑒𝑠 𝑖𝑠

1 𝑎
= 𝑎 + 𝑎𝑟 + 𝑎𝑟 2 + ...+ 𝑎𝑟 (𝑛−1) = ෍ 𝑎𝑟 𝑖 =𝑎 =
1−𝑟 1−𝑟
𝑖=0

Hence,
1
⇒ 𝑇 𝑛 ≤ 3𝑛2 + 11 𝑛
1
1−
2
⇒ 𝑇 𝑛 ≤ 3𝑛2 . 2 + 11 𝑛
⇒ 𝑇 𝑛 ≤ 6𝑛2 + 11 𝑛
𝐻𝑒𝑛𝑐𝑒 𝑇 𝑛 = Ο(𝑛2 )
Iteration Method ( Example 3)
Example 3:
Solve the following recurrence relation by using Iteration method.
𝑛
8𝑇 + 𝑛2 𝑖𝑓 𝑛 > 1
𝑇 𝑛 =ቐ 2
1 𝑖𝑓 𝑛 = 1
Iteration Method ( Example 3)
𝑛
𝐼𝑡 𝑚𝑒𝑎𝑛𝑠 𝑇 𝑛 = 8𝑇 + 𝑛2 𝑖𝑓 𝑛 > 1 𝑎𝑛𝑑 𝑇 𝑛 = 1 𝑤ℎ𝑒𝑛 𝑛 = 1 −−− −(1)
2
𝑛
𝑃𝑢𝑡 𝑛 = 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
2
𝑛 𝑛 𝑛 2
𝑇 = 8𝑇 +
2 4 2
𝑛
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
2
𝑛 𝑛 2
𝑇 𝑛 = 8 8𝑇 + + 𝑛2
4 2
2
𝑛 𝑛2
𝑇 𝑛 =8 𝑇 + 8 + 𝑛2 −−−−−−−−−−−−− −(2)
4 4
𝑛
𝑃𝑢𝑡 𝑛 = 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
4
𝑛 𝑛 𝑛 2
𝑇 = 8𝑇 +
4 8 4
Iteration Method ( Example 3)
𝑛
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 2, 𝑤𝑒 𝑔𝑒𝑡
4
2
𝑛 𝑛 2 𝑛2
𝑇 𝑛 = 8 8𝑇 + + 8 + 𝑛2
8 4 4
𝑛 𝑛2 𝑛2
𝑇 𝑛 = 83 𝑇 8 + 82 42 + 84 + 𝑛2 −−−−−−−−−−−−− −(3)
……
𝑇 𝑛
𝑛 𝑛 2 𝑛 2 𝑛 2
= 8𝑘 𝑇 𝑘 + 8𝑘−1 𝑘−1 + ⋯ + ⋯ + ⋯ + 82 2 + 8 + 𝑛2 −−− −(𝑘 𝑡ℎ 𝑡𝑒𝑟𝑚)
2 4 4 4
𝑛 8𝑘−1 8𝑘−2 82 8
𝑇 𝑛 = 8𝑘 𝑇 𝑘 + 𝑛2 𝑘−1 + 𝑘−2 … + ⋯ + ⋯ + 2 + + 1
2 4 4 4 4
𝑛
𝑇 𝑛 = 8 𝑇 𝑘 + 𝑛2 2𝑘−1 + 2𝑘−2 … + ⋯ + ⋯ + 22 + 2 + 1 −−−− −(4)
𝑘
2
Iteration Method ( Example 3)
𝑛
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 2, 𝑤𝑒 𝑔𝑒𝑡
4
2
𝑛 𝑛 2 𝑛2
𝑇 𝑛 = 8 8𝑇 + + 8 + 𝑛2
8 4 4
𝑛 𝑛2 𝑛2
𝑇 𝑛 = 83 𝑇 8 + 82 42 + 84 + 𝑛2 −−−−−−−−−−−−− −(3)
……
𝑛 𝑛2 𝑛2 𝑛2
𝑇 𝑛 = 8𝑘 𝑇𝑘 +8𝑘−1
𝑘−1 + ⋯ + ⋯ + 8 2 + 8 + 𝑛2 −−− −(𝑘 𝑡ℎ 𝑡𝑒𝑟𝑚)
2
2 4 4 4
𝑛 8𝑘−1 8𝑘−2 82 8
𝑘
𝑇 𝑛 =8 𝑇 𝑘 + 𝑛 2 + …+ ⋯+ ⋯+ 2 + + 1
2 4𝑘−1 4𝑘−2 4 4
𝑛
𝑇 𝑛 = 8𝑘 𝑇 𝑘 + 𝑛2 2𝑘−1 + 2𝑘−2 … + ⋯ + ⋯ + 22 + 2 + 1 −−−− −(4)
2
Iteration Method ( Example 3)
𝑛
𝑇 𝑛 = 8 𝑇 𝑘 + 𝑛2 2𝑘−1 + 2𝑘−2 … + ⋯ + ⋯ + 22 + 2 + 1 −−− −(4)
𝑘
2
𝑛
𝑇 𝑛 = 8𝑘 𝑇 + 𝑛2 1 + 2 + 22 + ⋯ + ⋯ + 2𝑘−2 + 2𝑘−1 −−− − (5)
2𝑘
𝑛
𝑎𝑛𝑑 𝑡ℎ𝑒 𝑠𝑒𝑟𝑖𝑒𝑠 𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑡𝑒 𝑤ℎ𝑒𝑛 𝑘 = 1
2
⇒ 𝑛 = 2𝑘
𝑇𝑎𝑘𝑖𝑛𝑔 log 𝑏𝑜𝑡ℎ 𝑠𝑖𝑑𝑒
⇒ log 2 𝑛 = 𝑘 log 2 2
⇒ 𝑘 = log 2 𝑛 (𝑏𝑒𝑐𝑎𝑢𝑠𝑒 log 2 2 = 1)
𝑛
𝑁𝑜𝑤, 𝑎𝑝𝑝𝑙𝑦 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑘 = log 2 𝑛 𝑎𝑛𝑑 𝑘
= 1 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 5
2
Iteration Method ( Example 3)
𝑇 𝑛 = 8log2 𝑛 𝑇 1 + 𝑛2 1 + 2 + 22 + ⋯ + ⋯ + 2log2 𝑛−2 + 2log2 𝑛−1 −
(6)
= 𝑛log2 8 . 1 + 𝑛2 1 + 2 + 22 + ⋯ + ⋯ + 2log2 𝑛−2 + 2log2 𝑛−1
= 𝑛3 + 𝑛2 1 + 2 + 22 + ⋯ + ⋯ + 2log2 𝑛−2 + 2log2 𝑛−1

Is a G.P Series, but in this case no need of


evaluation. Because the highest order
polynomial is 𝑛3 . So no need to calculate 𝑛2 .

= 𝑛3
Hence the complexity is 𝑇(𝑛) = 𝑛3
Iteration Method ( Example 3)
𝑇 𝑛 = 8log2 𝑛 𝑇 1 + 𝑛2 1 + 2 + 22 + ⋯ + 2log2 𝑛−2 + 2log2 𝑛−1 − (6)
= 𝑛log2 8 . 1 + 𝑛2 1 + 2 + 22 + ⋯ + ⋯ + 2log2 𝑛−2 + 2log2 𝑛−1
= 𝑛3 + 𝑛2 1 + 2 + 22 + ⋯ + ⋯ + 2log2 𝑛−2 + 2log2 𝑛−1

Is a G.P Series, but in this case no need of


evaluation. Because the highest order
polynomial is 𝑛3 . So no need to calculate 𝑛2 .

= 𝑛3
Hence the complexity is 𝑇(𝑛) = 𝜪(𝑛3 )
𝑆𝑢𝑚 𝑜𝑓 𝑓𝑖𝑛𝑖𝑡𝑒 𝐺𝑒𝑜𝑚𝑒𝑡𝑟𝑖𝑐 𝑃𝑟𝑜𝑔𝑟𝑒𝑠𝑠𝑖𝑜𝑛 𝑠𝑒𝑟𝑖𝑒𝑠 𝑖𝑠
𝑛 𝑛+1 −1
𝑛 𝑟
= 𝑎 + 𝑎𝑟 + 𝑎𝑟 2 + . . . + 𝑎𝑟 = ෍ 𝑎𝑟 𝑖 = 𝑎
𝑟−1
𝑖=0
Iteration Method ( Example 4)
Example 4:
Solve the following recurrence relation by using Iteration method.
𝑛
7𝑇 + 𝑛2 𝑖𝑓 𝑛 > 1
𝑇 𝑛 =ቐ 2
1 𝑖𝑓 𝑛 = 1
(𝑖. 𝑒. 𝑆𝑡𝑟𝑎𝑠𝑠𝑖𝑜𝑛 𝐴𝑙𝑔𝑜𝑟𝑖𝑡ℎ𝑚)
Iteration Method ( Example 4)
𝑛
𝐼𝑡 𝑚𝑒𝑎𝑛𝑠 𝑇 𝑛 = 7𝑇 + 𝑛2 𝑖𝑓 𝑛 > 1 𝑎𝑛𝑑 𝑇 𝑛 = 1 𝑤ℎ𝑒𝑛 𝑛 = 1 −−− −(1)
2
𝑛
𝑃𝑢𝑡 𝑛 = 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
2
𝑛 𝑛 𝑛 2
𝑇 = 7𝑇 +
2 4 2
𝑛
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
2
𝑛 𝑛 2
𝑇 𝑛 = 7 7𝑇 + + 𝑛2
4 2
2
𝑛 𝑛2
𝑇 𝑛 =7 𝑇 + 7 + 𝑛2 −−−−−−−−−−−−− −(2)
4 4
𝑛
𝑃𝑢𝑡 𝑛 = 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
4
𝑛 𝑛 𝑛 2
𝑇 = 7𝑇 +
4 8 4
Iteration Method ( Example 4)
𝑛
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 2, 𝑤𝑒 𝑔𝑒𝑡
4
2
𝑛 𝑛 2 𝑛2
𝑇 𝑛 = 7 7𝑇 + + 7 + 𝑛2
8 4 4
3
𝑛 𝑛2 𝑛2
𝑇 𝑛 =7 𝑇 + 7 2 + 7 + 𝑛2 −−−−−−−−−−−−− −(3)
2
8 4 4
……
2 2 2
𝑛 𝑛 𝑛 𝑛
𝑇 𝑛 = 7𝑘 𝑇 𝑘 + 7𝑘−1 𝑘−1 + ⋯ + ⋯ + ⋯ + 72 2 + 7 + 𝑛2 −− −(𝑘 𝑡ℎ 𝑡𝑒𝑟𝑚)
2 4 4 4
𝑘−1 𝑘−2 2
𝑛 7 7 7 7
𝑇 𝑛 = 7𝑘 𝑇 𝑘 + 𝑛2 𝑘−1 + 𝑘−2 … + ⋯ + ⋯ + 2 + + 1
2 4 4 4 4
𝑘−1 𝑖
𝑛 7
𝑇 𝑛 = 7𝑘 𝑇 𝑘 + 𝑛2 ෍ −−−− −(4)
2 4
𝑖=0
Iteration Method ( Example 4)
𝑛
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 2, 𝑤𝑒 𝑔𝑒𝑡
4
2 2
𝑛 𝑛 𝑛
𝑇 𝑛 = 72 7𝑇 + + 7 + 𝑛2
8 4 4
𝑛 𝑛 2 𝑛 2
𝑇 𝑛 = 73 𝑇 + 72 2 + 7 + 𝑛2 −−−−−−−−−−−−− −(3)
8 4 4
……
𝑘
𝑛 𝑘−1
𝑛2 2
𝑛2 𝑛2 2 −− −(𝑘 𝑡ℎ 𝑡𝑒𝑟𝑚)
𝑇 𝑛 =7 𝑇 𝑘 +7 + ⋯ + ⋯ + ⋯ + 7 + 7 + 𝑛
2 4𝑘−1 42 4
𝑘
𝑛 2
7𝑘−1 7𝑘−2 72 7
𝑇 𝑛 =7 𝑇 𝑘 + 𝑛 + …+ ⋯+ ⋯+ 2 + + 1
2 4𝑘−1 4𝑘−2 4 4
𝑘−1 𝑖
𝑘
𝑛 2
7
𝑇 𝑛 =7 𝑇 𝑘 + 𝑛 ෍ −−−− −(4)
2 4
𝑖=0
Iteration Method ( Example 4)
𝑘−1 𝑖
𝑛 7
𝑇 𝑛 = 7𝑘 𝑇 𝑘 + 𝑛2 ෍ −−−− − 4
2 4
𝑖=0
𝑛
𝑎𝑛𝑑 𝑡ℎ𝑒 𝑠𝑒𝑟𝑖𝑒𝑠 𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑡𝑒 𝑤ℎ𝑒𝑛 𝑘 = 1
2
⇒ 𝑛 = 2𝑘
𝑇𝑎𝑘𝑖𝑛𝑔 log 𝑏𝑜𝑡ℎ 𝑠𝑖𝑑𝑒
⇒ log 2 𝑛 = 𝑘 log 2 2
⇒ 𝑘 = log 2 𝑛 (𝑏𝑒𝑐𝑎𝑢𝑠𝑒 log 2 2 = 1)
𝑛
𝑁𝑜𝑤, 𝑎𝑝𝑝𝑙𝑦 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑘 = log 2 𝑛 𝑎𝑛𝑑 = 1 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 4
2𝑘
Iteration Method ( Example 4)
log2 𝑛−1 𝑖
7
𝑇 𝑛 = 7log2 𝑛 𝑇 1 + 𝑛2 ෍ −−−− − 5
4
𝑖=0
log2 𝑛−1 𝑖
7
= 𝑛log2 7 . 1 + 𝑛2 ෍
4
𝑖=0
log2 𝑛−1 𝑖
7
= 𝑛log2 7 . 1 + 𝑛2 ෍
4
𝑖=0
log2 𝑛−1 𝑖
7
= 𝑛2.8 + 𝑛2 ෍
4
𝑖=0

Is a G.P Series, but in this case no need of


evaluation. Because the highest order
polynomial is 𝑛3 . So no need to calculate 𝑛2 .
Iteration Method ( Example 4)
log2 𝑛−1 𝑖
7
= 𝑛2.8 + 𝑛2 ෍
4
𝑖=0

Is a G.P Series, but in this case no need of


evaluation. Because the highest order
polynomial is 𝑛2.8 . So no need to calculate 𝑛2 .

= 𝑛2.8
Hence the complexity is 𝑇(𝑛) = 𝑛2.8
Iteration Method ( Example 4)
log2 𝑛−1 𝑖
7
= 𝑛2.8 + 𝑛2 ෍
4
𝑖=0

Is a G.P Series, but in this case no need of


evaluation. Because the highest order
polynomial is 𝑛2.8 . So no need to calculate 𝑛2 .

= 𝑛2.8
Hence the complexity is 𝑇(𝑛) = 𝜪(𝑛2.8 )
𝑆𝑢𝑚 𝑜𝑓 𝑓𝑖𝑛𝑖𝑡𝑒 𝐺𝑒𝑜𝑚𝑒𝑡𝑟𝑖𝑐 𝑃𝑟𝑜𝑔𝑟𝑒𝑠𝑠𝑖𝑜𝑛 𝑠𝑒𝑟𝑖𝑒𝑠 𝑖𝑠
𝑛
2 𝑛 𝑟 𝑛+1 −1
𝑖
= 𝑎 + 𝑎𝑟 + 𝑎𝑟 + . . . + 𝑎𝑟 = ෍ 𝑎𝑟 = 𝑎
𝑟−1
𝑖=0
Iteration Method ( Example 5)
Example 5:
Solve the following recurrence relation by using Iteration method.

𝑇 𝑛 − 1 + log 𝑛 𝑖𝑓 𝑛 > 1
𝑇 𝑛 =ቊ
1 𝑖𝑓 𝑛 = 1
Iteration Method ( Example 5)
𝐼𝑡 𝑚𝑒𝑎𝑛𝑠 𝑇 𝑛 = 𝑇 𝑛 − 1 + log 𝑛 𝑖𝑓 𝑛 > 1 𝑎𝑛𝑑 𝑇 𝑛 = 1 𝑤ℎ𝑒𝑛 𝑛 = 1 − −(1)
𝑃𝑢𝑡 𝑛 = 𝑛 − 1 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
𝑇 𝑛 − 1 = 𝑇 𝑛 − 2 + log(𝑛 − 1)
𝑃𝑢𝑡 𝑡ℎ𝑒 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑇 𝑛 − 1 𝑖𝑛 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 1, 𝑤𝑒 𝑔𝑒𝑡
𝑇 𝑛 = 𝑇 𝑛 − 2 + log(𝑛 − 1) + log 𝑛
= 𝑇 𝑛 − 3 + log(𝑛 − 2) + log(𝑛 − 1) + log 𝑛
= T n − 4 + log (𝑛 − 3) + log(𝑛 − 2) + log(𝑛 − 1) + log 𝑛
…………….
…………….
Hence the 𝑘𝑡ℎ order is :
T n = T n − k + log n − k − 1 + ⋯ + log(𝑛 − 2) + log(𝑛 − 1) + log 𝑛
T n = T n − k + log n − 𝑘 + 1 + ⋯ + log(𝑛 − 2) + log(𝑛 − 1) + log 𝑛
Iteration Method ( Example 5)
Hence the 𝑘𝑡ℎ order is :
T n = T n − k + log n − 𝑘 + 1 + ⋯ + log(𝑛 − 2) + log(𝑛 − 1) + log 𝑛

𝐴𝑠 𝑝𝑒𝑟 𝑡ℎ𝑒 𝑎𝑠𝑠𝑢𝑚𝑝𝑡𝑖𝑜𝑛 𝑛 − 𝑘 = 1


𝑆𝑜 𝑘 = 𝑛 − 1
The 𝑘 𝑡ℎ order can be written as:
T n = T 1 + log n − 𝑛 + 1 + 1 + ⋯ + log(𝑛 − 2) + log(𝑛 − 1) + log 𝑛
= 1 + log 2 + ⋯ + log(𝑛 − 2) + log(𝑛 − 1) + log 𝑛
= 1 + log 2 + log 3 + log(4) … + log(𝑛 − 2) + log(𝑛 − 1) + log 𝑛
= 1 + log 2. 3. 4. 5 … … … … . n
= 1 + log n!
𝑯𝒆𝒏𝒄𝒆 𝒕𝒉𝒆 𝒄𝒐𝒎𝒑𝒍𝒆𝒙𝒊𝒕𝒚 𝒊𝒔 ∶ 𝜪(𝒍𝒐𝒈𝒏!)
Iteration Method ( Practice)
7𝑛
𝑇 +𝑛 𝑖𝑓 𝑛 > 1
𝑄1. 𝑇 𝑛 = ൞ 10
1 𝑖𝑓 𝑛 = 1

𝑇 𝑛 − 1 + (𝑛 − 1) 𝑖𝑓 𝑛 > 1
𝑄2. 𝑇 𝑛 = ቊ
1 𝑖𝑓 𝑛 = 1

𝑇 𝑛 − 1 + 𝑛2 𝑖𝑓 𝑛 > 1
𝑄3. 𝑇 𝑛 = ቊ
1 𝑖𝑓 𝑛 = 1

You might also like