SlideShare a Scribd company logo
1 of 11
Download to read offline
Divide and Conquer
Andres Mendez-Vazquez
August 26, 2015
Contents
1 Improving Algorithms 2
1.1 Using Multiplication of Imaginary Numbers . . . . . . . . . . . . 2
2 Using Recursion to Find Complexities 4
3 Asymptotic Notation 6
3.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Relations between Θ and O and Ω . . . . . . . . . . . . . . . . . 7
3.3 Some examples about little o and ω . . . . . . . . . . . . . . . . 7
4 Solving Recurrences 8
4.1 Substitution Method . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.1.1 Subtleties of the Substitution Method . . . . . . . . . . . 8
4.2 The Reduced Version of the Master Theorem . . . . . . . . . . . 8
1
1 Improving Algorithms
Although, we saw already a simple way of reducing the complexity of an al-
gorithm by avoiding as much as possible the recursion by memorizing previous
smaller values (Iterative Fibonacci). It is clear that neater tricks must exist
in the realm of possible solutions while solving problems for algorithms. Thus,
looking a those tricks is quite important to be able to learn how to improve on
many different algorithms.
A clever strategy for improving algorithms is the well known Divide and
Conquer which consists of the following steps:
1. Divide. Here the algorithm must split the large problem into smaller
version, thus they can be solved recursively by using new algorithm in-
stantiation and the smaller inputs.
2. Conquer. At this moment, we use the idea of induction by going first
backwards to the basis case where the easiest solution can be find, then
the procedure is ready to go forward.
3. Combine. Here, we use the previously calculated answers to build the
an answer for each subproblem. For example in the case of Fibonacci:
Fn = Fn−1 + Fn−2 (1)
Then, it is essential to build clever algorithms that can build efficient answers
for given problems. Thus, the importance of looking at several possible tricks
to be able to obtain a basic intuitions for them!!! In order to avoid exponential
number of steps while calculating the answer.
The next example of a clever trick that we will be studying is coming from the
Prince of Mathematics, Frederich Carl Gauss (1777-1855) [1]. This improvement
was developed by Anatoly Alexeevitch Karatsuba (1937 - 2008) at the Faculty
of Mechanics and Mathematics of Moscow State University [2].
1.1 Using Multiplication of Imaginary Numbers
Even when we could have a efficient strategy to do the divide and conquer,
the most difficult part is always the combine one because the need of not only
doing simple combinations of subproblems, but clever ones. For example, given
that the numbers could be represented as x = xL ◦ xR = 2n/2
xL + xR by
assuming that n (Size of each of string of bits) is even. As an example of this,
x = 10110110 can be seen as the left bits concatenated to right bits: xL = 1011
and xR = 0110. Then, x = 1011 × 24
+ 0110.
Thus, the multiplication between two numbers, x and y, can be found using
the following equation:
2
xy = 2n/2
xL + xR 2n/2
yL + yR
=2n
xLyL + 2n/2
(xLyR + xRyL) + xRyR
Making possible to use the recursion to obtain the final multiplication be-
tween both numbers (Algorithm 1). This algorithm has the following total time:
T (n) = 4T
n
2
+ Somework. (2)
Where Somework correspond to the addition of the results obtained by
calling the function in the left and right sections of both numbers. Although
at the beginning, the recursive function looks quite complex, it is actually one
the easiest to solve by means of the recursive three to guess the complexity. In
addition, once you equipped with the three main methods of basic complexity
calculation:
• The Recursion-Tree Method.
• The Substitution Method.
• The Master Theorem Method.
Using these methods, it is possible to see that this recursive function is bounded
by cn2
time for some constant c.
An immediate question for anybody trying to improve this naive algorithm
is the following one: Can be possible to have an algorithm able to perform the
multiplication in shorter time? The answer is actually more convoluted than
one can imagine. First, for many problems is possible to obtain absolute lower
bounds that have not been reached by any actual algorithms used to solve them.
An example of this situation is the algorithms used for matrix multiplication [3].
Therefore, from the philosophical point of view of algorithms, we at algorithms,
first develop an initial solution and later on, we try to develop a faster solution.
Thus, What will allow us to improve the naive multiplication? While looking
through the history of mathematics (It is always a good starting point for any
developer of algorithms) Karatsuba [2] noticed that it is possible to have the
following representation of imaginary numbers in a computer:
100100100101 010101110110
Bits for imaginary Bits for real
He was able to see that imaginary numbers could be seen as binary numbers
with n
2 + n
2 bits. Thus, binary number can be seen as imaginary number where
x = 2
n
2 × xL
Imaginary
+ xR
Real
(3)
3
Algorithm 1 Recursive Multiplication
Naive_Recursive_Multiplication(x, y, n)
1. if n == 1
2. return x&y
3. t1 =Naive_Recursive_Multiplication xL, yL, n
2
4. t2 =Naive_Recursive_Multiplication xL, yR, n
2
5. t3 =Naive_Recursive_Multiplication xR, yL, n
2
6. t4 =Naive_Recursive_Multiplication xR, yR, n
2
7. return 2n
× t1 + 2
n
2 [t2 + t3] + t4
Thus, it could be possible to use the Gauss trick to decrease the number of
multiplications from four to three by realizing the following. Given the equation
of multiplication of imaginary numbers:
(a + ib) (c + id) = ac + (ad + bc) i − bd (4)
Thus, Gauss noticed that ad + bc =. Therefore,
(a + ib) (c + id) = ac + [(a + b) (c + d) − ac − bd] i − bd (5)
Then, if we use the Gauss’s trick, we only need xLyL, xRyR, (xL +xR)(yL +
yR) to calculate the multiplication because xLyR + xRyL = (xL + xR)(yL +
yR) − xLyL − xRyR. This allows to generate a new algorithm that only requires
to calculate three recursive multiplications. Thus, the time complexity of the
new matrix multiplication is:
T(n) = 3T(n/2) + Somework (6)
This equation can be proved to have an upper bound of cn1.59
. Therefore, it
is not only to use of divide, but also the clever use of that conquer and combine.
2 Using Recursion to Find Complexities
After this clear example on how to improve a basic algorithm, we turn our heads
to the merge sort algorithm (Algorithm 2). The merge sort algorithm exemplify
the classic way of using the recursion tree to obtain an initial guess for the time
complexity.
Definition 1. Given an input as a string where the problem is being encoded
using an alphabet Σ, the time complexity quantifies the amount of time taken
4
Algorithm 2 Merge Sort Algorithm
Merge-Sort(A,p,r)
1. if p < r then
2. q ← p+r
2
3. Merge-Sort(A,p,q)
4. Merge-Sort(A,q+1,r)
5. MERGE(A,p,q,r)
by an algorithm to run as a function on the length of such string. For this, look
at the recursion tree in Merge sort (Fig. 1). There, we can see how the data is
split in two parts in the following way
1. At the top we have n elements to be sorted
2. At the second level we split the data, using the recursion, into two sub-
problems of size n
2 and n
2 .
3. At the third level the data is split into subproblems of size n
4 .
4. And so on.
Thus, we can define the function to calculate the time complexity of steps using
a recursion defined in the following way (Eq. ).
T(n) = T n
2 + T n
2 + Somework.
Here, Somework can be seen as the merging that the MERGE needs to do
i.e. cn time complexity. Formally, we can define the recursion for the time
complexity as:
T (n) =
1 if n = 1
2T n
2 + cn if n > 1
(7)
5
Figure 1: The Recursion Tree Of Merge Sort when n is even
3 Asymptotic Notation
We are ready to define one of the main tools for the calculation of complexities,
the asymptotic notation. Asymptotic notation is a way to express the main
component of the cost of an algorithm by using idealized units of work. The
main families of asymptotic notation are the Big O, the Big Ω, the Θ, the little
o and the little ω.
First, let us to examine the famous big O.
Definition 2. For a given function g(n)
O(g(n)) = {f(n)| There exists c > 0 and n0 > 0
s.t. 0 ≤ f(n) ≤ cg(n) ∀n ≥ n0}
We have the following example for this notation.
Example. For example, we know that n ≤ n2
for n ≥ 1, thus if we select c = 1.
Then, we have that n ∈ O n2
or n = O n2
.
Next, we have the lower bound for the complexity functions, the Ω notation.
Definition 3. For a given function g(n)
Ω(g(n)) = {f(n)| There exists c > 0 and n0 > 0
s.t. 0 ≤ cg(n) ≤ f(n) ∀n ≥ n0}
6
Finally, we get a combination of the previous collections of functions the .
Definition 4. For a given function g(n)
Θ(g(n)) = {f(n)| There exists c1 > 0, c2 > 0 and n0 > 0
s.t. 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) ∀n ≥ n0}
3.1 Exercises
Please try to solve the following examples, i.e. find the c1, c2 and/or n0
1. n2
− 5n = Θ(n2
).
2.
√
n = O(n)
3. n2
= Ω (n)
3.2 Relations between Θ and O and Ω
The first relation is the transitivity.
Proposition 5. (Transitivity) Given f (n) and g (n), if f (n) = Θ (g (n)) and
g (n) = Θ (h (n))
It is easy to prove the proposition, you simply look at the constants provided
by the equalities. The remaining only requires a correct interpretation.
1. f (n) = Θ (f (n)) (Reflexivity).
2. f (n) = Θ (g (n)) ⇔ g (n) = Θ (f (n)) (Symmetry).
3. f (n) = O (g (n)) ⇔ g (n) = Ω (f (n))(Transpose Symmetry).
3.3 Some examples about little o and ω
The following examples clarify more the ideas about this “little” notation.
Example. For the little o, we have that 2n = o(n2
), but 2n2
= o(n2
). In the
case of the first part, it is easy to see that for any given c exist a n0 such that
1
no
2
< c. In addition, n > n0 implies that 1
n0
> 1
n . Then,
2 < cn ⇐⇒ 2n < cn2
(8)
This gives us the proof for the first part. In the second part, if we assume
c = 2 and a certain value n0 that makes true the inequality, we have that
2n2
0 < 2n2
0
which is clearly a contradiction.
A similar situation can be seen in little ω. For example n2
2 = ω(n), but
n2
2 = ω(n2
).
7
4 Solving Recurrences
4.1 Substitution Method
The main method is explained in the slides, but if you want more information
please take a look at Cormen’s book.
4.1.1 Subtleties of the Substitution Method
Guess that T(n) = O(n), then you can have something like
T(n) ≤c
n
2
+ c
n
2
+ 1
=cn + 1
=O(n)
Which is not the correct induction, after all cn+1 is not cn. We can overcome
this problem by assuming a d ≥ 0 and then “guessing” T(n) ≤ cn − d. Then
T(n) ≤ c
n
2
− d + c
n
2
− d + 1
=cn − 2d + 1
Then, if we select d ≥ 1 ⇒ 0 ≥ 1 − d. This means that cn − 2d + 1 ≤ cn − d.
Therefore, T(n) ≤ cn − d = O(n).
4.2 The Reduced Version of the Master Theorem
Theorem 1. Master Theorem. If T(n) = aT n
b + O(nd
) for some con-
stants a > 0, b > 1, and d ≥ 0 then
T(n) =



