SlideShare a Scribd company logo
Design and
Analysis of
Algorithms
DIVIDE AND CONQUER
PART I
GENERAL TEMPLATE
BINARY SEARCH
MERGE SORT & QUICK SORT
SOLVING RECURRENCE RELATIONS
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well

 Available for study sessions
Science and Engineering Hall
GWU
Algorithms Divide and Conquer - Part I 2
LOGISTICS
Algorithms
Analysis
Asymptotic
NP-
Completeness
Design
D&C
DP
Greedy
Graph
B&B
Applications
Algorithms Divide and Conquer - Part I 3
WHERE WE ARE
 A technique to solve complex problems by breaking into
smaller instances of the problem and combining the results
 Recursive methodology – Smaller instances of the same type of
problem
 Typically used accompaniments
 Induction for proving correctness
 Recurrence relation solving for computing time (and/or space)
complexity
Algorithms Divide and Conquer - Part I 4
DIVIDE AND CONQUER
By definition: For D&C, sub
problems must be of same
type.
[The phrase “D&C” is also used
in other contexts. It may refer
to breaking down a task, but in
Computer Science, D&C is a
formal paradigm]
Algorithms Divide and Conquer - Part I 5
D&C – CS, NOT MANAGEMENT/POLITICS
 A recursive algorithm is an algorithm that calls itself on
smaller input.
 Algorithm sort (Array a)
Begin
sort (subarray consisting of first half of a)
sort (subarray consisting of second half of a)
do_something_else();
End
Algorithms Divide and Conquer - Part I 6
RECURSION
 Recurrence Relation is a recursive formula, commonly used to
analyze the time complexity of recursive algorithms
 For example
 T(n) = T(n/2) + T(n/2) + n2
 T(n) = a T(n/b) + f(n)
 Note: Recurrence Relations have uses outside of time
complexity analysis as well (for example in combinatorics),
but for the purpose of this lecture, this is the main use case.
Algorithms Divide and Conquer - Part I 7
RECURRENCE RELATIONS
 Wikipedia says: “…it is often necessary to replace the original
problem by a more general or complicated problem in order to
get the recursion going, and there is no systematic method for
finding the proper generalization.”
 Refer to this as the “generalization” step
 Sometimes counterintuitive that making a “generalization”, that is,
making the problem harder actually helps in solving it!
Algorithms Divide and Conquer - Part I 8
HOW TO D&C
divide_conquer(input J)
{
// Base Case
if (size of input is small enough) {
solve directly and return
}
// Divide Step
divide J into two or more parts J1, J2,...
// Recursive Calls
call divide_conquer(J1) to get a subsolution S1
call divide_conquer(J2) to get a subsolution S2
...
// Merge Step
Merge the subsolutions S1, S2,...into a global solution S
return S
}
Algorithms Divide and Conquer - Part I 9
GENERAL TEMPLATE
 Number of subproblems that you create in the “divide” step
 This plays a role in the recurrence relation that is created for
analysis
 T(n) = a T(n/b) + f(n)
Here “a” branches, each with size “n/b”, and f(n) time spent in
dividing and merging
 Example: T(n) = T(n/2) + 1
1 branch, size half and constant time spent in dividing and merging
Algorithms Divide and Conquer - Part I 10
NUMBER OF BRANCHES
divide_conquer(input J)
{
// Base Case
if (size of input is small enough) {
solve directly and return
}
// Divide Step
divide J into two or more parts J1, J2,...
// Recursive Calls
call divide_conquer(J1) to get a subsolution S1
call divide_conquer(J2) to get a subsolution S2
...
// Merge Step
Merge the subsolutions S1, S2,...into a global solution S
return S
}
Algorithms Divide and Conquer - Part I 11
GENERAL TEMPLATE – TIME COMPLEXITY
VIEW
Combined time
in steps other
than recursive
calls: f(n)
a recursive calls of size
n/b each. Total time:
a T(n/b)
 Binary Search
 Merge Sort
 Quick Sort
Algorithms Divide and Conquer - Part I 12
D&C – EXAMPLE ALGORITHMS
 Search (A, low, high, key)
 Mid = (low + high) / 2
 Compare A[mid] to key, and look either in left half or in right half
 T(n) = T(n/2) + 1
 T(n) = O(log n)
