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

Unit 1

This document provides information about an algorithms course including: - The course code, name, category, and prerequisite courses - A tentative schedule for internal evaluations including 3 assignments and a surprise test - An overview of the teaching and learning process including lectures, assignments, a mini-project, and certifications - 6 expected learning outcomes covering algorithm design techniques - A list of 4 recommended books for learning resources - Introductions to algorithm design, what defines a problem, and the four desired properties of algorithms

Uploaded by

Akila
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Unit 1

This document provides information about an algorithms course including: - The course code, name, category, and prerequisite courses - A tentative schedule for internal evaluations including 3 assignments and a surprise test - An overview of the teaching and learning process including lectures, assignments, a mini-project, and certifications - 6 expected learning outcomes covering algorithm design techniques - A list of 4 recommended books for learning resources - Introductions to algorithm design, what defines a problem, and the four desired properties of algorithms

Uploaded by

Akila
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 144

Course Code :18CSC204J

Course Name : DESIGN AND ANALYSIS OF ALGORITHMS

Course Category : C Professional Core


Pre-requisite Courses : 18CSC201J

09/02/2023
Internal evaluation Planning(TENTATIVE)

• Assignment #1 : submission by  31st JANUARY   2023


• Assignment #2:  SUBMISSION DEADLINE 22ND  FEBRUARY
• Assignment # 3: programming assignment by 30th MARCH
• Surprise test: ANYTIME

09/02/2023
TEACHING LEARNING PROCESS

⚫Three lectures/week( 1 hr duration each)


⚫ONLINE assignments
⚫surprise test
⚫MINI-PROJECT
⚫ONLINE COURSE CERTIFICATIONS
⚫Three Cts + End Sem Exam

*
Course Learning Outcomes
At the end of this course, learners will be able to :

ClO1: apply efficient algorithms to reduce space and time complexity of both recurrent and
non- recurrent relations.

ClO2: solve problems using divide and conquer approaches

ClO3: apply greedy and dynamic programming type techniques to solve polynomial problems.

ClO4: create exponential problems using backtracking and branch and bound approaches.

ClO5: interpret various approximation algorithms and interpret solutions to evaluate p type, np
type, npc, np hard problems.

Clo6: create greedy algorithms that are efficient in space and time complexities by using divide
and conquer, greedy, backtracking techniques
09/02/2023
Recommended Books
Learning resources

1: Thomas h. cormen, Charles e leirson, Ronald l revest, Clifford stein,


introduction to algorithms, 3rd edition, the mit press Cambridge, 2014.

2: mark allen Weiss, data structures and algorithm analysis in c, 2nd


edition, pearson education, 2006

3: ellis horowitz, sartaj sahni, sanguthevar, rajasekaran, fundamentals of


algorithms, galgotia publications, 2010

4: S. Sridhar, design and analysis of algorithms, oxford university press,


2015.

09/02/2023
Introduction- Algorithm Design

09/02/2023
What is an Algorithm?

Algorithms are the ideas behind computer programs.

An algorithm is the thing that stays the same whether the


program is in C++ running on a Cray in New York or is in
BASIC running on a Macintosh in Chennai!

To be interesting, an algorithm has to solve a general,


specified problem.

09/02/2023
What is a problem?
Definition
• A mapping/relation between a set of input instances (domain) and an
output set (range)

Problem Specification
• Specify what a typical input instance is
• Specify what the output should be in terms of the input instance

Example: Sorting
• Input: A sequence of N numbers a1…an
• Output: the permutation (reordering) of the input sequence such that
a1  a2  …  an .
09/02/2023
Types of Problems
Search: Find X in the input satisfying property Y

Structuring: Transform input X to satisfy property Y

Construction: Build X satisfying Y

Optimization: Find the best X satisfying property Y

Decision: Does X satisfy Y?

Adaptive: Maintain property Y over time.

09/02/2023
FUNDAMENTALS OF ALGORITHM

09/02/2023
FOUR DESIRED PROPERTIES OF ALGORITHMS

Definiteness

• Each instruction must be clear and unambiguous

Finiteness

• The algorithm must terminate

Correctness

• It must provide correct output when presented with legal input

Efficiency

• Each instruction must be very basic so that it can be easily carried out.

09/02/2023
Example: Odd Number

