Vous êtes sur la page 1sur 15

Incremental

and
Decremental
Algorithm
Design
Incremental and Decremental Algorithm Design
Strategies
Strategies
Dr. Munesh
Singh

Dr. Munesh Singh

Indian Institute of Information Technology


Design and Manufacturing,
Kancheepuram
Chennai-600127

February 25, 2019


Algorithm Design Strategies

Incremental
and Incremental Algorithm Design
Decremental
Algorithm Our first intuition when looking at an algorithmic problem
Design
Strategies is to think of the whole input and try to find a solution for
Dr. Munesh it.
Singh
The incremental method is different. It assumes that you
have already found a solution, and now someone gives you
a slightly larger problem and asks you to extend the
solution.
If you can find a general way to extend the solution, then
you can start with an empty input and keep extending it.

Decremental Algorithm Design


Decremental algorithms are algorithms in which only
deletions of elements are allowed, starting with an
initialization of a full data structure.
Incremental
and Incremental Mathematical Induction
Decremental

Prove 1+2+3+4+—-n= n(n+1)


Algorithm
Design 2
Strategies

Dr. Munesh
Basis: n=1, we check LFS and RHS satisfies.
Singh
if base condition satisfy, then we do the induction
Induction 1+2+3+4+—-+k= k(k+1)
2
Prove for n=k+1;
1+2+3+4+—-+k+k+1= k(k+1)
2

Incremental Algorithm Strategies


n
1+3+32 +—–+3n−1 = 3 2−1
2
13 + 23 + 33 + − − − + n3 = n(n+1)
2
7n − 3n is divisible by 4
Algorithm Design Through Incremental Approch

Incremental
and Counting Regions in the plane
Decremental
Algorithm If no two lines are parallel and no three lines intersect at a
Design
Strategies common point. The next problem is to compute the
Dr. Munesh number of region in the plane formed by n line in general
Singh
position.

Incremental Appraoch
Good hint for the right guess can be obtained from small
cases.
Base Case
When n=1, there are 2 regions.
When n=2, there are 4 regions.
When n=3, there are 7 regions.
Induction Case
Algorithm Design Through Incremental Approch

Incremental
and
Decremental
Algorithm
Design
Strategies

Dr. Munesh
Incremental Appraoch Cont...
Singh
Induction Case
As we have already seen, the guess is true for n<=3.
We can now use the guess as our induction hypothesis,
adding one line increases the number of regions by n+1
Here is two ways to prove this problem, one by calculating
the number of region, and another with the growth rate of
the function
Algorithm Design Through Incremental Approch

Incremental
and
Decremental
Algorithm Incremental Appraoch For Problem 2
Design
Strategies Consider again n distinct lines in a plane, this time not
Dr. Munesh necessarily in general position. We are interested in
Singh
assigning colors to the region formed by these lines such
that neighboring regions have different color.
Problem It is possible to color regions formed by any
number of lines in the plane with only two colors.
Base Case: It is clear that two colors are necessary and
sufficient for n=1.
Assume the induction hypothesis, and consider n lines.
The idea is usually to stretch the hypothesis as much as
possible in order to get the most out of it.
Algorithm Design Through Incremental Approch

Incremental
and
Decremental
Algorithm Incremental Appraoch For Problem 2
Design
Strategies Consider again n distinct lines in a plane, this time not
Dr. Munesh necessarily in general position. We are interested in
Singh
assigning colors to the region formed by these lines such
that neighboring regions have different color.
Problem It is possible to color regions formed by any
number of lines in the plane with only two colors.
Base Case: It is clear that two colors are necessary and
sufficient for n=1.
Assume the induction hypothesis, and consider n lines.
The idea is usually to stretch the hypothesis as much as
possible in order to get the most out of it.
A More Complicated Summation Problem

Incremental
and Incremental Appraoch For Problem 3
Decremental
Algorithm
Design
Strategies

Dr. Munesh
Singh

Problem The problem is to find an expression for the sum