Algorithms Divide and Conquer - Part I 13
BINARY SEARCH
 Classic problem: Given an array, to sort it
 Generalization step: Given an array and indexes i and j (start and end)
to sort that portion of it
 Algorithm MergeSort (input: A,i,j) {
// Divide portion
if (j – i < THRESHOLD) {
InsertionSort(A,i,j)
Return
}
int k=(i+j)/2
// Recursive Calls
MergeSort(A,i,k)
MergeSort(A,k+1,j)
// Merge Calls
Merge(A,i,k,k+1,j)
}
Algorithms Divide and Conquer - Part I 14
MERGE SORT
 How to merge two lists effectively?
Algorithms Divide and Conquer - Part I 15
MERGING
 T(n) = 2T(n/2) + (n)
 Need some methods for solving such recurrence equations
 Substitution method
 Recursion tree method (unfolding)
 Master theorem
 T(n) = (n log n)
Algorithms Divide and Conquer - Part I 16
TIME COMPLEXITY OF MERGE SORT
Algorithms Divide and Conquer - Part I 17
EXAMPLES OF RECURRENCE RELATIONS
 Examples:
 T(n) = 2 T(n/2) + cn
T(n) = O (n log n)
 T(n) = T(n/2) + n
T(n) = O (n)
 3 General Approaches:
 Substitution method (Guess and Prove)
 Recursion tree method (unfold and reach a pattern)
 Master theorem
Algorithms Divide and Conquer - Part I 18
SOLVING RECURRENCE RELATIONS
 Given T(n) = 2 T(n/2) + cn
 We first “guess” that the solution is O(n log n)
 To prove this using induction, we first assume T(m) <= km log
m for all m < n
 Then T(n) = 2 T(n/2) + cn
<= 2 kn/2 log (n/2) + cn
= kn log n – (k – c)n // log (n/2) = log n – 1
<= k n log n, as long as k >= c
Algorithms Divide and Conquer - Part I 19
SUBSTITUTION METHOD FOR MERGE SORT
Algorithms Divide and Conquer - Part I 20
MASTER THEOREM FOR SOLVING
RECURRENCE RELATIONS
Only applies to Recurrence Relations of following type
T(n) = aT(n/b) + f(n)
 Case 1. If f(n) = O(nc) where c < logb a, then T(n) = θ(n^logb a)
 Case 2. If it is true, for some constant k ≥ 0, that f(n) = θ(nc
logk n) where c = logb a, then T(n) = θ(nc logk+1 n)
 Case 3. If it is true that f(n) = Ω(nc) where c > logb a, then T(n)
= θ(f(n))
T(n) = a T(n/b) + f(n)
If we unfold this, we get an expression like:
T(n) = ak T(n/bk) + f(n) + a f(n/b) + … + ak f(n/bk)
Then, for k ≈ logbn, T(n/bk) will be a small constant, and we can
assume T(n/bk) = 1.
Then, T(n) = a^(logbn) + f(n) + af(n/b) + … + ak f(n/bk)
= n^(logba) + f(n) + af(n/b) + … + ak f(n/bk)
We note that there are about logbn terms.
Algorithms Divide and Conquer - Part I 21
MASTER THEOREM – INTUITION
Intuition != Formal Proof
T(n) = n^(logba) + f(n) + af(n/b) + … + ak f(n/bk)
We observe that:
• If f(n) is very small, say a constant, then the first term dominates
• If f(n) =  (n^(logba)), then the T(n) = f(n) log n.
// The log n factor arises because there are ~ log n terms
• If f(n) is too large, then f(n) terms dominate
Algorithms Divide and Conquer - Part I 22
MASTER THEOREM – INTUITION (CONT.)
T(n) = 2 T(n/2) + c n
In this case:
• a = b = 2
• f(n) = c n
• logba = 1
• n^(logba) = n
So, f(n) =  (n^(logba))
Therefore, by Master Theorem,
T(n) = (f(n) log n)
That is, T(n) = (n log n)
Algorithms Divide and Conquer - Part I 23
APPLYING MASTER THEOREM TO MERGE
SORT RECURRENCE
 Select a “partition” element
 Partition the array into “left” and “right” portions (not
necessarily equal) based on the partition element
 Sort the left and right sides
 An inverted view of mergesort – spend time upfront
(partition), no need to merge later.
Algorithms Divide and Conquer - Part I 24
QUICKSORT
 quicksort(A,p,r)