Input: A number n

Output: Yes if n is odd, no if n is even

Which of the following algorithms solves Odd Number best?


• Count up to that number from one and alternate naming each number as odd or even.
• Factor the number and see if there are any twos in the factorization.
• Keep a lookup table of all numbers from 0 to the maximum integer.
• Look at the last bit (or digit) of the number.

09/02/2023
HOW TO DEVISE ALGORITHMS

Something of an art form

Cannot be fully automated

We will describe some general techniques and


try to illustrate when each is appropriate

09/02/2023
EXPRESSING ALGORITHMS

Implementations

Pseudo-code

English

My main concern here is not the specific language used but the
clarity of your expression

09/02/2023
CORRECTNESS OF ALGORITHM

09/02/2023
VERIFYING ALGORITHM CORRECTNESS

• Algorithm Validation
• Process of checking the correctness of algorithms.
• Performed by providing all valid inputs to the algorithm and checking its
outputs with expected results.
• Gives a guarantee that the given algorithm always gives correct answers.

• The ability of an algorithm to give correct outputs for valid inputs


is called algorithm correctness.
• Program correctness checks whether the algorithm conforms to the given
specifications.

09/02/2023
TIME COMPLEXITY ANALYSIS

09/02/2023
ANALYZING ALGORITHMS

The “process” of determining how much resources (time,


space) are used by a given algorithm

We want to be able to make quantitative assessments about


the value (goodness) of one algorithm compared to another

We want to do this WITHOUT implementing and running an


executable version of an algorithm
• Question: How can we study the time complexity of an algorithm if we
don’t run it or even choose a specific machine to measure it on?

09/02/2023
ANALYZING ALGORITHMS CONTD…

The challenge is to develop generic complexity analysis theory


for estimating the time and space required by an algorithm

The analysis should be independent of a particular machine or


software environment.

It is required for the following reasons:


• To estimate the efficiency of any given algorithm by predicting the
algorithm behavior.
• To provide a framework for comparing algorithms or solutions for the given
problem.

09/02/2023
Measurement for
algorithm analysis

Subjective Objective
Measure Measures

Ease of Understandabi Dynamic Static


Algorithm
implementatio lity of measure Objective
Style
n Algorithms Objectives Measures

Program Program
Time Space
Length Volume

09/02/2023
PERFORMANCE ANALYSIS

Time Complexity

• 
• 
Space Complexity
• The amount of memory an algorithm needs to run to completion.

09/02/2023
Algorithm Analysis Overview
Computational
Models for Asymptotic analysis
Algorithm Analysis

RAM model of Concept of input Three complexity Asymptotic


computation size measures notation

Unit Cost Model Best-case Big-oh

Logarithm Cost
Average-case Big- omega
Model

Worst-case Big- theta


09/02/2023
The RAM Model

RAM model represents a “generic” implementation of the algorithm

Each “simple” operation (+, -, =, if, call) takes exactly 1 step.

Loops and subroutine calls are not simple operations, but depend upon the
size of the data and the contents of a subroutine. We do not want “sort” to
be a single step operation.

Each memory access takes exactly 1 step.

09/02/2023
Input Size
The input size is defined formally as the number of bits used to
represent the input data.

In general, larger input instances require more resources to process


correctly

We standardize by defining a notion of size for an input instance

Examples
• What is the size of a sorting input instance?
• What is the size of an “Odd number” input instance?
09/02/2023
Methods of runtime measurement

Algorithm
Analysis

Steps Operations Asymptotic Recurrence Amortized


Count Count Analysis Relations Analysis

09/02/2023
Measuring Complexity

The running time of an algorithm is the function


defined by the number of steps required to solve
input instances of size n
• F(1) = 3
• F(2) = 5
• F(3) = 7
• …
• F(n) = 2n+1

09/02/2023
Specific ways of measuring step counts per execution:

Declarative statements with no


initializations have a statement
count of 0. In case initializations
are made, step count is 1.

Comments, brackets such as


begin/ end/ endif/ end while/
end for, all have a step count of
0.

Expressions have a step


count of 1.

Assignment statements, function


invocation, return statements, and other
statements such as break/continue/go all
have a step count of 1.

09/02/2023
Case Study

• Algorithm simple(A, B, C)
Begin

