0% found this document useful (0 votes)
10 views6 pages

Co 1 (Lo 3)

Uploaded by

deepti.u.1228
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Co 1 (Lo 3)

Uploaded by

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

Recurrence relations and non-recurrence relations are mathematical equations or formulas

that describe the relationship between terms in a sequence. These concepts are often
encountered in various fields of mathematics, computer science, and engineering,
particularly in the study of sequences, algorithms, and dynamic processes.

1. Recurrence Relation: A recurrence relation defines the terms of a sequence based


on previous terms in the same sequence. It expresses a term in the sequence as a
function of one or more previous terms. In other words, it recursively defines each
term in relation to the ones that come before it. Recurrence relations are commonly
used to model iterative processes and dynamic behaviours.

Example of a linear recurrence relation: Fibonacci sequence

F(0) = 0

F(1) = 1

F(n) = F(n-1) + F(n-2) for n ≥ 2

In this example, each term is the sum of the two previous terms.

2. Non-Recurrence Relation: Non-recurrence relations, on the other hand, define


terms of a sequence without relying on previous terms in the sequence. These
relations usually involve direct formulas or equations that express each term
independently of its predecessors.

Example of a non-recurrence relation: Arithmetic sequence

a(n) = a(1) + (n - 1) * d

In an arithmetic sequence, each term is calculated by adding a constant difference, "d," to


the initial term, "a(1)."

Recurrence relations are often used when there's a natural progression or dependency
among the terms, making them suitable for describing processes that evolve over time.
Non-recurrence relations, on the other hand, are more appropriate when the terms don't
rely on previous terms and can be computed directly.

Both types of relations have their applications in various areas. Recurrence relations are
commonly used in algorithm analysis, dynamic programming, and solving difference
equations, while non-recurrence relations are often seen in arithmetic and geometric
sequences, as well as in formulas for calculating interest, growth, and other non-iterative
processes.
Mathematical analysis of recursive and non-recursive algorithms involves evaluating their
time complexity and space complexity in terms of mathematical functions and expressions.
This analysis helps us understand how the algorithms perform in terms of time and memory
usage as the input size grows.

1. Time Complexity Analysis: Time complexity measures the amount of time an


algorithm takes to complete its execution as a function of the input size. It provides
an understanding of how the algorithm's performance scales with larger inputs.
 Recursive Algorithms: Analyzing the time complexity of recursive algorithms often
involves solving recurrence relations. The recurrence relation describes the time
required to solve a problem of size n in terms of the time required to solve smaller
subproblems. Solving the recurrence relation gives an expression for the algorithm's
time complexity.
 Non-Recursive Algorithms: For non-recursive algorithms, you can often determine
their time complexity by analyzing the number of basic operations performed as a
function of the input size. The operations can include comparisons, assignments,
arithmetic operations, etc. You derive an equation that represents the time
complexity and express it using mathematical notation.

Common notations used for time complexity analysis include O-notation (big O), Ω-
notation (big Omega), and Θ-notation (big Theta), which provide upper, lower, and tight
bounds on the algorithm's growth rate, respectively.

2. Space Complexity Analysis: Space complexity refers to the amount of memory an


algorithm uses to solve a problem as a function of the input size. It gives insights into
how the algorithm's memory usage increases with larger inputs.
 Recursive Algorithms: Recursive algorithms often use function call stacks to manage
recursion. The space complexity analysis involves considering the maximum depth of
recursion and the memory required for each recursive call. This analysis is similar to
time complexity analysis but focuses on memory usage.
 Non-Recursive Algorithms: For non-recursive algorithms, you analyze the memory
required for variables, data structures, and temporary storage as the input size
increases. Just like with time complexity, you express the space complexity using
mathematical notations such as O, Ω, and Θ.

Remember that analyzing both time and space complexity involves counting the dominant
operations or memory usage, which have the most significant impact on the overall
performance.

In summary, mathematical analysis of recursive and non-recursive algorithms involves


deriving mathematical expressions that describe their time and space complexity. This
analysis helps in understanding the efficiency and scalability of algorithms, which is crucial
for making informed decisions about algorithm selection and optimization.
Master Theorem: The Master Theorem is a tool used to solve recurrence
relations that arise in the analysis of divide-and-conquer algorithms. The Master
Theorem provides a systematic way of solving recurrence relations of the form:
T(n) = aT(n/b) + f(n)
1. where a, b, and f(n) are positive functions and n is the size of the
problem. The Master Theorem provides conditions for the solution of the
recurrence to be in the form of O(n^k) for some constant k, and it gives a
formula for determining the value of k.
2. The advanced version of the Master Theorem provides a more general
form of the theorem that can handle recurrence relations that are more
complex than the basic form. The advanced version of the Master
Theorem can handle recurrences with multiple terms and more complex
functions.
3. It is important to note that the Master Theorem is not applicable to all
recurrence relations, and it may not always provide an exact solution to a
given recurrence. However, it is a useful tool for analyzing the time
complexity of divide-and-conquer algorithms and provides a good
starting point for solving more complex recurrences.
Master Theorem is used to determine running time of algorithms (divide and
conquer algorithms) in terms of asymptotic notations.
Consider a problem that is solved using recursion.