O(nd
) if d > logb a
O(nd
log n) if d = logb a
O(nlogb a
) if d < logb a
Proof. First, for convenience assume n = bp
. Now we can notice that the size
of the subproblems are decreasing by a factor of b at each recursive step. This
means that the size of each subproblems is n
bi at level i. Thus, in order to reach
the bottom you need to have subptoblems of size 1. Therefore:
n
bi
= 1 ⇒ i = logb n (9)
where i = height of the recursion three. Now, given that the branching
factor is a, we have at the kth
level ak
subproblems, each of size n
bk . Then, the
work at level k is:
8
DEPTH
Branching FactorSize
Size
Size
Size 1
Figure 2: The branching and depth of a recursion T(n) = aT n
b + n
ak
× O
n
bk
d
= O(nd
) ×
a
bd
k
(10)
Then, the total work done by the recursion is
T(n) = O(nd
) ×
a
bd
0
+ O(nd
) ×
a
bd
2
+ ... + O(nd
) ×
a
bd
logbn
(11)
For the next step we are going to use the following facts of the Θ notation.
For a g(m) = 1 + c + c2
+ ... + cm
, we have the following cases:
1. if c < 1 then g(m) = Θ(1)
2. if c = 1 then g(m) = Θ(m)
3. if c > 1 then g(m) = Θ(cm
)
Now, we can see the different cases:
1. If a
bd < 1, then we have that a < bd
or logb a < d (Case one of the
theorem). Then, T(n) = O(nd
).
2. If a
bd = 1, then we have that a = bd
or logb a = d (Case two of the
theorem). Then, we have that g(n) = a
bd
0
+ a
bd
2
+ ... + a
bd
logbn
is
Θ(logb n). Then, T(n) = O(nlogb a
logb n) = O nlogn a
log2 n because b
can only be greater or equal to two.
9
3. If a
bd > 1, then we have that a > bd
or logb a > d (Case three of the
theorem). Then. we have nd
× a
bd
logbn
= nd
× alogb n
(blogb n
)
d = alogb n
=
a(loga n)(logb a)
= nlogb a
. Thus T(n) = O(nlogb a
)
10
References
[1] S. Dasgupta, C. H. Papadimitriou, and U. V. Vazirani. Algorithms. May
2006.
[2] A. Karatsuba and Yu. Ofman. Multiplication of many-digital numbers by au-
tomatic computers. Proceedings of USSR Academy of Sciences, 145(7):293–
294, 1962.
[3] Virginia Vassilevska Williams. Multiplying matrices faster than
coppersmith-winograd. In Proceedings of the Forty-fourth Annual ACM
Symposium on Theory of Computing, STOC ’12, pages 887–898, New York,
NY, USA, 2012. ACM.
11