A=B+1

C= A+2

D=A+B

End

Find the step count of this algorithm segment.


09/02/2023
Case Study Contd…
Step Number Algorithm Steps per Frequency Total
Segment execution
1 Algorithm 0 - -
simple(A, B, C)

2 Begin 0 - -
3 A=B+1 1 1 1
4 C= A+2 1 1 1
5 D=A+B 1 1 1
6 End 0 - -
Total 3

09/02/2023
Case Study

• Algorithm sum()
Begin

sum=0.0

for i=1 to n do

sum=sum+1

End for

Return sum

End

Find the step count of this algorithm segment.

09/02/2023
Case Study Contd…
Step Number Algorithm Steps per Frequency Total
Segment execution
1 Algorithm 0 - -
sum()
2 Begin 0 - -
3 Sum=0.0 1 1 1
4 for i=1 to n do 1 n+1 n+1
5 Sum=sum+1 1 n n
6 End for 0 - -
7 Return sum 1 1 1
8 End 0 0 0
Total 2n+3

09/02/2023
Case Study: Insertion Sort

Algorithm InsertionSort()
Begin
for i = 2 to n
key = A[i]
j=i-1
while j > 0 AND A[j] > key
A[j+1] = A[j]
j = j -1
A[j+1] = key
End for
End
Count the number of times each line will be executed:
09/02/2023
Case Study: Insertion Sort Contd…
Step Number Algorithm Segment Steps per Frequency Total
execution
1 Algorithm 0 - -
InsertionSort()
2 Begin 0 - -
3 for i = 2 to n 1 (n-1) + 1 n

4 key = A[i] 1 n-1 n-1


5 j=i-1 1 n-1 n-1
6 while j > 0 AND A[j] > 1 variable variable
key
7 A[j+1] = A[j] 1 variable variable
8 j = j -1 1 variable variable
9 A[j+1] = key 1 n-1 n-1
10 End for 0 - -
11 End 0 - -
09/02/2023 Total 4n-2
Advantages and Disadvantages of step
count

Evaluation of time complexity using step count is easy

Major Disadvantage is that it does not at all depend on the operands

• e.g. a=a+10 and a=a+1000000 have the same step count

09/02/2023
Case Study: Homework

Algorithm Sum()
Begin
Sum=0.0
for i = 1 to n do
val= 2*I
Sum=Sum+val
End for
Return Sum
End
Apply step count method and analyze the algorithm segment

09/02/2023
Case Study: Homework

Algorithm Sample()
Begin
for i = 1 to n do
return i
End for
End

Apply step count method and analyze the algorithm segment

09/02/2023
Case Study: Homework

Algorithm Sample()
Begin
for i = 1 to n do
for j=1 to n do
A(i,j)=0
End for
End for
End
Apply step count method and analyze the algorithm segment

09/02/2023
Operation Count

Another way of performing algorithm analysis.

Counts the number of operations instead of steps for


algorithm analysis.

Operations can be divided into two categories


• Elementary Operations: Assignment, Comparison, Arithmetic, Logical
• Non Elementary Operations: Sorting, Finding maximum or minimum in
an array
09/02/2023
Steps required for performing Operation Count

Count the number of basic operations of a program and express


it as a formula.

Simplify the formula

Represent time complexity as a function of the operation count.

09/02/2023
Rules for performing Operation Count

Consider the algorithm segment


• Begin
• s1
• s2
• End
Let the statement s1 require m operations and statement s2 require n
operations.
Then the whole algorithm requires (m+n) operations.

This is called the addition principle.

09/02/2023
Rules for performing Operation Count contd…

Consider the algorithm segment

• If (Condition C) Then Statement P


• Else Statement Q
Let the statement P require m operations and statement s2 require n
operations.

Thus, the if-then-else statement requires maximum(m,n) operations

The maximum number of operations of either the if-part or the else-part is


considered as the operation count of this segment.

09/02/2023
Rules for performing Operation Count contd…

If a loop executes a task n times and if the task involves


m operations, then the operation count is given as n x m.

This is called the multiplication principle.

09/02/2023
Case Study

Algorithm swap(a,b)
Begin
temp=a
a=b
b=a
End
Perform Complexity Analysis using Operation Count