function f(input x size n)


if(n < k)
solve x directly and return
else
divide x into a subproblems of size n/b
call f recursively to solve each subproblem
Combine the results of all sub-problems

The above algorithm divides the problem into a subproblems, each of size n/b and
solve them recursively to compute the problem and the extra work done for
problem is given by f(n), i.e., the time to create the subproblems and combine their
results in the above procedure.

So, according to master theorem the runtime of the above algorithm can be
expressed as:

T(n) = aT(n/b) + f(n)


where n = size of the problem
a = number of subproblems in the recursion and a >= 1
n/b = size of each subproblem
f(n) = cost of work done outside the recursive calls like dividing into subproblems
and cost of combining them to get the solution.
Not all recurrence relations can be solved with the use of the master theorem i.e. if

 T(n) is not monotone, ex: T(n) = sin n


 f(n) is not a polynomial, ex: T(n) = 2T(n/2) + 2 n
This theorem is an advance version of master theorem that can be used to
determine running time of divide and conquer algorithms if the recurrence is of the
following form :-

where n = size of the problem


a = number of subproblems in the recursion and a >= 1
n/b = size of each subproblem
b > 1, k >= 0 and p is a real number.
Then,

1. if a > bk, then T(n) = θ(nlog a)


b

2. if a = bk, then
(a) if p > -1, then T(n) = θ(n log a logp+1n)
b

(b) if p = -1, then T(n) = θ(n log a loglogn)


b

(c) if p < -1, then T(n) = θ(n log a)


b

3. if a < bk, then


(a) if p >= 0, then T(n) = θ(n k logpn)
(b) if p < 0, then T(n) = θ(n k)

Time Complexity Analysis –

 Example-1: Binary Search – T(n) = T(n/2) + O(1)


a = 1, b = 2, k = 0 and p = 0
bk = 1. So, a = bk and p > -1 [Case 2.(a)]
T(n) = θ(nlog a logp+1n)
b

T(n) = θ(logn)
 Example-2: Merge Sort – T(n) = 2T(n/2) + O(n)
a = 2, b = 2, k = 1, p = 0
bk = 2. So, a = bk and p > -1 [Case 2.(a)]
T(n) = θ(nlog a logp+1n)
b

T(n) = θ(nlogn)
 Example-3: T(n) = 3T(n/2) + n2
a = 3, b = 2, k = 2, p = 0
bk = 4. So, a < bk and p = 0 [Case 3.(a)]
T(n) = θ(nk logpn)
T(n) = θ(n2)

 Example-4: T(n) = 3T(n/2) + log2n


a = 3, b = 2, k = 0, p = 2
bk = 1. So, a > bk [Case 1]
T(n) = θ(nlog a )
b

T(n) = θ(nlog 3)
2

 Example-5: T(n) = 2T(n/2) + nlog2n


a = 2, b = 2, k = 1, p = 2
bk = 2. So, a = bk [Case 2.(a)]
T(n) = θ(nlog alogp+1n )
b

T(n) = θ(nlog 2log3n)


2

T(n) = θ(nlog3n)

 Example-6: T(n) = 2nT(n/2) + nn


This recurrence can’t be solved using above method since function is not
of form T(n) = aT(n/b) + θ(n k logpn)

Here are some important points to keep in mind regarding the Master
Theorem:
1. Divide-and-conquer recurrences: The Master Theorem is specifically
designed to solve recurrence relations that arise in the analysis of divide-
and-conquer algorithms.
2. Form of the recurrence: The Master Theorem applies to recurrence
relations of the form T(n) = aT(n/b) + f(n), where a, b, and f(n) are positive
functions and n is the size of the problem.
3. Time complexity: The Master Theorem provides conditions for the solution
of the recurrence to be in the form of O(n^k) for some constant k, and it
gives a formula for determining the value of k.
4. Advanced version: The advanced version of the Master Theorem provides
a more general form of the theorem that can handle recurrence relations
that are more complex than the basic form.
5. Limitations: The Master Theorem is not applicable to all recurrence
relations, and it may not always provide an exact solution to a given
recurrence.
6. Useful tool: Despite its limitations, the Master Theorem is a useful tool for
analyzing the time complexity of divide-and-conquer algorithms and
provides a good starting point for solving more complex recurrences.
7. Supplemented with other techniques: In some cases, the Master Theorem
may need to be supplemented with other techniques, such as the
substitution method or the iteration method, to completely solve a given
recurrence relation.

You might also like