<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Dynamic Programming</title>
	<atom:link href="http://blog.srinivasan.biz/software/dynamic-programming/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.srinivasan.biz/software/dynamic-programming</link>
	<description>Random musings</description>
	<lastBuildDate>Tue, 07 Sep 2010 08:33:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Vishesh</title>
		<link>http://blog.srinivasan.biz/software/dynamic-programming/comment-page-1#comment-9400</link>
		<dc:creator>Vishesh</dc:creator>
		<pubDate>Wed, 14 Jul 2010 11:08:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.srinivasan.biz/?p=585#comment-9400</guid>
		<description>&lt;p&gt;Hi Babu,
I would also recommend &lt;a href=&quot;http://people.csail.mit.edu/bdean/6.046/dp/&quot; rel=&quot;nofollow&quot;&gt;Dynamic Programming Practice Problems&lt;/a&gt; for understanding DP. It has flash videos of some common DP problems such as Balanced Partition problem explained in a lucid manner.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Babu,
I would also recommend <a href="http://people.csail.mit.edu/bdean/6.046/dp/" rel="nofollow">Dynamic Programming Practice Problems</a> for understanding DP. It has flash videos of some common DP problems such as Balanced Partition problem explained in a lucid manner.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Sivers</title>
		<link>http://blog.srinivasan.biz/software/dynamic-programming/comment-page-1#comment-8539</link>
		<dc:creator>Derek Sivers</dc:creator>
		<pubDate>Thu, 13 May 2010 18:03:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.srinivasan.biz/?p=585#comment-8539</guid>
		<description>&lt;p&gt;Hi Babu.  I&#039;m a fan of your blog and writing, but especially impressed with the intelligent discussion you continue in your comments.&lt;/p&gt;

&lt;p&gt;Thanks for keeping this blog.  It&#039;s very inspiring.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Babu.  I&#8217;m a fan of your blog and writing, but especially impressed with the intelligent discussion you continue in your comments.</p>

<p>Thanks for keeping this blog.  It&#8217;s very inspiring.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Babu Srinivasan</title>
		<link>http://blog.srinivasan.biz/software/dynamic-programming/comment-page-1#comment-7260</link>
		<dc:creator>Babu Srinivasan</dc:creator>
		<pubDate>Sun, 04 Apr 2010 05:06:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.srinivasan.biz/?p=585#comment-7260</guid>
		<description>&lt;p&gt;Neil,
  Raveendra also mentioned this. It is a start by Stanford but they have a long way to go. I would call it Open Sample Ware as they have only 10 courses.&lt;/p&gt;

&lt;p&gt;Programming Methodology&lt;/p&gt;

&lt;p&gt;Programming Abstractions&lt;/p&gt;

&lt;p&gt;Programming Paradigms&lt;/p&gt;

&lt;p&gt;Introduction to Robotics&lt;/p&gt;

&lt;p&gt;Natural Language Processing&lt;/p&gt;

&lt;p&gt;Machine Learning&lt;/p&gt;

&lt;p&gt;The Fourier Transform and its Applications&lt;/p&gt;

&lt;p&gt;Introduction to Linear Dynamical Systems&lt;/p&gt;

&lt;p&gt;Convex Optimization I&lt;/p&gt;

&lt;p&gt;Convex Optimization II&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Neil,
  Raveendra also mentioned this. It is a start by Stanford but they have a long way to go. I would call it Open Sample Ware as they have only 10 courses.</p>

<p>Programming Methodology</p>

<p>Programming Abstractions</p>

<p>Programming Paradigms</p>

<p>Introduction to Robotics</p>

<p>Natural Language Processing</p>

<p>Machine Learning</p>

<p>The Fourier Transform and its Applications</p>

<p>Introduction to Linear Dynamical Systems</p>

<p>Convex Optimization I</p>

<p>Convex Optimization II</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Neil</title>
		<link>http://blog.srinivasan.biz/software/dynamic-programming/comment-page-1#comment-7180</link>
		<dc:creator>Neil</dc:creator>
		<pubDate>Thu, 01 Apr 2010 00:24:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.srinivasan.biz/?p=585#comment-7180</guid>
		<description>&lt;p&gt;here it is:
http://see.stanford.edu/see/courses.aspx&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>here it is:
<a href="http://see.stanford.edu/see/courses.aspx" rel="nofollow">http://see.stanford.edu/see/courses.aspx</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://blog.srinivasan.biz/software/dynamic-programming/comment-page-1#comment-6978</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Fri, 19 Mar 2010 17:57:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.srinivasan.biz/?p=585#comment-6978</guid>
		<description>&lt;p&gt;Here is the memoization optimized version in PHP:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;
&lt;?
## 0-1 Knapsack Problem Solve (with memoization optimization)
# $w = weight of item
# $v = value of item
# $i = index
# $aW = Available Weight
# $m = memo array