if (p < r) {
q = partition (A,p,r)
quicksort(A,p,q-1)
quicksort(A,q+1,r)
}
Algorithms Divide and Conquer - Part I 25
QUICKSORT – THE PSEUDO CODE
 Invented in 1960 by C. A. R. Hoare
 More widely used than any other sort
 A well-studied, not difficult to implement algorithm
 R. Sedgewick – 1975 Ph.D. thesis at Stanford Univ. –
Analysis and Variations of QuickSort
Algorithms Divide and Conquer - Part I 26
QUICKSORT (THE TRIVIA CLUB VIEW)
Who said: “Elementary, My Dear Watson”?
 “There are two ways of constructing a software design: One
way is to make it so simple that there are obviously no
deficiencies, and the other way is to make it so complicated
that there are no obvious deficiencies. The first method is far
more difficult.”
 “We should forget about small efficiencies, say about 97% of
the time: premature optimization is the root of all evil.”
Algorithms Divide and Conquer - Part I 27
QUOTES, QUOTES
 How to find a good partition element
 How to partition (efficiently)
 Partition array so that:
 Some partitioning element (q) is its final position
 Every element smaller than q is to the left of q
 Every element larger than q is to the right of q
 Sedgwick states that “improving QuickSort is the better
mousetrap of computer science”
Algorithms Divide and Conquer - Part I 28
CENTRAL PROBLEM IN QUICKSORT
 T(n) = T(n1) + T(n2) + O(n)
Where n1 + n2 = n – 1
 So it all depends upon the kind of the split, and split will
likely not be the same each time.
 Worst case – very bad split: O(n2)
 Best case – good split: O(n log n)
 Average case – where does that fit?
http://mathworld.wolfram.com/Quicksort.html
Algorithms Divide and Conquer - Part I 29
QUICKSORT – TIME COMPLEXITY ANALYSIS
How long will the algorithm take?
Function sum (integer a) {
if (a == 1) exit;
if (a is odd) {
a = 3a + 1
} else {
a = a/2
}
}
Trichotomy – Extended
Given two functions f(n) and g(n), both strictly increasing with n,
is it possible that f(n) and g(n) cannot be compared
asymptotically?
Algorithms Divide and Conquer - Part I 30
OPEN QUESTIONS
1. Median Finding
(Textbook § 4.6)
2. Closest pair of
points algorithm
(Textbook § 4.7)
3. Strassen’s
algorithm for
matrix
multiplication
(Textbook § 4.8)
https://youtu.be/1AIvlizGo7Y
Algorithms Divide and Conquer - Part I 31
READING ASSIGNMENTS
We already have quite a few people who know how
to divide. So essentially we are now looking for
people who know how to conquer.
Algorithms
Analysis
Asymptotic
NP-
Completeness
Design
D&C
DP
Greedy
Graph
B&B
Applications
Algorithms Divide and Conquer - Part I 32
WHERE WE ARE
More D&C
in Next
Lecture
Ad

More Related Content

What's hot (20)

Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
Dr Shashikant Athawale
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Dr Shashikant Athawale
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
Mohammed Hussein
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
Amrinder Arora
 
Data Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and ConquerData Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and Conquer
Laguna State Polytechnic University
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And Conquer
UrviBhalani2
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
Sajid Marwat
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
Krish_ver2
 
Merge Sort
Merge SortMerge Sort
Merge Sort
Nikhil Sonkamble
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
Rajendra Dangwal
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
sandeep54552
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
Amrinder Arora
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And Conquer
UrviBhalani2
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
Sajid Marwat
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
Krish_ver2
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 

Viewers also liked (20)

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
Amrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
Amrinder Arora
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
Amrinder Arora
 
NP completeness
NP completenessNP completeness
NP completeness
Amrinder Arora
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
Amrinder Arora
 
NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
Amrinder Arora
 
Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1
Kumar
 
02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer
Andres Mendez-Vazquez
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrences
jayavignesh86
 
Big o notation
Big o notationBig o notation
Big o notation
hamza mushtaq
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Mohammed Hussein
 
Quick Sort
Quick SortQuick Sort
Quick Sort
priyankanaidu6
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Vikas Sharma
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notation
irdginfo
 
02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences
Noushadur Shoukhin
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Muhammad Sarfraz
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Amrinder Arora
 
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
Amrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
Amrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
Amrinder Arora
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
Amrinder Arora
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
Amrinder Arora
 
