SlideShare a Scribd company logo
1 of 10
NADAR SARASWATHI COLLEGE OF ARTS
AND SCIENCE
DEPARTMENT OF COMPUTER SCIENCE
KNAPSACK PROBLEMS
NAME : P.ANUSUYA
CLASS : I-M.SC(CS)
KNAPSACK PROBLEM :
• Given weights and values of n items, put these items in a knapsack of
capacity W to get the maximum total value in the knapsack. In other
words, given two integer arrays val[0..n-1] and wt[0..n-1] which
represent values and weights associated with n items respectively.
Also given an integer W which represents knapsack capacity, find out
the maximum value subset of val[] such that sum of the weights of
this subset is smaller than or equal to W.
• You cannot break an item, either pick the complete item or don’t pick
it (0-1 property).
KNAPSACK PROBLEM EXAMPLE
:
You are given weights and values of N items, put these items in a knapsack of
capacity W to get the maximum total value in the knapsack. Note that we have
only one quantity of each item.
In other words, given two integer arrays val[0..N-1] and wt[0..N-1] which
represent values and weights associated with N items respectively. Also given an
integer W which represents knapsack capacity, find out the maximum value
subset of val[] such that sum of the weights of this subset is smaller than or
equal to W. You cannot break an item, either pick the complete item or don’t pick
it (0-1 property).Complete the function knapSack() which takes maximum
capacity W, weight array wt[], value array val[], and the number of items n as a
parameter and returns the maximum possible value you can get.
EXAMPLE 1&2 :
TRAVELING SALES PROBLEM :
• Given a set of cities and distances between every pair of cities, the problem
is to find the shortest possible route that visits every city exactly once and
returns to the starting point.
• Note the difference between Hamiltonian Cycle and TSP. The Hamiltonian
cycle problem is to find if there exists a tour that visits every city exactly
once. Here we know that Hamiltonian Tour exists (because the graph is
complete) and in fact, many such tours exist, the problem is to find a
minimum weight Hamiltonian Cycle.
• For example, consider the graph shown in the figure on the right side. A TSP
tour in the graph is 1-2-4-3-1. The cost of the tour is 10+25+30+15 which is
80.
• The problem is a famous NP-hard problem. There is no polynomial-time
known solution for this problem.
EFFICIENCY CONSIDERATION :
• The efficiency of an algorithm defines the number of computational resources used by an
algorithm and time taken by an algorithm to produce the desired result.
• An algorithm which takes fewer resources and computes results in a minimum time for a
problem then that algorithm is known as efficient.
• The efficiency of an algorithm defines the number of computational resources used by an
algorithm and time taken by an algorithm to produce the desired result.
• The efficiency of the algorithm is measured based on the usage of different resources and
minimum running time.
• Since every algorithm uses computer resources to run, But to analyze an algorithm,
execution time and internal memory are essential to consider.
•THANK YOU ☺️

More Related Content

Similar to DSA

Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problemharsh kothari
 
Unit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxUnit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxMaryJacob24
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programminghodcsencet
 
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...Abhishek Singh
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmHoneyChintal
 
Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Techglyphs
 
Linear Programming.pptx
Linear Programming.pptxLinear Programming.pptx
Linear Programming.pptxDrBabinDhasD
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsMuthu Vinayagam
 
Beginners Guide to Non-Negative Matrix Factorization
Beginners Guide to Non-Negative Matrix FactorizationBeginners Guide to Non-Negative Matrix Factorization
Beginners Guide to Non-Negative Matrix FactorizationBenjamin Bengfort
 
Deepika(14 mba5012) transportation ppt
Deepika(14 mba5012)  transportation pptDeepika(14 mba5012)  transportation ppt
Deepika(14 mba5012) transportation pptDeepika Bansal
 
transportation-model.ppt
transportation-model.ppttransportation-model.ppt
transportation-model.pptanubhuti18
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERmuthukrishnavinayaga
 
AMA_Assignment Theory notes
AMA_Assignment Theory notesAMA_Assignment Theory notes
AMA_Assignment Theory notesCA Niraj Thapa
 