09/02/2023
Case Study Contd…
Step Number Algorithm Operations Operation Count Repetitions Total
Segment Accounted for

1 Algorithm 0 - 0 0
swap(a,b)
2 Begin 0 - 0 0
3 temp=a Assignment C1 1 C1

4 a=b Assignment C2 1 C2

5 b=a Assignment C3 1 C3
6 End 0 - - -
Total T(n) C1 + C2 +
C3
09/02/2023
Case Study

Algorithm Sample()
Begin
for k=1 to n do
A=A x k
End for
End

Perform Complexity Analysis using Operation Count

09/02/2023
Case Study Contd…
Step Number Algorithm Operations Operation Count Repetitions Total
Segment Accounted for

1 Algorithm 0 - 0 0
Sample()
2 Begin 0 - 0 0
3 for k=1 to n Assignment C1 n+1 (n+1) x C1
do , testing and
increment
4 A=A x k Multiplicati C2 n nC2
on
5 End for - - - -
6 End - - - -
Total T(n) (n+1) C1 +
nC2
T(n) =(C1 +C2)n +C1
09/02/2023
09/02/2023
Designing an Algorithm: Best Case, Worst Case and
Average Case Complexity

09/02/2023
Algorithms

Polynomial Exponential

Polynomial Time Exponential


Complexity Time Complexity

   

09/02/2023
Measuring Complexity Again

Efficiency of algorithm does not only depend on the input size

It depends on the distribution of input as well

Worst- case, best-case and average-case efficiency of algorithms can


be estimated by considering different distributions of input data.

 
09/02/2023
Measuring Complexity Again

 
09/02/2023
Best, Worst, and Average Case

09/02/2023
Simplifications

Ignore constants
• 
• 

Asymptotic Efficiency
• 

 
09/02/2023
Why ignore constants?

RAM model introduces errors in constants


• Do all instructions take equal time?
• Specific implementation (hardware, code optimizations)
can speed up an algorithm by constant factors
• We want to understand how effective an algorithm is
independent of these factors

Simplification of analysis
• 

09/02/2023
the order of some common used functions
1 logn n nlogn n2 2n n! nn

09/02/2023
Asymptotic Analysis

• Goal: to simplify analysis of running time by getting rid of”details”, which may be affected by
specific implementation and hardware

• like“rounding”: 1,000,001=1,000,000

• 3n2=n2

• Capturing the essence: how the running time of an algorithm increases with the size of the input
in the limit.

• Asymptotically more efficient algorithms are best for all but small inputs

09/02/2023
Asymptotic Analysis

• Simple Rule: Drop lower order terms and constant factors.

• 50 n log n is O(n log n)

• 7n -3 is O(n)

• 8n2log n + 5n2+ n is O(n2log n)

09/02/2023
Asymptotic Analysis

• Use O-notation to express number of primitive operations executed as function of input size.

• Comparing asymptotic running times


• an algorithm that runs in O(n) time is better than one that runs in O(n2) time

• similarly, O(log n) is better than O(n)

• hierarchy of functions: log n < n < n2< n3< 2n

• Caution!Beware of very large constant factors. An algorithm running in time 1,000,000 n is


still O(n) but might be less efficient than one running in time 2n2, which is O(n2)

09/02/2023
Asymptotic Notation

• The “big-Oh” O-Notation


• asymptotic upper bound

• f(n) is O(g(n)), if there exists constants c and n0, s.t.

f(n) <=c g(n) for all n >= n0


• f(n) and g(n) are functions over non-negative integers

09/02/2023
Asymptotic Notation
• The “big-Omega” Ὡ- Notation
• asymptotic lower bound

• f(n) is Ὡ (g(n)) if there exists constants c and n0, s.t. c g(n) <=f(n) for n >=n0

• Used to describe best-case running times or lower bounds for algorithmic


problems
• E.g., lower-bound for searching in an unsorted array is Ὡ (n).

09/02/2023
Asymptotic Notation

• The “big-Theta” Θ - Notation

• asymptotically tight bound

• Θf(n) is Θ(g(n)) if there exists constants c1, c2, and n0,

s.t. c1 g(n) <=f(n) <=c2 g(n) for n >= n0

• f(n) is Θ(g(n)) if and only if f(n) is O(g(n)) and f(n) is Θ(g(n))