More Related Content

What's hot (19)

Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
 
Numerical Methods
Numerical MethodsNumerical Methods
Numerical Methods
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Comparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesComparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategies
 
NFSFIXES
NFSFIXESNFSFIXES
NFSFIXES
 
44 randomized-algorithms
44 randomized-algorithms44 randomized-algorithms
44 randomized-algorithms
 
The Complexity Of Primality Testing
The Complexity Of Primality TestingThe Complexity Of Primality Testing
The Complexity Of Primality Testing
 
Thesis
ThesisThesis
Thesis
 
Greedy Algorithms with examples' b-18298
Greedy Algorithms with examples'  b-18298Greedy Algorithms with examples'  b-18298
Greedy Algorithms with examples' b-18298
 
Ms nikita greedy agorithm
Ms nikita greedy agorithmMs nikita greedy agorithm
Ms nikita greedy agorithm
 
Probability Assignment Help
Probability Assignment HelpProbability Assignment Help
Probability Assignment Help
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Permutations and Combinations IIT JEE+Olympiad Lecture 1
Permutations and Combinations IIT JEE+Olympiad Lecture 1 Permutations and Combinations IIT JEE+Olympiad Lecture 1
Permutations and Combinations IIT JEE+Olympiad Lecture 1
 
Bab 4 dan bab 5 algebra and trigonometry
Bab 4 dan bab 5 algebra and trigonometryBab 4 dan bab 5 algebra and trigonometry
Bab 4 dan bab 5 algebra and trigonometry
 
