SlideShare a Scribd company logo
1 of 19
Design & Analysis
of
Algorithms
DECREASE&CONQUER
TRANSFORM & CONQUER
TRANSFORM & CONQUER
Transforming
Stage
Conquering
Stage
Problem instance is
simplified to be more
amenable
Transformed
problem is solved
Types of problem modification
INSTANCE
SIMPLIFICATION
Problem instance is
transformed to be
more simple to solve
Presorting
Types of problem modification
Representation
Change
Data structure is
transformed so that
it is more efficient to
solve.
Horner’s Rule
Types of problem modification
Problem
Reduction
Problem is
transformed to
different problem
whose algorithm is
already available
Finding LCM
Presorting to find Mode
Algorithm PresortMode(A[0...n-1])
// assumes that A is sorted
i ← 0
modefrequency ← 0
while i < n do
runlength ← 1
runvalue ← A[i]
while i+runlength < n and A[i+runlength] = runvalue do
runlength++
if runlength > modefequency then
modefrequency ← runlength
modevalue ← runvalue
i += runlength
return modevalue
Algorithm PresortMode(A[0...n-1])
// assumes that A is sorted
i ← 0
modefrequency ← 0
while i < n do
runlength ← 1
runvalue ← A[i]
while i+runlength < n and A[i+runlength] = runvalue do
runlength++
if runlength > modefequency then
modefrequency ← runlength
modevalue ← runvalue
i += runlength
return modevalue
Using GCD to find LCM
lcm(m,n) = (m*n)/ gcd(m,n)
Decrease & CONQUER
Problem of size
N
Conquering
Stage
Solve for N-1
• Problem of Size N
• Solve for N-1
• Repeat above and problem will be
reduced eventually to what we can
easily solve
Decrement types
• Decrease by constant
e.g. insertion sort
• Decrease by constant factor
e.g. the fake coin problem
• Decrease by variable
e.g. Euclid’s Algorithm
Insertion Sort
Algorithm InsertionSort(A[0...n-1])
for i ← to n-1 do // move the unsorted portion
v ← A[i] // value to sort
j ← i-1 // end of the sorted array
while j ≥ 0 and A[j] > v do // scan the sorted part of the array for
the insertion point
A[j+1] ← A[j] // shift the sort array to make room for the insertion
j--
A[j+1] ← v // insert
Algorithm InsertionSort(A[0...n-1])
for i ← to n-1 do
v ← A[i]
j ← i-1
while j ≥ 0 and A[j] > v do
A[j+1] ← A[j]
j--
A[j+1] ← v
Complexity:
>>O(n^2) in worst case
>>O(n) for presorted array
BACKTRACKING APPROACH
BACK
TRACK
START
Yes
No
SearchAgain
SOLUTION
More about backtracking
• Just like Brute Force
• It is used when a problem has many candidates as solution.
• Used very commonly by hacker
• Used in electrical engineering
• Artificial intelligence
• Solving puzzles & paths
• Accuracy is guaranteed
Sum of Subsets
Algorithm SumOfSubset(s,k,y){
X[k] = 1;
If(s+w[k] = m)
Write (x[1:n]);
Else if((s+w[k] + w[k+1]) <= m)
SumOfSubset(s+w[k], k+1, y-w[k]);
If ((s+ y-w[k]>=m) &&(s =w[k+1] <=m)) {
X[k] =0;
SumOfSubset(s,k+1,y-w[k]);
}
}
Design & Analysis of Algorithms Techniques
Design & Analysis of Algorithms Techniques
Design & Analysis of Algorithms Techniques

More Related Content

What's hot

Derivatives
DerivativesDerivatives
Derivatives
smj123
 
Discreate time system and z transform
Discreate time system and z transformDiscreate time system and z transform
Discreate time system and z transform
VIKAS KUMAR MANJHI
 

What's hot (16)

Selection sort
Selection sortSelection sort
Selection sort
 
LYAPUNOV STABILITY PROBLEM SOLUTION
LYAPUNOV STABILITY PROBLEM SOLUTIONLYAPUNOV STABILITY PROBLEM SOLUTION
LYAPUNOV STABILITY PROBLEM SOLUTION
 
Lyapunov stability
Lyapunov stability Lyapunov stability
Lyapunov stability
 
Queues
QueuesQueues
Queues
 
Derivatives
DerivativesDerivatives
Derivatives
 
Admissions in india 2015
Admissions in india 2015Admissions in india 2015
Admissions in india 2015
 
Detalied information of queue
Detalied information of queueDetalied information of queue
Detalied information of queue
 
Nfa
NfaNfa
Nfa
 
n-squared_sorts
n-squared_sortsn-squared_sorts
n-squared_sorts
 
Discreate time system and z transform
Discreate time system and z transformDiscreate time system and z transform
Discreate time system and z transform
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Randomizing quicksort algorith with example
Randomizing quicksort algorith with exampleRandomizing quicksort algorith with example
Randomizing quicksort algorith with example
 
The Ring programming language version 1.3 book - Part 15 of 88
The Ring programming language version 1.3 book - Part 15 of 88The Ring programming language version 1.3 book - Part 15 of 88
The Ring programming language version 1.3 book - Part 15 of 88
 