Divide and conquer 1
Divide and conquer 1Divide and conquer 1
Divide and conquer 1
Kumar
 
02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer
Andres Mendez-Vazquez
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrences
jayavignesh86
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort ,  Heap SortQuick Sort , Merge Sort ,  Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Vikas Sharma
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notation
irdginfo
 
02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences
Noushadur Shoukhin
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Amrinder Arora
 
Ad

Similar to Divide and Conquer - Part 1 (20)

T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
GadaFarhan
 
Merge Sort
Merge SortMerge Sort
Merge Sort
Juan Zamora, MSc. MBA
 
ADA_Module 2_MN.pptx Analysis and Design of Algorithms
ADA_Module 2_MN.pptx Analysis and Design of AlgorithmsADA_Module 2_MN.pptx Analysis and Design of Algorithms
ADA_Module 2_MN.pptx Analysis and Design of Algorithms
madhu614742
 
Presentation_23953_Content_Document_20240906040454PM.pptx
Presentation_23953_Content_Document_20240906040454PM.pptxPresentation_23953_Content_Document_20240906040454PM.pptx
Presentation_23953_Content_Document_20240906040454PM.pptx
rameshmanoj733
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
KokilaK25
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
Tareq Hasan
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
B.Kirron Reddi
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquer
chidabdu
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
Mumtaz Ali
 
2.pptx
2.pptx2.pptx
2.pptx
MohAlyasin1
 
03 dc
03 dc03 dc
03 dc
Hira Gul
 
Slide2
Slide2Slide2
Slide2
Thiti Sununta
 
Intro to super. advance algorithm..pptx
Intro to super.   advance algorithm..pptxIntro to super.   advance algorithm..pptx
Intro to super. advance algorithm..pptx
ManishBaranwal10
 
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.pptChapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
AbdisaAwel
 
lecture 1
lecture 1lecture 1
lecture 1
sajinsc
 
Divide and Conquer in DAA concept. For B Tech CSE
Divide and Conquer  in DAA concept. For B Tech CSEDivide and Conquer  in DAA concept. For B Tech CSE
Divide and Conquer in DAA concept. For B Tech CSE
RUHULAMINHAZARIKA
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
subhashchandra197
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
NANDINI SHARMA
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
appasami
 
Algorithms - Rocksolid Tour 2013
Algorithms  - Rocksolid Tour 2013Algorithms  - Rocksolid Tour 2013
Algorithms - Rocksolid Tour 2013
Gary Short
 
T2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptxT2311 - Ch 4_Part1.pptx
T2311 - Ch 4_Part1.pptx
GadaFarhan
 
ADA_Module 2_MN.pptx Analysis and Design of Algorithms
ADA_Module 2_MN.pptx Analysis and Design of AlgorithmsADA_Module 2_MN.pptx Analysis and Design of Algorithms
ADA_Module 2_MN.pptx Analysis and Design of Algorithms
madhu614742
 
Presentation_23953_Content_Document_20240906040454PM.pptx
Presentation_23953_Content_Document_20240906040454PM.pptxPresentation_23953_Content_Document_20240906040454PM.pptx
Presentation_23953_Content_Document_20240906040454PM.pptx
rameshmanoj733
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
KokilaK25
 
Sienna 4 divideandconquer
Sienna 4 divideandconquerSienna 4 divideandconquer
Sienna 4 divideandconquer
chidabdu
 
dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)dynamic programming complete by Mumtaz Ali (03154103173)
dynamic programming complete by Mumtaz Ali (03154103173)
Mumtaz Ali
 
Intro to super. advance algorithm..pptx
Intro to super.   advance algorithm..pptxIntro to super.   advance algorithm..pptx
Intro to super. advance algorithm..pptx
ManishBaranwal10
 
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.pptChapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
Chapter 1 & 2 - Introduction dhjgsdkjfsaf.ppt
AbdisaAwel
 
lecture 1
lecture 1lecture 1
lecture 1
sajinsc
 
Divide and Conquer in DAA concept. For B Tech CSE
Divide and Conquer  in DAA concept. For B Tech CSEDivide and Conquer  in DAA concept. For B Tech CSE
Divide and Conquer in DAA concept. For B Tech CSE
RUHULAMINHAZARIKA
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
subhashchandra197
 