GREKing: The most repeated type of quants problem.
GREKing: The most repeated type of quants problem.GREKing: The most repeated type of quants problem.
GREKing: The most repeated type of quants problem.Rahul Singh
 

Similar to DSA (20)

Fractional Knapsack Problem
Fractional Knapsack ProblemFractional Knapsack Problem
Fractional Knapsack Problem
 
Unit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptxUnit 3- Greedy Method.pptx
Unit 3- Greedy Method.pptx
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
 
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...0 1 knapsack using naive recursive approach and top-down dynamic programming ...
0 1 knapsack using naive recursive approach and top-down dynamic programming ...
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithm
 
Brute force method
Brute force methodBrute force method
Brute force method
 
Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2
 
Linear Programming.pptx
Linear Programming.pptxLinear Programming.pptx
Linear Programming.pptx
 
Asssignment problem
Asssignment problemAsssignment problem
Asssignment problem
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
 
Beginners Guide to Non-Negative Matrix Factorization
Beginners Guide to Non-Negative Matrix FactorizationBeginners Guide to Non-Negative Matrix Factorization
Beginners Guide to Non-Negative Matrix Factorization
 
Deepika(14 mba5012) transportation ppt
Deepika(14 mba5012)  transportation pptDeepika(14 mba5012)  transportation ppt
Deepika(14 mba5012) transportation ppt
 
transportation-model.ppt
transportation-model.ppttransportation-model.ppt
transportation-model.ppt
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
 
AMA_Assignment Theory notes
AMA_Assignment Theory notesAMA_Assignment Theory notes
AMA_Assignment Theory notes
 
Operations Research Project
Operations Research ProjectOperations Research Project
Operations Research Project
 
Design and analysis of algorithms
Design and analysis of algorithmsDesign and analysis of algorithms
Design and analysis of algorithms
 
Assign transportation
Assign transportationAssign transportation
Assign transportation
 
Av 738- Adaptive Filtering - Background Material
Av 738- Adaptive Filtering - Background MaterialAv 738- Adaptive Filtering - Background Material
Av 738- Adaptive Filtering - Background Material
 
GREKing: The most repeated type of quants problem.
GREKing: The most repeated type of quants problem.GREKing: The most repeated type of quants problem.
GREKing: The most repeated type of quants problem.
 

More from rithika858339

data mining and Whorehousing.pptx
data mining and Whorehousing.pptxdata mining and Whorehousing.pptx
data mining and Whorehousing.pptxrithika858339
 
distribute computing.pptx
distribute computing.pptxdistribute computing.pptx
distribute computing.pptxrithika858339
 
fault tolerance1.pptx
fault tolerance1.pptxfault tolerance1.pptx
fault tolerance1.pptxrithika858339
 
artificial intelligence.pptx
artificial intelligence.pptxartificial intelligence.pptx
artificial intelligence.pptxrithika858339
 
artificial intelligence.pptx
artificial intelligence.pptxartificial intelligence.pptx
artificial intelligence.pptxrithika858339
 
Network information security
Network information securityNetwork information security
Network information securityrithika858339
 
Advance computer architecture
Advance computer architectureAdvance computer architecture
Advance computer architecturerithika858339
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithmrithika858339
 
Network and information security
Network and information securityNetwork and information security
Network and information securityrithika858339
 
Network and information security
Network and information securityNetwork and information security
Network and information securityrithika858339
 
Network and information security
Network and information securityNetwork and information security
Network and information securityrithika858339
 
General method in backtracking
General method in backtrackingGeneral method in backtracking
General method in backtrackingrithika858339
 
Presentation (1).pptx
Presentation (1).pptxPresentation (1).pptx
Presentation (1).pptxrithika858339
 

More from rithika858339 (20)

data mining and Whorehousing.pptx
data mining and Whorehousing.pptxdata mining and Whorehousing.pptx
data mining and Whorehousing.pptx
 
distribute computing.pptx
distribute computing.pptxdistribute computing.pptx
distribute computing.pptx
 
clustering.pptx
clustering.pptxclustering.pptx
clustering.pptx
 