function knapSolveFast($w,$v,$i,$aW,$m) {

    global $numcalls, $m;
    $numcalls ++;
    // echo &quot;Called with i=$i, aW=$aW&quot;;

    // Return memo if we have one
    if (isset($m[$i][$aW])) {
        return $m[$i][$aW];
    } else {

        if ($i == 0) {
            if ($w[$i]  $aW) {
            $m[$i][$aW] = $without_i;
            return $without_i;
        } else {
            $with_i = $v[$i] + knapSolveFast($w, $v, ($i-1), ($aW - $w[$i]),$m);
            $res = max($with_i, $without_i); 
            $m[$i][$aW] = $res;
            return $res;
        }   
    }
}


$w3 = array(1, 1, 1, 2, 2, 2, 4, 4, 4, 44, 96, 96, 96);
$v3 = array(1, 1, 1, 2, 2, 2, 4, 4, 4, 44, 96, 96, 96);

$numcalls = 0;
$m = array();
$m3 = knapSolveFast($w3, $v3, sizeof($v3) -1, 54,$m);
print_r($w3); echo &quot;&quot;;
echo &quot;&lt;b&gt;Max: $m3&lt;/b&gt; ($numcalls calls)&quot;;
?&gt;
&lt;/pre&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Here is the memoization optimized version in PHP:</p>

<p><pre>
&lt;?
## 0-1 Knapsack Problem Solve (with memoization optimization)
# $w = weight of item
# $v = value of item
# $i = index
# $aW = Available Weight
# $m = memo array

function knapSolveFast($w,$v,$i,$aW,$m) {

    global $numcalls, $m;
    $numcalls ++;
    // echo &quot;Called with i=$i, aW=$aW";

    // Return memo if we have one
    if (isset($m[$i][$aW])) {
        return $m[$i][$aW];
    } else {

        if ($i == 0) {
            if ($w[$i]  $aW) {
            $m[$i][$aW] = $without_i;
            return $without_i;
        } else {
            $with_i = $v[$i] + knapSolveFast($w, $v, ($i-1), ($aW - $w[$i]),$m);
            $res = max($with_i, $without_i); 
            $m[$i][$aW] = $res;
            return $res;
        }   
    }
}


$w3 = array(1, 1, 1, 2, 2, 2, 4, 4, 4, 44, 96, 96, 96);
$v3 = array(1, 1, 1, 2, 2, 2, 4, 4, 4, 44, 96, 96, 96);

$numcalls = 0;
$m = array();
$m3 = knapSolveFast($w3, $v3, sizeof($v3) -1, 54,$m);
print_r($w3); echo "";
echo "<b>Max: $m3</b> ($numcalls calls)";
?&gt;
</pre></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://blog.srinivasan.biz/software/dynamic-programming/comment-page-1#comment-6964</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Thu, 18 Mar 2010 19:28:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.srinivasan.biz/?p=585#comment-6964</guid>
		<description>&lt;p&gt;OK I think I was just trying too hard to understand the Java and got discouraged...  The Python example was a lot easier to understand and translate to PHP...&lt;/p&gt;

&lt;p&gt;For those who are interested, here is a direct translation of the first (Python) version above in PHP:&lt;/p&gt;

&lt;p&gt;0-1 Knapsack Problem Solve&lt;/p&gt;

&lt;p&gt;&lt;pre lang=&quot;php&quot; line=&quot;1&quot;&gt;
$w = weight of item
$v = value of item
$i = index
$aW = Available Weight
$numcalls = 0;
function maxVal($w,$v,$i,$aW) {
    global $numcalls;
    $numcalls ++;
    echo &quot;Called with i=$i, aW=$aW&quot;;
    if ($i == 0) {
        if ($w[$i]  $aW) {
            return $without_i;
        } else {
            $with_i = $v[$i] + maxVal($w, $v, ($i-1), ($aW - $w[$i]));
            return max($with_i, $without_i);
        }
}
$w1 = array(5,3,2);
$v1 = array(9,7,8);
$w2 = array( 1,1,5,5,3,3,4,4);
$v2 = array(15,15,10,10,4,4,5,5);
$m1 = maxVal($w1, $v1, sizeof($v1)-1, 5 );
echo &quot;&lt;b&gt;Max: $m1&lt;/b&gt; ($numcalls calls)&quot;;
$numcalls = 0;
$m2 = maxVal($w2, $v2, sizeof($v2) -1, 8 );
echo &quot;&lt;b&gt;Max: $m2&lt;/b&gt; ($numcalls calls)&quot;;
&lt;/pre&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>OK I think I was just trying too hard to understand the Java and got discouraged&#8230;  The Python example was a lot easier to understand and translate to PHP&#8230;</p>

<p>For those who are interested, here is a direct translation of the first (Python) version above in PHP:</p>

<p>0-1 Knapsack Problem Solve</p>

<p>

</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> weight of item
<span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> value of item
<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> index
<span style="color: #000088;">$aW</span> <span style="color: #339933;">=</span> Available Weight
<span style="color: #000088;">$numcalls</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> maxVal<span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span><span style="color: #000088;">$v</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #000088;">$aW</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$numcalls</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$numcalls</span> <span style="color: #339933;">++;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Called with i=<span style="color: #006699; font-weight: bold;">$i</span>, aW=<span style="color: #006699; font-weight: bold;">$aW</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span>  <span style="color: #000088;">$aW</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$without_i</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$with_i</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$v</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> maxVal<span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$v</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$aW</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$w</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #990000;">max</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$with_i</span><span style="color: #339933;">,</span> <span style="color: #000088;">$without_i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$w1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$v1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$w2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$v2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$m1</span> <span style="color: #339933;">=</span> maxVal<span style="color: #009900;">&#40;</span><span style="color: #000088;">$w1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$v1</span><span style="color: #339933;">,</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt;Max: <span style="color: #006699; font-weight: bold;">$m1</span>&lt;/b&gt; (<span style="color: #006699; font-weight: bold;">$numcalls</span> calls)&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$numcalls</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$m2</span> <span style="color: #339933;">=</span> maxVal<span style="color: #009900;">&#40;</span><span style="color: #000088;">$w2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$v2</span><span style="color: #339933;">,</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt;Max: <span style="color: #006699; font-weight: bold;">$m2</span>&lt;/b&gt; (<span style="color: #006699; font-weight: bold;">$numcalls</span> calls)&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://blog.srinivasan.biz/software/dynamic-programming/comment-page-1#comment-6962</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Thu, 18 Mar 2010 18:22:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.srinivasan.biz/?p=585#comment-6962</guid>
		<description>&lt;p&gt;Hi Babu,&lt;/p&gt;

&lt;p&gt;This may be an unusual request, but I&#039;m looking for a &quot;dumbed down&quot; explanation of this algorithm so that I can make a PHP implementation of the 0-1 Knapsack solve.&lt;/p&gt;

&lt;p&gt;I&#039;ve found a number of solutions in various other languages, but none that I am familiar with being primarily a web programmer. One in particular that was ideal for my application was written in Java, and although I recognize some of the control structures, the language primitives are still too foreign for me to make sense of.&lt;/p&gt;

&lt;p&gt;http://www.alesdar.org/oldSite/IS/Knapsack/KnapsackApplet.html&lt;/p&gt;

&lt;p&gt;I need to be able to take a list of items with a weight and value (both positive integers) and return the best optimal combination for a specified maximum weight.  The above linked applet works perfectly for my needs (though I don&#039;t need the additional GA algorithm that it&#039;s comparing against).&lt;/p&gt;

&lt;p&gt;Any help understanding the code or a simplified explanation would be of tremendous assistance.  I will happy post the final PHP code for others encountering the same issue...&lt;/p&gt;

&lt;p&gt;Brian&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Babu,</p>

<p>This may be an unusual request, but I&#8217;m looking for a &#8220;dumbed down&#8221; explanation of this algorithm so that I can make a PHP implementation of the 0-1 Knapsack solve.</p>

<p>I&#8217;ve found a number of solutions in various other languages, but none that I am familiar with being primarily a web programmer. One in particular that was ideal for my application was written in Java, and although I recognize some of the control structures, the language primitives are still too foreign for me to make sense of.</p>

<p><a href="http://www.alesdar.org/oldSite/IS/Knapsack/KnapsackApplet.html" rel="nofollow">http://www.alesdar.org/oldSite.....pplet.html</a></p>

<p>I need to be able to take a list of items with a weight and value (both positive integers) and return the best optimal combination for a specified maximum weight.  The above linked applet works perfectly for my needs (though I don&#8217;t need the additional GA algorithm that it&#8217;s comparing against).</p>

<p>Any help understanding the code or a simplified explanation would be of tremendous assistance.  I will happy post the final PHP code for others encountering the same issue&#8230;</p>

<p>Brian</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Raveendra</title>
		<link>http://blog.srinivasan.biz/software/dynamic-programming/comment-page-1#comment-6255</link>
		<dc:creator>Raveendra</dc:creator>
		<pubDate>Tue, 09 Feb 2010 07:17:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.srinivasan.biz/?p=585#comment-6255</guid>
		<description>&lt;p&gt;Stanford does offer online courses. Check this one. http://see.stanford.edu/see/courses.aspx&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Stanford does offer online courses. Check this one. <a href="http://see.stanford.edu/see/courses.aspx" rel="nofollow">http://see.stanford.edu/see/courses.aspx</a></p>]]></content:encoded>
	</item>
</channel>
</rss>
