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

More Related Content

What's hot

Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
Satya Narayana
 
Topic Modeling
Topic ModelingTopic Modeling
Topic Modeling
Karol Grzegorczyk
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Python unit 3 and Unit 4
Python unit 3 and Unit 4Python unit 3 and Unit 4
Python unit 3 and Unit 4
Anandh Arumugakan
 
XLnet RoBERTa Reformer
XLnet RoBERTa ReformerXLnet RoBERTa Reformer
XLnet RoBERTa Reformer
San Kim
 
Language modelling and its use cases
Language modelling and its use casesLanguage modelling and its use cases
Language modelling and its use cases
Khrystyna Skopyk
 
LCS Presentation
LCS PresentationLCS Presentation
LCS Presentation
Tania Sahito
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
Divya Ks
 
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
BERT: Pre-training of Deep Bidirectional Transformers for Language UnderstandingBERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
Minh Pham
 
Word Embeddings - Introduction
Word Embeddings - IntroductionWord Embeddings - Introduction
Word Embeddings - Introduction
Christian Perone
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
Krish_ver2
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
Abhishek Singh
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
Shipra Swati
 
Basic review on topic modeling
Basic review on  topic modelingBasic review on  topic modeling
Basic review on topic modeling
Hiroyuki Kuromiya
 
Introduction to Natural Language Processing
Introduction to Natural Language ProcessingIntroduction to Natural Language Processing
Introduction to Natural Language Processing
Pranav Gupta
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Respa Peter
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
Arvind Krishnaa
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Kiran K
 
NLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit DistanceNLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit Distance
Hemantha Kulathilake
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
Hema Kashyap
 

What's hot (20)

Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Topic Modeling
Topic ModelingTopic Modeling
Topic Modeling
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Python unit 3 and Unit 4
Python unit 3 and Unit 4Python unit 3 and Unit 4
Python unit 3 and Unit 4
 
XLnet RoBERTa Reformer
XLnet RoBERTa ReformerXLnet RoBERTa Reformer
XLnet RoBERTa Reformer
 
Language modelling and its use cases
Language modelling and its use casesLanguage modelling and its use cases
Language modelling and its use cases
 
LCS Presentation
LCS PresentationLCS Presentation
LCS Presentation
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
 
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
BERT: Pre-training of Deep Bidirectional Transformers for Language UnderstandingBERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
 
Word Embeddings - Introduction
Word Embeddings - IntroductionWord Embeddings - Introduction
Word Embeddings - Introduction
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
 
Basic review on topic modeling
Basic review on  topic modelingBasic review on  topic modeling
Basic review on topic modeling
 
Introduction to Natural Language Processing
Introduction to Natural Language ProcessingIntroduction to Natural Language Processing
Introduction to Natural Language Processing
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
NLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit DistanceNLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit Distance
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
 

Viewers also liked

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
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
 

Viewers also liked (20)

01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
Backtracking
BacktrackingBacktracking
Backtracking
 
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
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Solution 3.
Solution 3.Solution 3.
Solution 3.
 
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
 
Physical Computing and IoT
Physical Computing and IoTPhysical Computing and IoT
Physical Computing and IoT
 
Seminar report on android os
Seminar report on android osSeminar report on android os
Seminar report on android os
 