• O(f(n)) is often misused instead of Θ(f(n))


09/02/2023
Asymptotic Notation
• Two more asymptotic notations

• "Little-Oh" notation f(n) is o(g(n))non-tight analogue of Big-Oh


• For every c>0, there should exist n0 ,s.t. f(n) <=c g(n)for n >=n0

• Used for comparisons of running times. If f(n) is o(g(n)), it is said that g(n)
dominates f(n).

• "Little-omega" notation f(n) is w(g(n)) non-tight analogue of Big-Omega

09/02/2023
09/02/2023
Set Notation Comment

However, we will use one-way equalities like


•  

Analogy
• “A dog is an animal” but not “an animal is a dog”
09/02/2023
Example Function

09/02/2023
ASYMTOTIC NOTATION

09/02/2023
Measuring Complexity Again
• The worst case running time of an algorithm is the function defined by
the maximum number of steps taken on any instance of size n.

• The best case running time of an algorithm is the function defined by


the minimum number of steps taken on any instance of size n.

• The average-case running time of an algorithm is the function defined


by an average number of steps taken on any instance of size n.

• Which of these is the best to use?

09/02/2023
Average case analysis

• Drawbacks
• Based on a probability distribution of input instances
• How do we know if distribution is correct or not?

• Usually more complicated to compute than worst case running time


• Often worst case running time is comparable to average case running time(see next graph)
• Counterexamples to above:
• Quicksort
• simplex method for linear programming

09/02/2023
Best, Worst, and Average Case

09/02/2023
Worst case analysis

• Typically much simpler to compute as we do not need to “average”


performance on many inputs
• Instead, we need to find and understand an input that causes worst case performance

• Provides guarantee that is independent of any assumptions about the input

• Often reasonably close to average case running time

• The standard analysis performed

09/02/2023
Motivation for Asymptotic Analysis

• An exact computation of worst-case running time can be difficult


• Function may have many terms:
• 4n2 - 3n log n + 17.5 n - 43 n⅔ + 75

• An exact computation of worst-case running time is unnecessary


• Remember that we are already approximating running time by using RAM
model

09/02/2023
Simplifications

• Ignore constants
• 4n2 - 3n log n + 17.5 n - 43 n⅔ + 75 becomes

• n2 – n log n + n - n⅔ + 1

• Asymptotic Efficiency
• n2 – n log n + n - n⅔ + 1 becomes n2

• End Result: Θ(n2)

09/02/2023
Why ignore constants?
• RAM model introduces errors in constants
• Do all instructions take equal time?
• Specific implementation (hardware, code optimizations) can speed up an
algorithm by constant factors
• We want to understand how effective an algorithm is independent of these
factors
• Simplification of analysis
• Much easier to analyze if we focus only on n2 rather than worrying about 3.7
n2 or 3.9 n2

09/02/2023
Asymptotic Analysis

• When we focus at input sets large enough to make only


order of growth of the running time relevant, we are
studying asymptotic efficiency of algorithms.

• Usually, an algorithm that is asymptotically more efficient


will be the best choice for all but very small inputs.

0 infinity

09/02/2023
Big Oh , Big Omega and Big Theta
Notation

• 

09/02/2023
Set Notation Comment

• O(g(n)) is a set of functions.


• However, we will use one-way equalities like
n = O(n2)
• This really means that function n belongs to the set of
functions O(n2)
• Incorrect notation: O(n2) = n
• Analogy
• “A dog is an animal” but not “an animal is a dog”

09/02/2023
Three Common Sets

f(n) = O(g(n)) means c  g(n) is an Upper Bound on f(n)

f(n) = (g(n)) means c  g(n) is a Lower Bound on f(n)

f(n) = (g(n)) means c1  g(n) is an Upper Bound on f(n)


and c2  g(n) is a Lower Bound on f(n)

These bounds hold for all inputs beyond some threshold n 0.

09/02/2023
O(g(n))

09/02/2023
(g(n))

09/02/2023
(g(n))

09/02/2023
O(f(n)) and (g(n))

O( f (n))  1
100
n2

( g (n))  1
25
n

09/02/2023
Example Function

f(n) = 3n - 100n + 6
2