Q
QQ
Q
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Unit 2
Unit 2Unit 2
Unit 2
 
test pre
test pretest pre
test pre
 
Machnical Engineering Assignment Help
Machnical Engineering Assignment HelpMachnical Engineering Assignment Help
Machnical Engineering Assignment Help
 

Viewers also liked

Recurrence relationclass 5
Recurrence relationclass 5Recurrence relationclass 5
Recurrence relationclass 5Kumar
 
01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysis01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysisOnkar Nath Sharma
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123Ankita Goyal
 
Customer Anaytics at Swiss TUG 2009
Customer Anaytics at Swiss TUG 2009Customer Anaytics at Swiss TUG 2009
Customer Anaytics at Swiss TUG 2009Patrick Deglon
 
Comments from Consulting Clients
Comments from Consulting ClientsComments from Consulting Clients
Comments from Consulting ClientsLeslie Belay
 
PR 2.0 - PR & Social Media
PR 2.0 - PR & Social MediaPR 2.0 - PR & Social Media
PR 2.0 - PR & Social MediaLalit Agrawal
 
law360-5-comp-considerations-2013
law360-5-comp-considerations-2013law360-5-comp-considerations-2013
law360-5-comp-considerations-2013Carol Botros Samaan
 
Sujets anglais bac_a2_2013_old1
Sujets anglais bac_a2_2013_old1Sujets anglais bac_a2_2013_old1
Sujets anglais bac_a2_2013_old1blessedkkr
 
Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2Traian Rebedea
 
Radix 4 FFT algorithm and it time complexity computation
Radix 4 FFT algorithm and it time complexity computationRadix 4 FFT algorithm and it time complexity computation
Radix 4 FFT algorithm and it time complexity computationRaj Jaiswal
 
Geography presentation
Geography presentationGeography presentation
Geography presentationewalk1920
 
Karmarkar's Algorithm For Linear Programming Problem
Karmarkar's Algorithm For Linear Programming ProblemKarmarkar's Algorithm For Linear Programming Problem
Karmarkar's Algorithm For Linear Programming ProblemAjay Dhamija
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsAmrinder Arora
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 

Viewers also liked (20)

Recurrence relationclass 5
Recurrence relationclass 5Recurrence relationclass 5
Recurrence relationclass 5
 
Códigos
CódigosCódigos
Códigos
 
Big o notation
Big o notationBig o notation
Big o notation
 
01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysis01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysis
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
 
Customer Anaytics at Swiss TUG 2009
Customer Anaytics at Swiss TUG 2009Customer Anaytics at Swiss TUG 2009
Customer Anaytics at Swiss TUG 2009
 
Електромобільні FAQ
Електромобільні FAQ Електромобільні FAQ
Електромобільні FAQ
 
Comments from Consulting Clients
Comments from Consulting ClientsComments from Consulting Clients
Comments from Consulting Clients
 
PR 2.0 - PR & Social Media
PR 2.0 - PR & Social MediaPR 2.0 - PR & Social Media
PR 2.0 - PR & Social Media
 
law360-5-comp-considerations-2013
law360-5-comp-considerations-2013law360-5-comp-considerations-2013
law360-5-comp-considerations-2013
 
Sujets anglais bac_a2_2013_old1
Sujets anglais bac_a2_2013_old1Sujets anglais bac_a2_2013_old1
Sujets anglais bac_a2_2013_old1
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
 
Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2Algorithm Design and Complexity - Course 1&2
Algorithm Design and Complexity - Course 1&2
 
Radix 4 FFT algorithm and it time complexity computation
Radix 4 FFT algorithm and it time complexity computationRadix 4 FFT algorithm and it time complexity computation
Radix 4 FFT algorithm and it time complexity computation
 
Geography presentation
Geography presentationGeography presentation
Geography presentation
 
Karmarkar's Algorithm For Linear Programming Problem
Karmarkar's Algorithm For Linear Programming ProblemKarmarkar's Algorithm For Linear Programming Problem
Karmarkar's Algorithm For Linear Programming Problem
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 

Similar to 02 Notes Divide and Conquer

T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxGadaFarhan
 
SURF 2012 Final Report(1)
SURF 2012 Final Report(1)SURF 2012 Final Report(1)
SURF 2012 Final Report(1)Eric Zhang
 
journal of mathematics research
journal of mathematics researchjournal of mathematics research
journal of mathematics researchrikaseorika
 
research paper publication journals
research paper publication journalsresearch paper publication journals
research paper publication journalsrikaseorika
 
Lecture 3 complexity
Lecture 3 complexityLecture 3 complexity
Lecture 3 complexityMadhu Niket
 
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDEDFACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDEDZac Darcy
 
Conjugate Gradient Methods
Conjugate Gradient MethodsConjugate Gradient Methods
Conjugate Gradient MethodsMTiti1
 
lecture 1
lecture 1lecture 1
lecture 1sajinsc
 
Find the compact trigonometric Fourier series for the periodic signal.pdf
Find the compact trigonometric Fourier series for the periodic signal.pdfFind the compact trigonometric Fourier series for the periodic signal.pdf
Find the compact trigonometric Fourier series for the periodic signal.pdfarihantelectronics
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquerchidabdu
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosluzenith_g
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsNagendraK18
 