of the ith row, and prove its correctness.
Base Case: It is clear that first row sum cube is the same
number.
Induction hypothesis: The sum of ow i in the triangle is
i3
The ith row contains i numbers. The numbers are the odd
numbers in order.
A More Complicated Summation Problem

Incremental
and Incremental Appraoch For Problem 3
Decremental
Algorithm
Design
To prove that the sum of row i is i 3 , we need only to show
Strategies that the difference between row i+1 and row i is
Dr. Munesh
Singh
(i + 1)3 − i 3
What is the difference between the first number in row
i+1 and the first number in row i?
Since the number are the odd numbers in order and there
are i of them in row i, the difference is 2i.
Overall, there are i differences, each of size 2i. Hence, the
difference between the two rows is 2i 2 .
There is also the last element at the end of row i+1,
which is not matched to any number in the previous row.
Since (i + 1)3 − i 3 = 3i 2 + 3i + 1, we need to prove that
the value of the last number in row i+1 is 3i 2 + 3i + 1.
A More Complicated Summation Problem

Incremental
and
Decremental
Algorithm
Design
Strategies Incremental Appraoch For Problem 3
Dr. Munesh Nested induction hypothesis: The last number in row
Singh
i+1 is i 2 + 3i + 1
We have reduced the problem of finding the sum to a
problem of finding an element.
The claim is true for i=1. Now it is sufficient , by
induction, to check only the differences. That is, we have
to prove that the difference between the last number in
row i+1 and the last number in row is equal to
(i 2 + 3i + 1) − (i − 1)2 + 3(i − 1) + 1) = 2i + 2
Prove Using the Mathematical Induction

Incremental
and
Decremental
Algorithm Apply Incremental Appraoch
Design
Strategies Find an expression for the sum of the ith row of the
Dr. Munesh following triangle, which is called the Pascal triangle, and
Singh
prove the correctness of your claim. The sides of the
triangle are 1s, and each other entry is the sum of the two
entries directly above it.
Prove Using the Mathematical Induction

Incremental
and
Decremental Apply Incremental Appraoch
Algorithm
Design
Strategies
Find an expression for the sum of the ith row of the
Dr. Munesh
following triangle, and prove the correctness of your claim.
Singh Each entry in the triangle is the sum of the three entries
directly above it (a non-existing entry is considered 0).
Lower Bound for Sorting Algorithm

Incremental
and
Decremental
Algorithm
Design TheoremEvery ”comaprison-based” sorting algorithm has
Strategies
worst-case running time Ω(nlogn) (assume for
Dr. Munesh
Singh deterministic algorithm, but lower bound can be extended
to randomized)
Comparison Based Sort Access input array elements
”general purpose sorting algorithm method” Eg. Merge
sort, Quick Sort, Heap Sort
Non Comparison Based Radix Sort, Bucket Sort,
Counting Sort
How to prove the every comparison based algorithm taken
Ω(nlogn)?
Prof of Comaprsion Based Algorithm

Incremental
and
Decremental
Algorithm
Design
Strategies

Dr. Munesh e1,e2,e3


Singh n! e1:e2
3! e1<e2 e1>e2

e1 e2 e3 e1 e3 e2 e1:e3
e1>e3
e2:e3
e1<e3 e2<e3 e2>e3
e2 e1 e2 e3 e1 e3 e2:e3 e3,e1,e2 e1:e3 e3,e2,e1

e3 e3 e1 e2 e2 e1e2<e3 e2>e3 e1<e3 e1>e3


e1,e2,e3 e1,e3,e2 e2,e1,e3 e2,e3,e1
Proof of Comaprsion Based Algorithm

Incremental
and
Decremental
Algorithm
Design
Strategies Lets take three element e1, e2, e3, to find out how many
Dr. Munesh
Singh
permutation possible for these three elements.
In the below tree all permutation are formed at leaves of
tree
A tree with height h has at max 2h leaves
Let l be the number of leaves in the tree, then
n!<= l <= 2h
Take a log both the side then h >= log (n!), so time
complexity in worst case will be Ω(nlogn)

Vous aimerez peut-être aussi