09/02/2023
Quick Questions
c n0
3n2 - 100n + 6 = O(n2)
3n2 - 100n + 6 = O(n3)
3n2 - 100n + 6  O(n)

3n2 - 100n + 6 = (n2)


3n2 - 100n + 6  (n3)
3n2 - 100n + 6 = (n)

3n2 - 100n + 6 = (n2)?


3n2 - 100n + 6 = (n3)?
3n2 - 100n + 6 = (n)?
09/02/2023
“Little Oh” Notation

• o(g(n)) = {f(n) : "c >0 $n0 > 0 such that "n ≥ n0


0 ≤ f(n) < cg(n)}

• Intuitively, limn f(n)/g(n) = 0

• f(n) < c g(n)

09/02/2023
Two Other Sets

f(n) = o(g(n)) means c  g(n) is a strict upper bound on f(n)

f(n) = w(g(n)) means c  g(n) is a strict lower bound on f(n)

These bounds hold for all inputs beyond some threshold n0


where n0 is now dependent on c.

09/02/2023
Example Problems
1. What does it mean if:
f(n)  O(g(n)) and g(n)  O(f(n)) ???

2. Is 2n+1 = O(2n) ?
Is 22n = O(2n) ?

3. Does f(n) = O(f(n)) ?

4. If f(n) = O(g(n)) and g(n) = O(h(n)),


can we say f(n) = O(h(n)) ?
09/02/2023
Recursive Algorithm Analysis

09/02/2023
Chapter Objectives

• Basics of recurrence equations

 Formulation of recurrence equations

 Solving recurrence equations using different methods

 Basics of divide-and-conquer recurrences

 Master theorem for solving recurrence equations

 Conditional asymptotics

09/02/2023
Skills required

A recurrence equation defines a sequence using the elements of


that sequence.

Recurrence equations are used to analyse recursive programs

To analyze a recursive algorithm, two basic skills are required


• Formulating a recurrence equation
• Solving the recurrence equation to understand the behaviour of the program

09/02/2023
Types

Recurrence Relation

Non-Linear Recurrences e.g.


Liner Recurrences
Divide-and-Conquer Recurrence

Expresses the final term as a


linear combination of its
previous terms in a polynomial
form

09/02/2023
09/02/2023
Constant vs Variable Coefficient
In the generic linear recurrence equation

a t + a t + … + a t = f(n),
0 n 1 n−1 k n−k

the terms ai can be constants or variables.

Based on this fact, one can classify linear recurrence equations into two types: linear
recurrence equations with constant coefficients and those with variable coefficients.

Consider the following linear recurrence equation:


t=n×t
n n−2

This recurrence equation is dependent on the variable n and does not have constant
coefficients.

09/02/2023
09/02/2023
Analysis of Framework
For example, for the sequence 1, 4, 7, 10, …, one can write the recurrence equation as
follows:

T(n) = T(n − 1) + 3
T(0) = 1

It can be observed that T(0) = 1 is a base condition.

From this equation, T(1) can be generated as


T(0) + 3 = 4 and
T(2) as T(1) + 4 = 7.

Similarly, all terms of the sequence can be generated.

The preceding equation can be denoted as follows:


tn = tn−1 + 3
t0 = 0
09/02/2023
Example

•Example 4.1 What is the recurrence equation for the sequence 1000, 2000, 4000, 8000, …?

•Solution

• t0 = 1000

• t1 = 2000 = 2 × 1000 = 2 × t0

• t2 = 4000 = 2 × 2000 = 2 × t1 = 22 t0

•

•∴, one would guess

• tn = 2 × t(n-1) or tn = 2n × t0

•It can be observed that tn = 2 × t(n-1) is the required recurrence equation of this problem.

09/02/2023
Example
Example 4.2 Find the recurrence equation and the initial condition of the following
sequence:
7, 21/4 , 63/16, 189/64 , …
Solution
Let the initial condition be t0 = 7. Let us observe the patterns. Let us calculate the ratios of
the successive elements as follows:

t1 /t0 = 21/4 ÷ 7 = 21 ÷ 28 = 3/4;


t2 /t1 = 63/16 ÷21 4 = 63 /16 x4 /31 = 3/4;
t3 /t2 = 189 /64 ÷ 63/ 16 = 189 /64 × 16 /63 = 3/4
Therefore, one can predict that tn /tn–1 = 3/4
Therefore, tn = tn−1 × 3/4
Thus, one can conclude that the recurrence equation is tn = tn-1 × 3/4.