Similar to 02 Notes Divide and Conquer (20)

Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
SAS Homework Help
SAS Homework HelpSAS Homework Help
SAS Homework Help
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
 
SURF 2012 Final Report(1)
SURF 2012 Final Report(1)SURF 2012 Final Report(1)
SURF 2012 Final Report(1)
 
published research papers
published research paperspublished research papers
published research papers
 
journal of mathematics research
journal of mathematics researchjournal of mathematics research
journal of mathematics research
 
research paper publication journals
research paper publication journalsresearch paper publication journals
research paper publication journals
 
Lecture 3 complexity
Lecture 3 complexityLecture 3 complexity
Lecture 3 complexity
 
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDEDFACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
FACTORING CRYPTOSYSTEM MODULI WHEN THE CO-FACTORS DIFFERENCE IS BOUNDED
 
Cis435 week02
Cis435 week02Cis435 week02
Cis435 week02
 
3.pdf
3.pdf3.pdf
3.pdf
 
Conjugate Gradient Methods
Conjugate Gradient MethodsConjugate Gradient Methods
Conjugate Gradient Methods
 
lecture 1
lecture 1lecture 1
lecture 1
 
Alg1
Alg1Alg1
Alg1
 
Find the compact trigonometric Fourier series for the periodic signal.pdf
Find the compact trigonometric Fourier series for the periodic signal.pdfFind the compact trigonometric Fourier series for the periodic signal.pdf
Find the compact trigonometric Fourier series for the periodic signal.pdf
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquer
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmos
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 

More from Andres Mendez-Vazquez

01.04 orthonormal basis_eigen_vectors
01.04 orthonormal basis_eigen_vectors01.04 orthonormal basis_eigen_vectors
01.04 orthonormal basis_eigen_vectorsAndres Mendez-Vazquez
 
01.03 squared matrices_and_other_issues
01.03 squared matrices_and_other_issues01.03 squared matrices_and_other_issues
01.03 squared matrices_and_other_issuesAndres Mendez-Vazquez
 
05 backpropagation automatic_differentiation
05 backpropagation automatic_differentiation05 backpropagation automatic_differentiation
05 backpropagation automatic_differentiationAndres Mendez-Vazquez
 
01 Introduction to Neural Networks and Deep Learning
01 Introduction to Neural Networks and Deep Learning01 Introduction to Neural Networks and Deep Learning
01 Introduction to Neural Networks and Deep LearningAndres Mendez-Vazquez
 
25 introduction reinforcement_learning
25 introduction reinforcement_learning25 introduction reinforcement_learning
25 introduction reinforcement_learningAndres Mendez-Vazquez
 
Neural Networks and Deep Learning Syllabus
Neural Networks and Deep Learning SyllabusNeural Networks and Deep Learning Syllabus
Neural Networks and Deep Learning SyllabusAndres Mendez-Vazquez
 
Introduction to artificial_intelligence_syllabus
Introduction to artificial_intelligence_syllabusIntroduction to artificial_intelligence_syllabus
Introduction to artificial_intelligence_syllabusAndres Mendez-Vazquez
 
Ideas about a Bachelor in Machine Learning/Data Sciences
Ideas about a Bachelor in Machine Learning/Data SciencesIdeas about a Bachelor in Machine Learning/Data Sciences
Ideas about a Bachelor in Machine Learning/Data SciencesAndres Mendez-Vazquez
 
20 k-means, k-center, k-meoids and variations
20 k-means, k-center, k-meoids and variations20 k-means, k-center, k-meoids and variations
20 k-means, k-center, k-meoids and variationsAndres Mendez-Vazquez
 

More from Andres Mendez-Vazquez (20)

2.03 bayesian estimation
2.03 bayesian estimation2.03 bayesian estimation
2.03 bayesian estimation
 
05 linear transformations
05 linear transformations05 linear transformations
05 linear transformations
 
01.04 orthonormal basis_eigen_vectors
01.04 orthonormal basis_eigen_vectors01.04 orthonormal basis_eigen_vectors
01.04 orthonormal basis_eigen_vectors
 
01.03 squared matrices_and_other_issues
01.03 squared matrices_and_other_issues01.03 squared matrices_and_other_issues
01.03 squared matrices_and_other_issues
 
01.02 linear equations
01.02 linear equations01.02 linear equations
01.02 linear equations
 
01.01 vector spaces
01.01 vector spaces01.01 vector spaces
01.01 vector spaces
 
06 recurrent neural_networks
06 recurrent neural_networks06 recurrent neural_networks
06 recurrent neural_networks
 
05 backpropagation automatic_differentiation
05 backpropagation automatic_differentiation05 backpropagation automatic_differentiation
05 backpropagation automatic_differentiation
 
Zetta global
Zetta globalZetta global
Zetta global
 
01 Introduction to Neural Networks and Deep Learning
01 Introduction to Neural Networks and Deep Learning01 Introduction to Neural Networks and Deep Learning
01 Introduction to Neural Networks and Deep Learning
 