Basic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV SyllabusBasic Computer Engineering Unit II as per RGPV Syllabus
Basic Computer Engineering Unit II as per RGPV Syllabus
NANDINI SHARMA
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
appasami
 
Algorithms - Rocksolid Tour 2013
Algorithms  - Rocksolid Tour 2013Algorithms  - Rocksolid Tour 2013
Algorithms - Rocksolid Tour 2013
Gary Short
 
Ad

More from Amrinder Arora (19)

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Amrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Amrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
Amrinder Arora
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
Amrinder Arora
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
Amrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
Amrinder Arora
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
Amrinder Arora
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for Strings
Amrinder Arora
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data Structures
Amrinder Arora
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTs
Amrinder Arora
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
Amrinder Arora
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsGraphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their Representations
Amrinder Arora
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Amrinder Arora
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
Amrinder Arora
 
Learning to learn
Learning to learnLearning to learn
Learning to learn
Amrinder Arora
 
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Amrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Amrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
Amrinder Arora
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
Amrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
Amrinder Arora
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
Amrinder Arora
 
Tries - Tree Based Structures for Strings
Tries - Tree Based Structures for StringsTries - Tree Based Structures for Strings
Tries - Tree Based Structures for Strings
Amrinder Arora
 
Splay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data StructuresSplay Trees and Self Organizing Data Structures
Splay Trees and Self Organizing Data Structures
Amrinder Arora
 
BTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTsBTrees - Great alternative to Red Black, AVL and other BSTs
BTrees - Great alternative to Red Black, AVL and other BSTs
Amrinder Arora
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
Amrinder Arora
 
Graphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their RepresentationsGraphs, Trees, Paths and Their Representations
Graphs, Trees, Paths and Their Representations
Amrinder Arora
 
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data StructuresStacks, Queues, Binary Search Trees -  Lecture 1 - Advanced Data Structures
Stacks, Queues, Binary Search Trees - Lecture 1 - Advanced Data Structures
Amrinder Arora
 
Online Algorithms - An Introduction
Online Algorithms - An IntroductionOnline Algorithms - An Introduction
Online Algorithms - An Introduction
Amrinder Arora
 

Recently uploaded (20)

Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 