fault tolerance1.pptx
fault tolerance1.pptxfault tolerance1.pptx
fault tolerance1.pptx
 
python.pptx
python.pptxpython.pptx
python.pptx
 
artificial intelligence.pptx
artificial intelligence.pptxartificial intelligence.pptx
artificial intelligence.pptx
 
artificial intelligence.pptx
artificial intelligence.pptxartificial intelligence.pptx
artificial intelligence.pptx
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Network information security
Network information securityNetwork information security
Network information security
 
ACA
ACAACA
ACA
 
CD-1.pptx
CD-1.pptxCD-1.pptx
CD-1.pptx
 
Java JSP.pptx
Java JSP.pptxJava JSP.pptx
Java JSP.pptx
 
CD
CDCD
CD
 
Advance computer architecture
Advance computer architectureAdvance computer architecture
Advance computer architecture
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Network and information security
Network and information securityNetwork and information security
Network and information security
 
Network and information security
Network and information securityNetwork and information security
Network and information security
 
Network and information security
Network and information securityNetwork and information security
Network and information security
 
General method in backtracking
General method in backtrackingGeneral method in backtracking
General method in backtracking
 
Presentation (1).pptx
Presentation (1).pptxPresentation (1).pptx
Presentation (1).pptx
 

Recently uploaded

VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
Spark3's new memory model/management
Spark3's new memory model/managementSpark3's new memory model/management
Spark3's new memory model/managementakshesh doshi
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Data Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationData Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationBoston Institute of Analytics
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 

Recently uploaded (20)

VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
Spark3's new memory model/management
Spark3's new memory model/managementSpark3's new memory model/management
Spark3's new memory model/management
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
Data Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health ClassificationData Science Project: Advancements in Fetal Health Classification
Data Science Project: Advancements in Fetal Health Classification
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...
Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...
Russian Call Girls Dwarka Sector 15 💓 Delhi 9999965857 @Sabina Modi VVIP MODE...
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 

DSA

  • 1. NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE DEPARTMENT OF COMPUTER SCIENCE KNAPSACK PROBLEMS NAME : P.ANUSUYA CLASS : I-M.SC(CS)
  • 2. KNAPSACK PROBLEM : • Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. In other words, given two integer arrays val[0..n-1] and wt[0..n-1] which represent values and weights associated with n items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. • You cannot break an item, either pick the complete item or don’t pick it (0-1 property).
  • 3.
  • 4. KNAPSACK PROBLEM EXAMPLE : You are given weights and values of N items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. Note that we have only one quantity of each item. In other words, given two integer arrays val[0..N-1] and wt[0..N-1] which represent values and weights associated with N items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item or don’t pick it (0-1 property).Complete the function knapSack() which takes maximum capacity W, weight array wt[], value array val[], and the number of items n as a parameter and returns the maximum possible value you can get.
  • 6.
  • 7. TRAVELING SALES PROBLEM : • Given a set of cities and distances between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns to the starting point. • Note the difference between Hamiltonian Cycle and TSP. The Hamiltonian cycle problem is to find if there exists a tour that visits every city exactly once. Here we know that Hamiltonian Tour exists (because the graph is complete) and in fact, many such tours exist, the problem is to find a minimum weight Hamiltonian Cycle. • For example, consider the graph shown in the figure on the right side. A TSP tour in the graph is 1-2-4-3-1. The cost of the tour is 10+25+30+15 which is 80. • The problem is a famous NP-hard problem. There is no polynomial-time known solution for this problem.
  • 8.
  • 9. EFFICIENCY CONSIDERATION : • The efficiency of an algorithm defines the number of computational resources used by an algorithm and time taken by an algorithm to produce the desired result. • An algorithm which takes fewer resources and computes results in a minimum time for a problem then that algorithm is known as efficient. • The efficiency of an algorithm defines the number of computational resources used by an algorithm and time taken by an algorithm to produce the desired result. • The efficiency of the algorithm is measured based on the usage of different resources and minimum running time. • Since every algorithm uses computer resources to run, But to analyze an algorithm, execution time and internal memory are essential to consider.