25 introduction reinforcement_learning
25 introduction reinforcement_learning25 introduction reinforcement_learning
25 introduction reinforcement_learning
 
Neural Networks and Deep Learning Syllabus
Neural Networks and Deep Learning SyllabusNeural Networks and Deep Learning Syllabus
Neural Networks and Deep Learning Syllabus
 
Introduction to artificial_intelligence_syllabus
Introduction to artificial_intelligence_syllabusIntroduction to artificial_intelligence_syllabus
Introduction to artificial_intelligence_syllabus
 
Ideas 09 22_2018
Ideas 09 22_2018Ideas 09 22_2018
Ideas 09 22_2018
 
Ideas about a Bachelor in Machine Learning/Data Sciences
Ideas about a Bachelor in Machine Learning/Data SciencesIdeas about a Bachelor in Machine Learning/Data Sciences
Ideas about a Bachelor in Machine Learning/Data Sciences
 
Analysis of Algorithms Syllabus
Analysis of Algorithms  SyllabusAnalysis of Algorithms  Syllabus
Analysis of Algorithms Syllabus
 
20 k-means, k-center, k-meoids and variations
20 k-means, k-center, k-meoids and variations20 k-means, k-center, k-meoids and variations
20 k-means, k-center, k-meoids and variations
 
18.1 combining models
18.1 combining models18.1 combining models
18.1 combining models
 
17 vapnik chervonenkis dimension
17 vapnik chervonenkis dimension17 vapnik chervonenkis dimension
17 vapnik chervonenkis dimension
 
A basic introduction to learning
A basic introduction to learningA basic introduction to learning
A basic introduction to learning
 

Recently uploaded

Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptbibisarnayak0
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Erbil Polytechnic University
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentBharaniDharan195623
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in projectDM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in projectssuserb6619e
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 

Recently uploaded (20)

Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.ppt
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managament
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in projectDM Pillar Training Manual.ppt will be useful in deploying TPM in project
DM Pillar Training Manual.ppt will be useful in deploying TPM in project
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 

