mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-23 21:32:09 +08:00
Documentation for fb5e00f5fb
This commit is contained in:
@@ -136,7 +136,7 @@ Functions</h2></td></tr>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>Implementation of <a href="https://en.wikipedia.org/wiki/Knapsack_problem">0-1 Knapsack Problem</a> </p>
|
||||
<p>Given weights and values of n items, put these items in a knapsack of capacity <code>W</code> to get the maximum total value in the knapsack. In other words, given two integer arrays <code>val[0..n-1]</code> and <code>wt[0..n-1]</code> 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 <code>val[]</code> 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)</p>
|
||||
<h3><a class="anchor" id="autotoc_md48"></a>
|
||||
<h3><a class="anchor" id="autotoc_md49"></a>
|
||||
Algorithm</h3>
|
||||
<p>The idea is to consider all subsets of items and calculate the total weight and value of all subsets. Consider the only subsets whose total weight is smaller than <code>W</code>. From all such subsets, pick the maximum value subset.</p>
|
||||
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/Anmol3299">Anmol</a> </dd>
|
||||
|
||||
@@ -132,7 +132,7 @@ Functions</h2></td></tr>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>Implementation of <a href="https://en.wikipedia.org/wiki/Kadane%27s_algorithm">Kadane Algorithm</a> </p>
|
||||
<p>Kadane algorithm is used to find the maximum sum subarray in an array and maximum sum subarray problem is the task of finding a contiguous subarray with the largest sum</p>
|
||||
<h3><a class="anchor" id="autotoc_md52"></a>
|
||||
<h3><a class="anchor" id="autotoc_md53"></a>
|
||||
Algorithm</h3>
|
||||
<p>The simple idea of the algorithm is to search for all positive contiguous segments of the array and keep track of maximum sum contiguous segment among all positive segments(curr_sum is used for this) Each time we get a positive sum we compare it with max_sum and update max_sum if it is greater than curr_sum</p>
|
||||
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/ayush523">Ayush Singh</a> </dd></dl>
|
||||
|
||||
Reference in New Issue
Block a user