SlideShare a Scribd company logo
Willing is not enough, we must do
Bruce lee
Problem Statement:
In the subset-sum problem, we are given a finite set S of positive
integers and an integer target t > 0. We ask whether there exists a
subset S`⊆ S whose elements sum to t.
TRUE FALSE
t = 138457 TRUE
How to Design an Algorithm to Solve this Problem??
Brute Force??
Making all possible Subsets
A={1,2,4}
What will be its Complexity???
All possible subsets???
1. A’={}
2. A’={1}
3. A’={1,2}
4. A’={1,4}
5. A’={1,2,4}
6. A’={2}
7. A’={2,4}
8. A’={4}
SumOFSubset=2n=8
Brute Force Subset Sum Solution
Running time Q(n 2n )
What does this tell us about the time
complexity of the subset sum problem?
bool SumSub (w, i, j)
{
if (i == 0) return (j == 0);
else
if (SumSub (w, i-1, j)) return true;
else if ((j - wi) >= 0) return SumSub (w, i-1, j - wi);
else return false;
}
Complexity
0( 2n N)
All possible subsets and time required to sum them.
Brute Force??? No, thanks
Why is this Failing???
• Sometimes, the divide and conquer
approach seems appropriate but fails
to produce an efficient algorithm.
• One of the reasons is that D&Q
produces overlapping sub problems.
Dynamic Approach
Divide and conquer with Tabular form
Solves a sub-problem by making use of previously stored
solutions for all other sub problems.
HOW?????
Lets take an example
0 1 2 3 4 5 6 7 8 9 10 11
2
3
7
8
10
A={2,3,7,8,10} t=11
Any subset of { 2} making sum=0 ???
Lets take an example
0 1 2 3 4 5 6 7 8 9 10 11
2 T
3
7
8
10
A={2,3,7,8,10} t=11
Lets take an example
0 1 2 3 4 5 6 7 8 9 10 11
2 T F
3
7
8
10
A={2,3,7,8,10} t=11
Any subset of { 2} making sum=1 ???
Lets take an example
0 1 2 3 4 5 6 7 8 9 10 11
2 T F T
3
7
8
10
A={2,3,7,8,10} t=11
Any subset of { 2} making sum=3 ???
Lets take an example
0 1 2 3 4 5 6 7 8 9 10 11
2 T F T F F F F F F F F F
3 T F T T F T F F F F F F
7 T F T T F T F T F T T F
8 T F T T F T F T T T T T
10 T F T T F T F T T T T T
A={2,3,7,8,10} t=11
How to get the Answer??
8 is one of the Element
3 is one of the Element
As we have reached the Last row..
A’={8,3} is our Answer 
18
Dynamic Programming Algorithm
bool SumSub (w , n , m)
{
1. t[0,0] = true; for (j = 1 to m) t[0,j] = false;
2. for (i = 1 to n)
3. for (j = 0 to m)
4. t[i,j] = t[i-1,j];
5. if ((j-wi) >= 0)
6. t[i,j] = t[i-1,j] || t[i-1, j – wi];
7. return t[n,m];
}
i-1,
j - wi
i-1,
j
i , j
Its Complexity???
Time complexity is T(n) = O(m) + O(nm) = O(nm)
Application
Traveling Salesperson Problem
–Input: a graph of cities and roads
with distance connecting them and a
minimum total distant
–Output: either a path that visits each
with a cost less than the minimum,
or “no”.
• If given a path, easy to check if it
visits every city with less than
minimum distance travelled.
Drug Discovery Problem
–Input: a set of
proteins, a desired
3D shape
–Output: a sequence
of proteins that
produces the shape
(or impossible)
If given a sequence, easy to
check if sequence has the right shape.
THE END
Ad

More Related Content

What's hot (20)

CMSC 56 | Lecture 15: Closures of Relations
CMSC 56 | Lecture 15: Closures of RelationsCMSC 56 | Lecture 15: Closures of Relations
CMSC 56 | Lecture 15: Closures of Relations
allyn joy calcaben
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
Dr Shashikant Athawale
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
Megha V
 
ER to relational Mapping: Data base design using ER to relational language. C...
ER to relational Mapping: Data base design using ER to relational language. C...ER to relational Mapping: Data base design using ER to relational language. C...
ER to relational Mapping: Data base design using ER to relational language. C...
Raj vardhan
 
Regular expression to NFA (Nondeterministic Finite Automata)
Regular expression to NFA (Nondeterministic Finite Automata)Regular expression to NFA (Nondeterministic Finite Automata)
Regular expression to NFA (Nondeterministic Finite Automata)
Niloy Biswas
 
minimum spanning tree
minimum spanning tree minimum spanning tree
minimum spanning tree
Melaku Bayih Demessie
 
Master theorem
Master theoremMaster theorem
Master theorem
fika sweety
 
Prim's algorithm
Prim's algorithmPrim's algorithm
Prim's algorithm
Pankaj Thakur
 
Introduction of suffix tree
Introduction of suffix treeIntroduction of suffix tree
Introduction of suffix tree
Liou Shu Hung
 
3.4 deterministic pda
3.4 deterministic pda3.4 deterministic pda
3.4 deterministic pda
Sampath Kumar S
 
Sql Objects And PL/SQL
Sql Objects And PL/SQLSql Objects And PL/SQL
Sql Objects And PL/SQL
Gary Myers
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
subhashchandra197
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
Bipul Roy Bpl
 
Fp growth
Fp growthFp growth
Fp growth
Farah M. Altufaili
 
Branch & bound
Branch & boundBranch & bound
Branch & bound
kannanchirayath
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
Muhammad Hammad Waseem
 
Prims & kruskal algorithms
Prims & kruskal algorithmsPrims & kruskal algorithms
Prims & kruskal algorithms
Ayesha Tahir
 
Automata theory -RE to NFA-ε
Automata theory -RE to  NFA-εAutomata theory -RE to  NFA-ε
Automata theory -RE to NFA-ε
Akila Krishnamoorthy
 
pushdown automata
pushdown automatapushdown automata
pushdown automata
Sujata Pardeshi
 
Tries
TriesTries
Tries
Shubham Shukla
 
CMSC 56 | Lecture 15: Closures of Relations
CMSC 56 | Lecture 15: Closures of RelationsCMSC 56 | Lecture 15: Closures of Relations
CMSC 56 | Lecture 15: Closures of Relations
allyn joy calcaben
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
Megha V
 
ER to relational Mapping: Data base design using ER to relational language. C...
ER to relational Mapping: Data base design using ER to relational language. C...ER to relational Mapping: Data base design using ER to relational language. C...
ER to relational Mapping: Data base design using ER to relational language. C...
Raj vardhan
 
Regular expression to NFA (Nondeterministic Finite Automata)
Regular expression to NFA (Nondeterministic Finite Automata)Regular expression to NFA (Nondeterministic Finite Automata)
Regular expression to NFA (Nondeterministic Finite Automata)
Niloy Biswas
 
Introduction of suffix tree
Introduction of suffix treeIntroduction of suffix tree
Introduction of suffix tree
Liou Shu Hung
 
Sql Objects And PL/SQL
Sql Objects And PL/SQLSql Objects And PL/SQL
Sql Objects And PL/SQL
Gary Myers
 
Recurrence relation solutions
Recurrence relation solutionsRecurrence relation solutions
Recurrence relation solutions
subhashchandra197
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
Bipul Roy Bpl
 
Prims & kruskal algorithms
Prims & kruskal algorithmsPrims & kruskal algorithms
Prims & kruskal algorithms
Ayesha Tahir
 

Viewers also liked (20)

01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
mandlapure
 
Backtracking
BacktrackingBacktracking
Backtracking
Vikas Sharma
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
Kumar
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
Sahil Kumar
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Backtracking
BacktrackingBacktracking
Backtracking
subhradeep mitra
 
Solution 3.
Solution 3.Solution 3.
Solution 3.
sansaristic
 
All Pair Shortest Path Algorithm – Parallel Implementation and Analysis
All Pair Shortest Path Algorithm – Parallel Implementation and AnalysisAll Pair Shortest Path Algorithm – Parallel Implementation and Analysis
All Pair Shortest Path Algorithm – Parallel Implementation and Analysis
Inderjeet Singh
 
Physical Computing and IoT
Physical Computing and IoTPhysical Computing and IoT
Physical Computing and IoT
Eduardo Oliveira
 
Seminar report on android os
Seminar report on android osSeminar report on android os
Seminar report on android os
Appsthentic Technology
 
(floyd's algm)
(floyd's algm)(floyd's algm)
(floyd's algm)
Jothi Lakshmi
 
Randomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Randomized Algorithms in Linear Algebra & the Column Subset Selection ProblemRandomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Randomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Wei Xue
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Yıldırım Tam
 
lecture 30
lecture 30lecture 30
lecture 30
sajinsc
 
Chap08alg
Chap08algChap08alg
Chap08alg
Munkhchimeg
 
Solving The Shortest Path Tour Problem
Solving The Shortest Path Tour ProblemSolving The Shortest Path Tour Problem
Solving The Shortest Path Tour Problem
Nozir Shokirov
 
21 backtracking
21 backtracking21 backtracking
21 backtracking
Aparup Behera
 
DP
DPDP
DP
Subba Oota
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
Krish_ver2
 
Matrix chain multiplication 2
Matrix chain multiplication 2Matrix chain multiplication 2
Matrix chain multiplication 2
Maher Alshammari
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
mandlapure
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
Kumar
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
Sahil Kumar
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
All Pair Shortest Path Algorithm – Parallel Implementation and Analysis
All Pair Shortest Path Algorithm – Parallel Implementation and AnalysisAll Pair Shortest Path Algorithm – Parallel Implementation and Analysis
All Pair Shortest Path Algorithm – Parallel Implementation and Analysis
Inderjeet Singh
 
Physical Computing and IoT
Physical Computing and IoTPhysical Computing and IoT
Physical Computing and IoT
Eduardo Oliveira
 
Randomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Randomized Algorithms in Linear Algebra & the Column Subset Selection ProblemRandomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Randomized Algorithms in Linear Algebra & the Column Subset Selection Problem
Wei Xue
 
lecture 30
lecture 30lecture 30
lecture 30
sajinsc
 
Solving The Shortest Path Tour Problem
Solving The Shortest Path Tour ProblemSolving The Shortest Path Tour Problem
Solving The Shortest Path Tour Problem
Nozir Shokirov
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
Krish_ver2
 
Matrix chain multiplication 2
Matrix chain multiplication 2Matrix chain multiplication 2
Matrix chain multiplication 2
Maher Alshammari
 
Ad

Similar to Subset sum problem Dynamic and Brute Force Approch (20)

Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Ed...
Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Ed...Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Ed...
Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Ed...
linarasivani50
 
Mergesort
MergesortMergesort
Mergesort
luzenith_g
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
YekoyeTigabuYeko
 
Time complexity.pptr56435 erfgegr t 45t 35
Time complexity.pptr56435 erfgegr t 45t 35Time complexity.pptr56435 erfgegr t 45t 35
Time complexity.pptr56435 erfgegr t 45t 35
DickyNsjg1
 
How to calculate complexity in Data Structure
How to calculate complexity in Data StructureHow to calculate complexity in Data Structure
How to calculate complexity in Data Structure
debasisdas225831
 
Time complexity.pptxghhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjj
Time complexity.pptxghhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjjTime complexity.pptxghhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjj
Time complexity.pptxghhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjj
shesnasuneer
 
Computation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine MatricesComputation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine Matrices
Lossian Barbosa Bacelar Miranda
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
Dr. Rajdeep Chatterjee
 
3. convolution fourier
3. convolution fourier3. convolution fourier
3. convolution fourier
skysunilyadav
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
Hull White model presentation
Hull White model presentationHull White model presentation
Hull White model presentation
Stephan Chang
 
DOUBLE INTEGRAL.Introduction Numerical Problem Based on Lagrange’s Method of ...
DOUBLE INTEGRAL.Introduction Numerical Problem Based on Lagrange’s Method of ...DOUBLE INTEGRAL.Introduction Numerical Problem Based on Lagrange’s Method of ...
DOUBLE INTEGRAL.Introduction Numerical Problem Based on Lagrange’s Method of ...
ruvirgandhi123
 
X01 Supervised learning problem linear regression one feature theorie
X01 Supervised learning problem linear regression one feature theorieX01 Supervised learning problem linear regression one feature theorie
X01 Supervised learning problem linear regression one feature theorie
Marco Moldenhauer
 
C1 - Insertion Sort
C1 - Insertion SortC1 - Insertion Sort
C1 - Insertion Sort
Juan Zamora, MSc. MBA
 
Tutorial on EM algorithm – Part 2
Tutorial on EM algorithm – Part 2Tutorial on EM algorithm – Part 2
Tutorial on EM algorithm – Part 2
Loc Nguyen
 
file_5.pptx
file_5.pptxfile_5.pptx
file_5.pptx
MdMuhaiminurRahmanRu
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
pppepito86
 
TableDrivenProg_20160714
TableDrivenProg_20160714TableDrivenProg_20160714
TableDrivenProg_20160714
Teddy Hsiung
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
Tareq Hasan
 
0-1 knapsack problem
0-1 knapsack problem0-1 knapsack problem
0-1 knapsack problem
A. S. M. Shafi
 
Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Ed...
Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Ed...Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Ed...
Solution Manual for Data Structures and Algorithm Analysis in C++, 4/E 4th Ed...
linarasivani50
 
Time complexity.pptr56435 erfgegr t 45t 35
Time complexity.pptr56435 erfgegr t 45t 35Time complexity.pptr56435 erfgegr t 45t 35
Time complexity.pptr56435 erfgegr t 45t 35
DickyNsjg1
 
How to calculate complexity in Data Structure
How to calculate complexity in Data StructureHow to calculate complexity in Data Structure
How to calculate complexity in Data Structure
debasisdas225831
 
Time complexity.pptxghhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjj
Time complexity.pptxghhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjjTime complexity.pptxghhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjj
Time complexity.pptxghhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjj
shesnasuneer
 
Computation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine MatricesComputation of Semi-Magic Squares Generated by Serpentine Matrices
Computation of Semi-Magic Squares Generated by Serpentine Matrices
Lossian Barbosa Bacelar Miranda
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
Dr. Rajdeep Chatterjee
 
3. convolution fourier
3. convolution fourier3. convolution fourier
3. convolution fourier
skysunilyadav
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
Tariq Khan
 
Hull White model presentation
Hull White model presentationHull White model presentation
Hull White model presentation
Stephan Chang
 
DOUBLE INTEGRAL.Introduction Numerical Problem Based on Lagrange’s Method of ...
DOUBLE INTEGRAL.Introduction Numerical Problem Based on Lagrange’s Method of ...DOUBLE INTEGRAL.Introduction Numerical Problem Based on Lagrange’s Method of ...
DOUBLE INTEGRAL.Introduction Numerical Problem Based on Lagrange’s Method of ...
ruvirgandhi123
 
X01 Supervised learning problem linear regression one feature theorie
X01 Supervised learning problem linear regression one feature theorieX01 Supervised learning problem linear regression one feature theorie
X01 Supervised learning problem linear regression one feature theorie
Marco Moldenhauer
 
Tutorial on EM algorithm – Part 2
Tutorial on EM algorithm – Part 2Tutorial on EM algorithm – Part 2
Tutorial on EM algorithm – Part 2
Loc Nguyen
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
pppepito86
 
TableDrivenProg_20160714
TableDrivenProg_20160714TableDrivenProg_20160714
TableDrivenProg_20160714
Teddy Hsiung
 
Ad

Recently uploaded (20)

CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
ThanushsaranS
 
computer organization and assembly language.docx
computer organization and assembly language.docxcomputer organization and assembly language.docx
computer organization and assembly language.docx
alisoftwareengineer1
 
1. Briefing Session_SEED with Hon. Governor Assam - 27.10.pdf
1. Briefing Session_SEED with Hon. Governor Assam - 27.10.pdf1. Briefing Session_SEED with Hon. Governor Assam - 27.10.pdf
1. Briefing Session_SEED with Hon. Governor Assam - 27.10.pdf
Simran112433
 
Customer Segmentation using K-Means clustering
Customer Segmentation using K-Means clusteringCustomer Segmentation using K-Means clustering
Customer Segmentation using K-Means clustering
Ingrid Nyakerario
 
Minions Want to eat presentacion muy linda
Minions Want to eat presentacion muy lindaMinions Want to eat presentacion muy linda
Minions Want to eat presentacion muy linda
CarlaAndradesSoler1
 
Classification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptxClassification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptx
wencyjorda88
 
Data Analytics Overview and its applications
Data Analytics Overview and its applicationsData Analytics Overview and its applications
Data Analytics Overview and its applications
JanmejayaMishra7
 
C++_OOPs_DSA1_Presentation_Template.pptx
C++_OOPs_DSA1_Presentation_Template.pptxC++_OOPs_DSA1_Presentation_Template.pptx
C++_OOPs_DSA1_Presentation_Template.pptx
aquibnoor22079
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
VKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptxVKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptx
Vinod Srivastava
 
Deloitte - A Framework for Process Mining Projects
Deloitte - A Framework for Process Mining ProjectsDeloitte - A Framework for Process Mining Projects
Deloitte - A Framework for Process Mining Projects
Process mining Evangelist
 
Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
ISO 9001_2015 FINALaaaaaaaaaaaaaaaa - MDX - Copy.pptx
ISO 9001_2015 FINALaaaaaaaaaaaaaaaa - MDX - Copy.pptxISO 9001_2015 FINALaaaaaaaaaaaaaaaa - MDX - Copy.pptx
ISO 9001_2015 FINALaaaaaaaaaaaaaaaa - MDX - Copy.pptx
pankaj6188303
 
Conic Sectionfaggavahabaayhahahahahs.pptx
Conic Sectionfaggavahabaayhahahahahs.pptxConic Sectionfaggavahabaayhahahahahs.pptx
Conic Sectionfaggavahabaayhahahahahs.pptx
taiwanesechetan
 
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptxPerencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
PareaRusan
 
Modern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx AaModern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx Aa
MuhammadAwaisKamboh
 
定制学历(美国Purdue毕业证)普渡大学电子版毕业证
定制学历(美国Purdue毕业证)普渡大学电子版毕业证定制学历(美国Purdue毕业证)普渡大学电子版毕业证
定制学历(美国Purdue毕业证)普渡大学电子版毕业证
Taqyea
 
VKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptxVKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptx
Vinod Srivastava
 
03 Daniel 2-notes.ppt seminario escatologia
03 Daniel 2-notes.ppt seminario escatologia03 Daniel 2-notes.ppt seminario escatologia
03 Daniel 2-notes.ppt seminario escatologia
Alexander Romero Arosquipa
 
DPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdfDPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdf
inmishra17121973
 
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
CTS EXCEPTIONSPrediction of Aluminium wire rod physical properties through AI...
ThanushsaranS
 
computer organization and assembly language.docx
computer organization and assembly language.docxcomputer organization and assembly language.docx
computer organization and assembly language.docx
alisoftwareengineer1
 
1. Briefing Session_SEED with Hon. Governor Assam - 27.10.pdf
1. Briefing Session_SEED with Hon. Governor Assam - 27.10.pdf1. Briefing Session_SEED with Hon. Governor Assam - 27.10.pdf
1. Briefing Session_SEED with Hon. Governor Assam - 27.10.pdf
Simran112433
 
Customer Segmentation using K-Means clustering
Customer Segmentation using K-Means clusteringCustomer Segmentation using K-Means clustering
Customer Segmentation using K-Means clustering
Ingrid Nyakerario
 
Minions Want to eat presentacion muy linda
Minions Want to eat presentacion muy lindaMinions Want to eat presentacion muy linda
Minions Want to eat presentacion muy linda
CarlaAndradesSoler1
 
Classification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptxClassification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptx
wencyjorda88
 
Data Analytics Overview and its applications
Data Analytics Overview and its applicationsData Analytics Overview and its applications
Data Analytics Overview and its applications
JanmejayaMishra7
 
C++_OOPs_DSA1_Presentation_Template.pptx
C++_OOPs_DSA1_Presentation_Template.pptxC++_OOPs_DSA1_Presentation_Template.pptx
C++_OOPs_DSA1_Presentation_Template.pptx
aquibnoor22079
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
VKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptxVKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptx
Vinod Srivastava
 
Deloitte - A Framework for Process Mining Projects
Deloitte - A Framework for Process Mining ProjectsDeloitte - A Framework for Process Mining Projects
Deloitte - A Framework for Process Mining Projects
Process mining Evangelist
 
Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
ISO 9001_2015 FINALaaaaaaaaaaaaaaaa - MDX - Copy.pptx
ISO 9001_2015 FINALaaaaaaaaaaaaaaaa - MDX - Copy.pptxISO 9001_2015 FINALaaaaaaaaaaaaaaaa - MDX - Copy.pptx
ISO 9001_2015 FINALaaaaaaaaaaaaaaaa - MDX - Copy.pptx
pankaj6188303
 
Conic Sectionfaggavahabaayhahahahahs.pptx
Conic Sectionfaggavahabaayhahahahahs.pptxConic Sectionfaggavahabaayhahahahahs.pptx
Conic Sectionfaggavahabaayhahahahahs.pptx
taiwanesechetan
 
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptxPerencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
PareaRusan
 
Modern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx AaModern_Distribution_Presentation.pptx Aa
Modern_Distribution_Presentation.pptx Aa
MuhammadAwaisKamboh
 
定制学历(美国Purdue毕业证)普渡大学电子版毕业证
定制学历(美国Purdue毕业证)普渡大学电子版毕业证定制学历(美国Purdue毕业证)普渡大学电子版毕业证
定制学历(美国Purdue毕业证)普渡大学电子版毕业证
Taqyea
 
VKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptxVKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptx
Vinod Srivastava
 
DPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdfDPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdf
inmishra17121973
 

Subset sum problem Dynamic and Brute Force Approch

  • 1. Willing is not enough, we must do Bruce lee
  • 2. Problem Statement: In the subset-sum problem, we are given a finite set S of positive integers and an integer target t > 0. We ask whether there exists a subset S`⊆ S whose elements sum to t.
  • 3. TRUE FALSE t = 138457 TRUE How to Design an Algorithm to Solve this Problem??
  • 4. Brute Force?? Making all possible Subsets
  • 5. A={1,2,4} What will be its Complexity??? All possible subsets??? 1. A’={} 2. A’={1} 3. A’={1,2} 4. A’={1,4} 5. A’={1,2,4} 6. A’={2} 7. A’={2,4} 8. A’={4} SumOFSubset=2n=8
  • 6. Brute Force Subset Sum Solution Running time Q(n 2n ) What does this tell us about the time complexity of the subset sum problem? bool SumSub (w, i, j) { if (i == 0) return (j == 0); else if (SumSub (w, i-1, j)) return true; else if ((j - wi) >= 0) return SumSub (w, i-1, j - wi); else return false; }
  • 7. Complexity 0( 2n N) All possible subsets and time required to sum them. Brute Force??? No, thanks Why is this Failing???
  • 8. • Sometimes, the divide and conquer approach seems appropriate but fails to produce an efficient algorithm. • One of the reasons is that D&Q produces overlapping sub problems.
  • 9. Dynamic Approach Divide and conquer with Tabular form Solves a sub-problem by making use of previously stored solutions for all other sub problems. HOW?????
  • 10. Lets take an example 0 1 2 3 4 5 6 7 8 9 10 11 2 3 7 8 10 A={2,3,7,8,10} t=11 Any subset of { 2} making sum=0 ???
  • 11. Lets take an example 0 1 2 3 4 5 6 7 8 9 10 11 2 T 3 7 8 10 A={2,3,7,8,10} t=11
  • 12. Lets take an example 0 1 2 3 4 5 6 7 8 9 10 11 2 T F 3 7 8 10 A={2,3,7,8,10} t=11 Any subset of { 2} making sum=1 ???
  • 13. Lets take an example 0 1 2 3 4 5 6 7 8 9 10 11 2 T F T 3 7 8 10 A={2,3,7,8,10} t=11 Any subset of { 2} making sum=3 ???
  • 14. Lets take an example 0 1 2 3 4 5 6 7 8 9 10 11 2 T F T F F F F F F F F F 3 T F T T F T F F F F F F 7 T F T T F T F T F T T F 8 T F T T F T F T T T T T 10 T F T T F T F T T T T T A={2,3,7,8,10} t=11 How to get the Answer??
  • 15. 8 is one of the Element
  • 16. 3 is one of the Element
  • 17. As we have reached the Last row.. A’={8,3} is our Answer 
  • 18. 18 Dynamic Programming Algorithm bool SumSub (w , n , m) { 1. t[0,0] = true; for (j = 1 to m) t[0,j] = false; 2. for (i = 1 to n) 3. for (j = 0 to m) 4. t[i,j] = t[i-1,j]; 5. if ((j-wi) >= 0) 6. t[i,j] = t[i-1,j] || t[i-1, j – wi]; 7. return t[n,m]; } i-1, j - wi i-1, j i , j Its Complexity??? Time complexity is T(n) = O(m) + O(nm) = O(nm)
  • 19. Application Traveling Salesperson Problem –Input: a graph of cities and roads with distance connecting them and a minimum total distant –Output: either a path that visits each with a cost less than the minimum, or “no”. • If given a path, easy to check if it visits every city with less than minimum distance travelled.
  • 20. Drug Discovery Problem –Input: a set of proteins, a desired 3D shape –Output: a sequence of proteins that produces the shape (or impossible) If given a sequence, easy to check if sequence has the right shape.