09/02/2023
Techniques for Solving

Guess and verify

Substitution Method

Recurrence tree method

Difference Method

Polynomial reduction method

Generating function method

Table look-up method or master theorem

09/02/2023
Guess and Verify Methods
Known by various names such as guess and verify, guess and test
and solution by mathematical induction or method of
substitution(Cormen)

It comprises of two important aspects

Guess: Guess the solution by substituting the different values of n


to generate the sequence from the recurrence equation.

• The closed form can be obtained by verifying the sequences carefully


• The technique is thus to guess the closed form that may be the solution of the given
recurrence equation.

Verify: The second part of this method is to verify the solution


guessed in the first phase.

• Verification is required because the solution is just a guess.


• Justification is carried out using the techniques of mathematical induction.
• Based on verification, solutions are established for given recurrence equation.
09/02/2023
Example
Example 4.7 Solve the recurrence equation tn = tn−1 + 2 t0 = 1 using the guess-and-
verify method.

Solution As said earlier, first make a guess of the solution and then verify it.

Guess: For making a guess, use different values of n in the recurrence equation as follows:
t0 = 1
t1 = t1−1 + 2 = t0 + 2 = 3
t2 = t2−1 + 2 = t1 + 2 = 5
t3 = t3−1 + 2 = t2 + 2 = 7
:
:
The sequence obtained (1, 3, 5, 7, …) indicates that every term differs from the previous
one by 2. This is an odd-number series. Therefore, one can guess that the solution for the
recurrence equation would be 2n + 1. As this is a non-recursive formula in terms of n, this
can be a solution. To confirm this, one should verify the guess.

09/02/2023
Examples of Input Size

09/02/2023
09/02/2023
09/02/2023
Substitution method

Involves 2 Steps

Plug: Substitute Chug: Simplify


Repeatedly the expressions

09/02/2023
Backward Substitution
 
The process is continued till the closed form is obtained, which can be confirmed by the observation of the common pattern
that emerges from the process of repeated substitution

09/02/2023
09/02/2023
Forward Substitution
 

09/02/2023
Recurrence Tree Method

09/02/2023
Recurrence Tree Method

09/02/2023
09/02/2023
09/02/2023
09/02/2023
Difference Method

09/02/2023
Polynomial Reduction

09/02/2023
09/02/2023
09/02/2023
09/02/2023
09/02/2023
Non-homogeneous Equations

09/02/2023
09/02/2023
09/02/2023
Generating Functions

09/02/2023
09/02/2023
09/02/2023
Procedure

09/02/2023
09/02/2023
09/02/2023
09/02/2023
Master Theorem

09/02/2023
09/02/2023
09/02/2023
Akra_Bazzi Theorem

•Akra–Bazzi Theorem and its Generalization

•In 1998, two Lebanon-based researchers provided the solutions for the generalized form of the master theorem, which is as
follows:

•T(n) = h(n) for 1 ≤ n ≤ n0

•aT ( a bk) + f(n) for n ≥ n0

•Here, a > 0, b > 1, and n0 ≥ b are integers; h(n) is a function that is in the range d1 ≤ h(n) ≤ d2 for two constants d1 and d2 and 1 ≤
n ≤ n0; and f(n) is a positive polynomial that is in the range c1g(n) ≤ f(n) ≤ c2g(n) for all x > 0 and u ∈ nb , n. If all
these conditions are satisfied and the condition a bp = 1 is true, then the solution of the recurrence is given as follows:

•T(n) = Θ(np(1 + u∫1 f(u) uP+1 ))

•This is a powerful theorem and solves almost all those recurrences that cannot be solved easily by other methods.

09/02/2023
Example

09/02/2023
Generalized Master Theorem

09/02/2023
09/02/2023
Example

09/02/2023
Cases where master theorem fails

09/02/2023
Transformation

09/02/2023
Example

09/02/2023
Range Transform

09/02/2023
Example

09/02/2023
Conditional Asymptotics

09/02/2023
Smoothness Rule

09/02/2023
Example

09/02/2023
09/02/2023

You might also like