02 Notes Divide and Conquer

  • 1. Divide and Conquer Andres Mendez-Vazquez August 26, 2015 Contents 1 Improving Algorithms 2 1.1 Using Multiplication of Imaginary Numbers . . . . . . . . . . . . 2 2 Using Recursion to Find Complexities 4 3 Asymptotic Notation 6 3.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 Relations between Θ and O and Ω . . . . . . . . . . . . . . . . . 7 3.3 Some examples about little o and ω . . . . . . . . . . . . . . . . 7 4 Solving Recurrences 8 4.1 Substitution Method . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.1.1 Subtleties of the Substitution Method . . . . . . . . . . . 8 4.2 The Reduced Version of the Master Theorem . . . . . . . . . . . 8 1
  • 2. 1 Improving Algorithms Although, we saw already a simple way of reducing the complexity of an al- gorithm by avoiding as much as possible the recursion by memorizing previous smaller values (Iterative Fibonacci). It is clear that neater tricks must exist in the realm of possible solutions while solving problems for algorithms. Thus, looking a those tricks is quite important to be able to learn how to improve on many different algorithms. A clever strategy for improving algorithms is the well known Divide and Conquer which consists of the following steps: 1. Divide. Here the algorithm must split the large problem into smaller version, thus they can be solved recursively by using new algorithm in- stantiation and the smaller inputs. 2. Conquer. At this moment, we use the idea of induction by going first backwards to the basis case where the easiest solution can be find, then the procedure is ready to go forward. 3. Combine. Here, we use the previously calculated answers to build the an answer for each subproblem. For example in the case of Fibonacci: Fn = Fn−1 + Fn−2 (1) Then, it is essential to build clever algorithms that can build efficient answers for given problems. Thus, the importance of looking at several possible tricks to be able to obtain a basic intuitions for them!!! In order to avoid exponential number of steps while calculating the answer. The next example of a clever trick that we will be studying is coming from the Prince of Mathematics, Frederich Carl Gauss (1777-1855) [1]. This improvement was developed by Anatoly Alexeevitch Karatsuba (1937 - 2008) at the Faculty of Mechanics and Mathematics of Moscow State University [2]. 1.1 Using Multiplication of Imaginary Numbers Even when we could have a efficient strategy to do the divide and conquer, the most difficult part is always the combine one because the need of not only doing simple combinations of subproblems, but clever ones. For example, given that the numbers could be represented as x = xL ◦ xR = 2n/2 xL + xR by assuming that n (Size of each of string of bits) is even. As an example of this, x = 10110110 can be seen as the left bits concatenated to right bits: xL = 1011 and xR = 0110. Then, x = 1011 × 24 + 0110. Thus, the multiplication between two numbers, x and y, can be found using the following equation: 2
  • 3. xy = 2n/2 xL + xR 2n/2 yL + yR =2n xLyL + 2n/2 (xLyR + xRyL) + xRyR Making possible to use the recursion to obtain the final multiplication be- tween both numbers (Algorithm 1). This algorithm has the following total time: T (n) = 4T n 2 + Somework. (2) Where Somework correspond to the addition of the results obtained by calling the function in the left and right sections of both numbers. Although at the beginning, the recursive function looks quite complex, it is actually one the easiest to solve by means of the recursive three to guess the complexity. In addition, once you equipped with the three main methods of basic complexity calculation: • The Recursion-Tree Method. • The Substitution Method. • The Master Theorem Method. Using these methods, it is possible to see that this recursive function is bounded by cn2 time for some constant c. An immediate question for anybody trying to improve this naive algorithm is the following one: Can be possible to have an algorithm able to perform the multiplication in shorter time? The answer is actually more convoluted than one can imagine. First, for many problems is possible to obtain absolute lower bounds that have not been reached by any actual algorithms used to solve them. An example of this situation is the algorithms used for matrix multiplication [3]. Therefore, from the philosophical point of view of algorithms, we at algorithms, first develop an initial solution and later on, we try to develop a faster solution. Thus, What will allow us to improve the naive multiplication? While looking through the history of mathematics (It is always a good starting point for any developer of algorithms) Karatsuba [2] noticed that it is possible to have the following representation of imaginary numbers in a computer: 100100100101 010101110110 Bits for imaginary Bits for real He was able to see that imaginary numbers could be seen as binary numbers with n 2 + n 2 bits. Thus, binary number can be seen as imaginary number where x = 2 n 2 × xL Imaginary + xR Real (3) 3
  • 4. Algorithm 1 Recursive Multiplication Naive_Recursive_Multiplication(x, y, n) 1. if n == 1 2. return x&y 3. t1 =Naive_Recursive_Multiplication xL, yL, n 2 4. t2 =Naive_Recursive_Multiplication xL, yR, n 2 5. t3 =Naive_Recursive_Multiplication xR, yL, n 2 6. t4 =Naive_Recursive_Multiplication xR, yR, n 2 7. return 2n × t1 + 2 n 2 [t2 + t3] + t4 Thus, it could be possible to use the Gauss trick to decrease the number of multiplications from four to three by realizing the following. Given the equation of multiplication of imaginary numbers: (a + ib) (c + id) = ac + (ad + bc) i − bd (4) Thus, Gauss noticed that ad + bc =. Therefore, (a + ib) (c + id) = ac + [(a + b) (c + d) − ac − bd] i − bd (5) Then, if we use the Gauss’s trick, we only need xLyL, xRyR, (xL +xR)(yL + yR) to calculate the multiplication because xLyR + xRyL = (xL + xR)(yL + yR) − xLyL − xRyR. This allows to generate a new algorithm that only requires to calculate three recursive multiplications. Thus, the time complexity of the new matrix multiplication is: T(n) = 3T(n/2) + Somework (6) This equation can be proved to have an upper bound of cn1.59 . Therefore, it is not only to use of divide, but also the clever use of that conquer and combine. 2 Using Recursion to Find Complexities After this clear example on how to improve a basic algorithm, we turn our heads to the merge sort algorithm (Algorithm 2). The merge sort algorithm exemplify the classic way of using the recursion tree to obtain an initial guess for the time complexity. Definition 1. Given an input as a string where the problem is being encoded using an alphabet Σ, the time complexity quantifies the amount of time taken 4
  • 5. Algorithm 2 Merge Sort Algorithm Merge-Sort(A,p,r) 1. if p < r then 2. q ← p+r 2 3. Merge-Sort(A,p,q) 4. Merge-Sort(A,q+1,r) 5. MERGE(A,p,q,r) by an algorithm to run as a function on the length of such string. For this, look at the recursion tree in Merge sort (Fig. 1). There, we can see how the data is split in two parts in the following way 1. At the top we have n elements to be sorted 2. At the second level we split the data, using the recursion, into two sub- problems of size n 2 and n 2 . 3. At the third level the data is split into subproblems of size n 4 . 4. And so on. Thus, we can define the function to calculate the time complexity of steps using a recursion defined in the following way (Eq. ). T(n) = T n 2 + T n 2 + Somework. Here, Somework can be seen as the merging that the MERGE needs to do i.e. cn time complexity. Formally, we can define the recursion for the time complexity as: T (n) = 1 if n = 1 2T n 2 + cn if n > 1 (7) 5
  • 6. Figure 1: The Recursion Tree Of Merge Sort when n is even 3 Asymptotic Notation We are ready to define one of the main tools for the calculation of complexities, the asymptotic notation. Asymptotic notation is a way to express the main component of the cost of an algorithm by using idealized units of work. The main families of asymptotic notation are the Big O, the Big Ω, the Θ, the little o and the little ω. First, let us to examine the famous big O. Definition 2. For a given function g(n) O(g(n)) = {f(n)| There exists c > 0 and n0 > 0 s.t. 0 ≤ f(n) ≤ cg(n) ∀n ≥ n0} We have the following example for this notation. Example. For example, we know that n ≤ n2 for n ≥ 1, thus if we select c = 1. Then, we have that n ∈ O n2 or n = O n2 . Next, we have the lower bound for the complexity functions, the Ω notation. Definition 3. For a given function g(n) Ω(g(n)) = {f(n)| There exists c > 0 and n0 > 0 s.t. 0 ≤ cg(n) ≤ f(n) ∀n ≥ n0} 6
  • 7. Finally, we get a combination of the previous collections of functions the . Definition 4. For a given function g(n) Θ(g(n)) = {f(n)| There exists c1 > 0, c2 > 0 and n0 > 0 s.t. 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) ∀n ≥ n0} 3.1 Exercises Please try to solve the following examples, i.e. find the c1, c2 and/or n0 1. n2 − 5n = Θ(n2 ). 2. √ n = O(n) 3. n2 = Ω (n) 3.2 Relations between Θ and O and Ω The first relation is the transitivity. Proposition 5. (Transitivity) Given f (n) and g (n), if f (n) = Θ (g (n)) and g (n) = Θ (h (n)) It is easy to prove the proposition, you simply look at the constants provided by the equalities. The remaining only requires a correct interpretation. 1. f (n) = Θ (f (n)) (Reflexivity). 2. f (n) = Θ (g (n)) ⇔ g (n) = Θ (f (n)) (Symmetry). 3. f (n) = O (g (n)) ⇔ g (n) = Ω (f (n))(Transpose Symmetry). 3.3 Some examples about little o and ω The following examples clarify more the ideas about this “little” notation. Example. For the little o, we have that 2n = o(n2 ), but 2n2 = o(n2 ). In the case of the first part, it is easy to see that for any given c exist a n0 such that 1 no 2 < c. In addition, n > n0 implies that 1 n0 > 1 n . Then, 2 < cn ⇐⇒ 2n < cn2 (8) This gives us the proof for the first part. In the second part, if we assume c = 2 and a certain value n0 that makes true the inequality, we have that 2n2 0 < 2n2 0 which is clearly a contradiction. A similar situation can be seen in little ω. For example n2 2 = ω(n), but n2 2 = ω(n2 ). 7
  • 8. 4 Solving Recurrences 4.1 Substitution Method The main method is explained in the slides, but if you want more information please take a look at Cormen’s book. 4.1.1 Subtleties of the Substitution Method Guess that T(n) = O(n), then you can have something like T(n) ≤c n 2 + c n 2 + 1 =cn + 1 =O(n) Which is not the correct induction, after all cn+1 is not cn. We can overcome this problem by assuming a d ≥ 0 and then “guessing” T(n) ≤ cn − d. Then T(n) ≤ c n 2 − d + c n 2 − d + 1 =cn − 2d + 1 Then, if we select d ≥ 1 ⇒ 0 ≥ 1 − d. This means that cn − 2d + 1 ≤ cn − d. Therefore, T(n) ≤ cn − d = O(n). 4.2 The Reduced Version of the Master Theorem Theorem 1. Master Theorem. If T(n) = aT n b + O(nd ) for some con- stants a > 0, b > 1, and d ≥ 0 then T(n) =    O(nd ) if d > logb a O(nd log n) if d = logb a O(nlogb a ) if d < logb a Proof. First, for convenience assume n = bp . Now we can notice that the size of the subproblems are decreasing by a factor of b at each recursive step. This means that the size of each subproblems is n bi at level i. Thus, in order to reach the bottom you need to have subptoblems of size 1. Therefore: n bi = 1 ⇒ i = logb n (9) where i = height of the recursion three. Now, given that the branching factor is a, we have at the kth level ak subproblems, each of size n bk . Then, the work at level k is: 8
  • 9. DEPTH Branching FactorSize Size Size Size 1 Figure 2: The branching and depth of a recursion T(n) = aT n b + n ak × O n bk d = O(nd ) × a bd k (10) Then, the total work done by the recursion is T(n) = O(nd ) × a bd 0 + O(nd ) × a bd 2 + ... + O(nd ) × a bd logbn (11) For the next step we are going to use the following facts of the Θ notation. For a g(m) = 1 + c + c2 + ... + cm , we have the following cases: 1. if c < 1 then g(m) = Θ(1) 2. if c = 1 then g(m) = Θ(m) 3. if c > 1 then g(m) = Θ(cm ) Now, we can see the different cases: 1. If a bd < 1, then we have that a < bd or logb a < d (Case one of the theorem). Then, T(n) = O(nd ). 2. If a bd = 1, then we have that a = bd or logb a = d (Case two of the theorem). Then, we have that g(n) = a bd 0 + a bd 2 + ... + a bd logbn is Θ(logb n). Then, T(n) = O(nlogb a logb n) = O nlogn a log2 n because b can only be greater or equal to two. 9
  • 10. 3. If a bd > 1, then we have that a > bd or logb a > d (Case three of the theorem). Then. we have nd × a bd logbn = nd × alogb n (blogb n ) d = alogb n = a(loga n)(logb a) = nlogb a . Thus T(n) = O(nlogb a ) 10
  • 11. References [1] S. Dasgupta, C. H. Papadimitriou, and U. V. Vazirani. Algorithms. May 2006. [2] A. Karatsuba and Yu. Ofman. Multiplication of many-digital numbers by au- tomatic computers. Proceedings of USSR Academy of Sciences, 145(7):293– 294, 1962. [3] Virginia Vassilevska Williams. Multiplying matrices faster than coppersmith-winograd. In Proceedings of the Forty-fourth Annual ACM Symposium on Theory of Computing, STOC ’12, pages 887–898, New York, NY, USA, 2012. ACM. 11