Dsa circular queue
Dsa circular queueDsa circular queue
Dsa circular queue
 
Applications of Z transform
Applications of Z transformApplications of Z transform
Applications of Z transform
 

Similar to Design & Analysis of Algorithms Techniques

Similar to Design & Analysis of Algorithms Techniques (20)

09d transform & conquer spring2015
09d transform & conquer spring201509d transform & conquer spring2015
09d transform & conquer spring2015
 
Lecture Notes on Adaptive Signal Processing-1.pdf
Lecture Notes on Adaptive Signal Processing-1.pdfLecture Notes on Adaptive Signal Processing-1.pdf
Lecture Notes on Adaptive Signal Processing-1.pdf
 
Derivative Free Optimization
Derivative Free OptimizationDerivative Free Optimization
Derivative Free Optimization
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
 
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Dsoop (co 221) 1
Dsoop (co 221) 1Dsoop (co 221) 1
Dsoop (co 221) 1
 
Lecture 9-online
Lecture 9-onlineLecture 9-online
Lecture 9-online
 
Cs1311lecture23wdl
Cs1311lecture23wdlCs1311lecture23wdl
Cs1311lecture23wdl
 
DynamicProgramming.ppt
DynamicProgramming.pptDynamicProgramming.ppt
DynamicProgramming.ppt
 
Linear Regression.pptx
Linear Regression.pptxLinear Regression.pptx
Linear Regression.pptx
 
dynamic-programming
dynamic-programmingdynamic-programming
dynamic-programming
 
Analysis of Algorithms - 1
Analysis of Algorithms - 1Analysis of Algorithms - 1
Analysis of Algorithms - 1
 
Z transfrm ppt
Z transfrm pptZ transfrm ppt
Z transfrm ppt
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
 
Coursera 2week
Coursera  2weekCoursera  2week
Coursera 2week
 
DynamicProgramming.pdf
DynamicProgramming.pdfDynamicProgramming.pdf
DynamicProgramming.pdf
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
Merge sort
Merge sortMerge sort
Merge sort
 

Recently uploaded

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

Design & Analysis of Algorithms Techniques

  • 1.
  • 3. TRANSFORM & CONQUER Transforming Stage Conquering Stage Problem instance is simplified to be more amenable Transformed problem is solved
  • 4. Types of problem modification INSTANCE SIMPLIFICATION Problem instance is transformed to be more simple to solve Presorting
  • 5. Types of problem modification Representation Change Data structure is transformed so that it is more efficient to solve. Horner’s Rule
  • 6. Types of problem modification Problem Reduction Problem is transformed to different problem whose algorithm is already available Finding LCM
  • 7. Presorting to find Mode Algorithm PresortMode(A[0...n-1]) // assumes that A is sorted i ← 0 modefrequency ← 0 while i < n do runlength ← 1 runvalue ← A[i] while i+runlength < n and A[i+runlength] = runvalue do runlength++ if runlength > modefequency then modefrequency ← runlength modevalue ← runvalue i += runlength return modevalue
  • 8. Algorithm PresortMode(A[0...n-1]) // assumes that A is sorted i ← 0 modefrequency ← 0 while i < n do runlength ← 1 runvalue ← A[i] while i+runlength < n and A[i+runlength] = runvalue do runlength++ if runlength > modefequency then modefrequency ← runlength modevalue ← runvalue i += runlength return modevalue
  • 9. Using GCD to find LCM lcm(m,n) = (m*n)/ gcd(m,n)
  • 10. Decrease & CONQUER Problem of size N Conquering Stage Solve for N-1 • Problem of Size N • Solve for N-1 • Repeat above and problem will be reduced eventually to what we can easily solve
  • 11. Decrement types • Decrease by constant e.g. insertion sort • Decrease by constant factor e.g. the fake coin problem • Decrease by variable e.g. Euclid’s Algorithm
  • 12. Insertion Sort Algorithm InsertionSort(A[0...n-1]) for i ← to n-1 do // move the unsorted portion v ← A[i] // value to sort j ← i-1 // end of the sorted array while j ≥ 0 and A[j] > v do // scan the sorted part of the array for the insertion point A[j+1] ← A[j] // shift the sort array to make room for the insertion j-- A[j+1] ← v // insert
  • 13. Algorithm InsertionSort(A[0...n-1]) for i ← to n-1 do v ← A[i] j ← i-1 while j ≥ 0 and A[j] > v do A[j+1] ← A[j] j-- A[j+1] ← v Complexity: >>O(n^2) in worst case >>O(n) for presorted array
  • 15. More about backtracking • Just like Brute Force • It is used when a problem has many candidates as solution. • Used very commonly by hacker • Used in electrical engineering • Artificial intelligence • Solving puzzles & paths • Accuracy is guaranteed
  • 16. Sum of Subsets Algorithm SumOfSubset(s,k,y){ X[k] = 1; If(s+w[k] = m) Write (x[1:n]); Else if((s+w[k] + w[k+1]) <= m) SumOfSubset(s+w[k], k+1, y-w[k]); If ((s+ y-w[k]>=m) &&(s =w[k+1] <=m)) { X[k] =0; SumOfSubset(s,k+1,y-w[k]); } }