Divide and Conquer - Part 1

  • 1. Design and Analysis of Algorithms DIVIDE AND CONQUER PART I GENERAL TEMPLATE BINARY SEARCH MERGE SORT & QUICK SORT SOLVING RECURRENCE RELATIONS
  • 2.  Instructor Prof. Amrinder Arora [email protected] Please copy TA on emails Please feel free to call as well   Available for study sessions Science and Engineering Hall GWU Algorithms Divide and Conquer - Part I 2 LOGISTICS
  • 4.  A technique to solve complex problems by breaking into smaller instances of the problem and combining the results  Recursive methodology – Smaller instances of the same type of problem  Typically used accompaniments  Induction for proving correctness  Recurrence relation solving for computing time (and/or space) complexity Algorithms Divide and Conquer - Part I 4 DIVIDE AND CONQUER
  • 5. By definition: For D&C, sub problems must be of same type. [The phrase “D&C” is also used in other contexts. It may refer to breaking down a task, but in Computer Science, D&C is a formal paradigm] Algorithms Divide and Conquer - Part I 5 D&C – CS, NOT MANAGEMENT/POLITICS
  • 6.  A recursive algorithm is an algorithm that calls itself on smaller input.  Algorithm sort (Array a) Begin sort (subarray consisting of first half of a) sort (subarray consisting of second half of a) do_something_else(); End Algorithms Divide and Conquer - Part I 6 RECURSION
  • 7.  Recurrence Relation is a recursive formula, commonly used to analyze the time complexity of recursive algorithms  For example  T(n) = T(n/2) + T(n/2) + n2  T(n) = a T(n/b) + f(n)  Note: Recurrence Relations have uses outside of time complexity analysis as well (for example in combinatorics), but for the purpose of this lecture, this is the main use case. Algorithms Divide and Conquer - Part I 7 RECURRENCE RELATIONS
  • 8.  Wikipedia says: “…it is often necessary to replace the original problem by a more general or complicated problem in order to get the recursion going, and there is no systematic method for finding the proper generalization.”  Refer to this as the “generalization” step  Sometimes counterintuitive that making a “generalization”, that is, making the problem harder actually helps in solving it! Algorithms Divide and Conquer - Part I 8 HOW TO D&C
  • 9. divide_conquer(input J) { // Base Case if (size of input is small enough) { solve directly and return } // Divide Step divide J into two or more parts J1, J2,... // Recursive Calls call divide_conquer(J1) to get a subsolution S1 call divide_conquer(J2) to get a subsolution S2 ... // Merge Step Merge the subsolutions S1, S2,...into a global solution S return S } Algorithms Divide and Conquer - Part I 9 GENERAL TEMPLATE
  • 10.  Number of subproblems that you create in the “divide” step  This plays a role in the recurrence relation that is created for analysis  T(n) = a T(n/b) + f(n) Here “a” branches, each with size “n/b”, and f(n) time spent in dividing and merging  Example: T(n) = T(n/2) + 1 1 branch, size half and constant time spent in dividing and merging Algorithms Divide and Conquer - Part I 10 NUMBER OF BRANCHES
  • 11. divide_conquer(input J) { // Base Case if (size of input is small enough) { solve directly and return } // Divide Step divide J into two or more parts J1, J2,... // Recursive Calls call divide_conquer(J1) to get a subsolution S1 call divide_conquer(J2) to get a subsolution S2 ... // Merge Step Merge the subsolutions S1, S2,...into a global solution S return S } Algorithms Divide and Conquer - Part I 11 GENERAL TEMPLATE – TIME COMPLEXITY VIEW Combined time in steps other than recursive calls: f(n) a recursive calls of size n/b each. Total time: a T(n/b)
  • 12.  Binary Search  Merge Sort  Quick Sort Algorithms Divide and Conquer - Part I 12 D&C – EXAMPLE ALGORITHMS
  • 13.  Search (A, low, high, key)  Mid = (low + high) / 2  Compare A[mid] to key, and look either in left half or in right half  T(n) = T(n/2) + 1  T(n) = O(log n) Algorithms Divide and Conquer - Part I 13 BINARY SEARCH
  • 14.  Classic problem: Given an array, to sort it  Generalization step: Given an array and indexes i and j (start and end) to sort that portion of it  Algorithm MergeSort (input: A,i,j) { // Divide portion if (j – i < THRESHOLD) { InsertionSort(A,i,j) Return } int k=(i+j)/2 // Recursive Calls MergeSort(A,i,k) MergeSort(A,k+1,j) // Merge Calls Merge(A,i,k,k+1,j) } Algorithms Divide and Conquer - Part I 14 MERGE SORT
  • 15.  How to merge two lists effectively? Algorithms Divide and Conquer - Part I 15 MERGING
  • 16.  T(n) = 2T(n/2) + (n)  Need some methods for solving such recurrence equations  Substitution method  Recursion tree method (unfolding)  Master theorem  T(n) = (n log n) Algorithms Divide and Conquer - Part I 16 TIME COMPLEXITY OF MERGE SORT
  • 17. Algorithms Divide and Conquer - Part I 17 EXAMPLES OF RECURRENCE RELATIONS
  • 18.  Examples:  T(n) = 2 T(n/2) + cn T(n) = O (n log n)  T(n) = T(n/2) + n T(n) = O (n)  3 General Approaches:  Substitution method (Guess and Prove)  Recursion tree method (unfold and reach a pattern)  Master theorem Algorithms Divide and Conquer - Part I 18 SOLVING RECURRENCE RELATIONS
  • 19.  Given T(n) = 2 T(n/2) + cn  We first “guess” that the solution is O(n log n)  To prove this using induction, we first assume T(m) <= km log m for all m < n  Then T(n) = 2 T(n/2) + cn <= 2 kn/2 log (n/2) + cn = kn log n – (k – c)n // log (n/2) = log n – 1 <= k n log n, as long as k >= c Algorithms Divide and Conquer - Part I 19 SUBSTITUTION METHOD FOR MERGE SORT
  • 20. Algorithms Divide and Conquer - Part I 20 MASTER THEOREM FOR SOLVING RECURRENCE RELATIONS Only applies to Recurrence Relations of following type T(n) = aT(n/b) + f(n)  Case 1. If f(n) = O(nc) where c < logb a, then T(n) = θ(n^logb a)  Case 2. If it is true, for some constant k ≥ 0, that f(n) = θ(nc logk n) where c = logb a, then T(n) = θ(nc logk+1 n)  Case 3. If it is true that f(n) = Ω(nc) where c > logb a, then T(n) = θ(f(n))
  • 21. T(n) = a T(n/b) + f(n) If we unfold this, we get an expression like: T(n) = ak T(n/bk) + f(n) + a f(n/b) + … + ak f(n/bk) Then, for k ≈ logbn, T(n/bk) will be a small constant, and we can assume T(n/bk) = 1. Then, T(n) = a^(logbn) + f(n) + af(n/b) + … + ak f(n/bk) = n^(logba) + f(n) + af(n/b) + … + ak f(n/bk) We note that there are about logbn terms. Algorithms Divide and Conquer - Part I 21 MASTER THEOREM – INTUITION Intuition != Formal Proof
  • 22. T(n) = n^(logba) + f(n) + af(n/b) + … + ak f(n/bk) We observe that: • If f(n) is very small, say a constant, then the first term dominates • If f(n) =  (n^(logba)), then the T(n) = f(n) log n. // The log n factor arises because there are ~ log n terms • If f(n) is too large, then f(n) terms dominate Algorithms Divide and Conquer - Part I 22 MASTER THEOREM – INTUITION (CONT.)
  • 23. T(n) = 2 T(n/2) + c n In this case: • a = b = 2 • f(n) = c n • logba = 1 • n^(logba) = n So, f(n) =  (n^(logba)) Therefore, by Master Theorem, T(n) = (f(n) log n) That is, T(n) = (n log n) Algorithms Divide and Conquer - Part I 23 APPLYING MASTER THEOREM TO MERGE SORT RECURRENCE
  • 24.  Select a “partition” element  Partition the array into “left” and “right” portions (not necessarily equal) based on the partition element  Sort the left and right sides  An inverted view of mergesort – spend time upfront (partition), no need to merge later. Algorithms Divide and Conquer - Part I 24 QUICKSORT
  • 25.  quicksort(A,p,r) if (p < r) { q = partition (A,p,r) quicksort(A,p,q-1) quicksort(A,q+1,r) } Algorithms Divide and Conquer - Part I 25 QUICKSORT – THE PSEUDO CODE
  • 26.  Invented in 1960 by C. A. R. Hoare  More widely used than any other sort  A well-studied, not difficult to implement algorithm  R. Sedgewick – 1975 Ph.D. thesis at Stanford Univ. – Analysis and Variations of QuickSort Algorithms Divide and Conquer - Part I 26 QUICKSORT (THE TRIVIA CLUB VIEW) Who said: “Elementary, My Dear Watson”?
  • 27.  “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”  “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” Algorithms Divide and Conquer - Part I 27 QUOTES, QUOTES
  • 28.  How to find a good partition element  How to partition (efficiently)  Partition array so that:  Some partitioning element (q) is its final position  Every element smaller than q is to the left of q  Every element larger than q is to the right of q  Sedgwick states that “improving QuickSort is the better mousetrap of computer science” Algorithms Divide and Conquer - Part I 28 CENTRAL PROBLEM IN QUICKSORT
  • 29.  T(n) = T(n1) + T(n2) + O(n) Where n1 + n2 = n – 1  So it all depends upon the kind of the split, and split will likely not be the same each time.  Worst case – very bad split: O(n2)  Best case – good split: O(n log n)  Average case – where does that fit? http://mathworld.wolfram.com/Quicksort.html Algorithms Divide and Conquer - Part I 29 QUICKSORT – TIME COMPLEXITY ANALYSIS
  • 30. How long will the algorithm take? Function sum (integer a) { if (a == 1) exit; if (a is odd) { a = 3a + 1 } else { a = a/2 } } Trichotomy – Extended Given two functions f(n) and g(n), both strictly increasing with n, is it possible that f(n) and g(n) cannot be compared asymptotically? Algorithms Divide and Conquer - Part I 30 OPEN QUESTIONS
  • 31. 1. Median Finding (Textbook § 4.6) 2. Closest pair of points algorithm (Textbook § 4.7) 3. Strassen’s algorithm for matrix multiplication (Textbook § 4.8) https://youtu.be/1AIvlizGo7Y Algorithms Divide and Conquer - Part I 31 READING ASSIGNMENTS We already have quite a few people who know how to divide. So essentially we are now looking for people who know how to conquer.