(floyd's algm)
(floyd's algm)(floyd's algm)
(floyd's algm)
 
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
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
lecture 30
lecture 30lecture 30
lecture 30
 
Chap08alg
Chap08algChap08alg
Chap08alg
 
Solving The Shortest Path Tour Problem
Solving The Shortest Path Tour ProblemSolving The Shortest Path Tour Problem
Solving The Shortest Path Tour Problem
 
21 backtracking
21 backtracking21 backtracking
21 backtracking
 
DP
DPDP
DP
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
 
Matrix chain multiplication 2
Matrix chain multiplication 2Matrix chain multiplication 2
Matrix chain multiplication 2
 

Similar to Subset sum problem Dynamic and Brute Force Approch

Mergesort
MergesortMergesort
Mergesort
luzenith_g
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
YekoyeTigabuYeko
 
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
 
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
 
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
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
 
Problem descriptionThe Jim Thornton Coffee House chain is .docx
Problem descriptionThe Jim Thornton Coffee House chain is .docxProblem descriptionThe Jim Thornton Coffee House chain is .docx
Problem descriptionThe Jim Thornton Coffee House chain is .docx
elishaoatway
 
Power of authomata
Power of authomataPower of authomata
Power of authomata
Dr. ABHISHEK K PANDEY
 
Ch8b
Ch8bCh8b
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
Abbas Ali
 

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

Mergesort
MergesortMergesort
Mergesort
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
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
 
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
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
 
3. convolution fourier
3. convolution fourier3. convolution fourier
3. convolution fourier
 
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.
 
Hull White model presentation
Hull White model presentationHull White model presentation
Hull White model presentation
 
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
 
C1 - Insertion Sort
C1 - Insertion SortC1 - Insertion Sort
C1 - Insertion Sort
 
Tutorial on EM algorithm – Part 2
Tutorial on EM algorithm – Part 2Tutorial on EM algorithm – Part 2
Tutorial on EM algorithm – Part 2
 
file_5.pptx
file_5.pptxfile_5.pptx
file_5.pptx
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
TableDrivenProg_20160714
TableDrivenProg_20160714TableDrivenProg_20160714
TableDrivenProg_20160714
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
0-1 knapsack problem
0-1 knapsack problem0-1 knapsack problem
0-1 knapsack problem
 
Problem descriptionThe Jim Thornton Coffee House chain is .docx
Problem descriptionThe Jim Thornton Coffee House chain is .docxProblem descriptionThe Jim Thornton Coffee House chain is .docx
Problem descriptionThe Jim Thornton Coffee House chain is .docx
 
Power of authomata
Power of authomataPower of authomata
Power of authomata
 
Ch8b
Ch8bCh8b
Ch8b
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 

Recently uploaded

一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
eoxhsaa
 
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
z6osjkqvd
 
How To Control IO Usage using Resource Manager
How To Control IO Usage using Resource ManagerHow To Control IO Usage using Resource Manager
How To Control IO Usage using Resource Manager
Alireza Kamrani
 
一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理
keesa2
 
社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .
NABLAS株式会社
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
ytypuem
 
Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)
GeorgiiSteshenko
 
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
oaxefes
 
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service LucknowCall Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
hiju9823
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
nyvan3
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
Vineet
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
dataschool1
 
06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus
Timothy Spann
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
eudsoh
 
SAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content DocumentSAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content Document
newdirectionconsulta
 
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
yuvarajkumar334
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
hyfjgavov
 
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
ywqeos
 
Template xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptxTemplate xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptx
TeukuEriSyahputra
 
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdfreading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
perranet1
 

Recently uploaded (20)

一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
 
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
一比一原版英属哥伦比亚大学毕业证(UBC毕业证书)学历如何办理
 
How To Control IO Usage using Resource Manager
How To Control IO Usage using Resource ManagerHow To Control IO Usage using Resource Manager
How To Control IO Usage using Resource Manager
 
一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理一比一原版悉尼大学毕业证如何办理
一比一原版悉尼大学毕业证如何办理
 
社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
 
Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)Telemetry Solution for Gaming (AWS Summit'24)
Telemetry Solution for Gaming (AWS Summit'24)
 
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
 
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service LucknowCall Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
 
06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus06-18-2024-Princeton Meetup-Introduction to Milvus
06-18-2024-Princeton Meetup-Introduction to Milvus
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
 
SAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content DocumentSAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content Document
 
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
 
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
 
Template xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptxTemplate xxxxxxxx ssssssssssss Sertifikat.pptx
Template xxxxxxxx ssssssssssss Sertifikat.pptx
 
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdfreading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
reading_sample_sap_press_operational_data_provisioning_with_sap_bw4hana (1).pdf
 

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.