<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Deepika on Medium]]></title>
        <description><![CDATA[Stories by Deepika on Medium]]></description>
        <link>https://medium.com/@maildeepikasivakumar?source=rss-c490f2389628------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2XyxlisGsfPMluHJXwtT-Q.jpeg</url>
            <title>Stories by Deepika on Medium</title>
            <link>https://medium.com/@maildeepikasivakumar?source=rss-c490f2389628------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 31 May 2026 18:43:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maildeepikasivakumar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Dynamic Programming — A collection]]></title>
            <link>https://medium.com/@maildeepikasivakumar/dynamic-programming-a-collection-11bc254eaa8c?source=rss-c490f2389628------2</link>
            <guid isPermaLink="false">https://medium.com/p/11bc254eaa8c</guid>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Deepika]]></dc:creator>
            <pubDate>Thu, 19 Dec 2024 03:01:40 GMT</pubDate>
            <atom:updated>2024-12-19T03:01:40.435Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dynamic Programming — A collection</h3><p>A collection of algorithms for problems using dynamic programming</p><ul><li><a href="https://medium.com/@maildeepikasivakumar/dynamic-programming-an-introduction-0c0c73d7e8d9">Dynamic Programming — An introduction</a></li><li><a href="https://medium.com/@maildeepikasivakumar/dynamic-programming-maximum-contiguous-subsequence-sum-546782f493d7">Dynamic Programming — Maximum Contiguous Subsequence Sum</a></li><li><a href="https://medium.com/@maildeepikasivakumar/dynamic-programming-longest-increasing-subsequence-aa759dba64a7">Dynamic Programming — Longest Increasing Subsequence</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11bc254eaa8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic Programming — Longest Increasing Subsequence]]></title>
            <link>https://medium.com/@maildeepikasivakumar/dynamic-programming-longest-increasing-subsequence-aa759dba64a7?source=rss-c490f2389628------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa759dba64a7</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Deepika]]></dc:creator>
            <pubDate>Mon, 16 Dec 2024 23:42:29 GMT</pubDate>
            <atom:updated>2024-12-16T23:42:29.049Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dynamic Programming — Longest Increasing Subsequence</h3><h4>Let us find the longest increasing subsequence using dynamic programming.</h4><p>We are going to solve yet another DP problem using the strategies we discussed in the previous post. If you haven’t, I strongly recommend you read my introduction post <a href="https://medium.com/@maildeepikasivakumar/dynamic-programming-an-introduction-0c0c73d7e8d9">here</a>, so it is easy to follow the slang.</p><h4>Problem Definition (DPV, chapter 6.2)</h4><p>We are given an array of numbers. A subsequence is a subset of these numbers taken in order, they can be consecutive or non-consecutive. An increasing subsequence is where the numbers are getting <strong><em>strictly larger</em></strong>. Our goal here is to find the length of the longest increasing subsequence.</p><p>Example: A = [5, -3, 7, 1, 10, 2, 3, -8]. Subsequence here are [5, 2, -8], [-3, 7, 1], [5, -8], etc. Increasing subsequences here are [5, 7, 10] , [2, 3],etc.</p><p><strong><em>Input: </em></strong>Array of n numbers A = a1, a2,…. an</p><p><strong><em>Output:</em></strong> Length of longest increasing subsequence.</p><h4>Solution</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iCKzu1TohQugLHujLBVmpQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TZVkwiQGft8d0BeFZysBgg.jpeg" /><figcaption>Longest Increasing Subsequence solution — Image by Author</figcaption></figure><p>From this, let us identify the recurring theme and crack the questions.</p><p>L[i] = Length of the maximum increasing subsequence until ith position, ending with element A[i].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ig9i3gGW6KkGwGIRa4YR1Q.jpeg" /><figcaption>Longest Increasing Subsequence, questions cracked — Image by Author</figcaption></figure><p>At last, we find the output by finding at which position i, maximum length was yielded. (Note: The max length need not always be at the last position. In our example, it is at i=6, LIS length = 4, LIS = [-3, 1, 2, 3].</p><h4>Algorithm</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FIrxTE-XdukCeZIDXu5B_A.jpeg" /><figcaption>LIS DP Algorithm — Image by Author</figcaption></figure><p><strong><em>Time complexity :</em></strong> O(n²)</p><p>Footnote: If you still don’t get DP don’t worry, Sheldon Cooper wouldn’t get it in his first try! Keep on reading, practicing and asking questions!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4XYBUYXr_Tf_wTfz4noQog.jpeg" /></figure><h4>Citations:</h4><p>Dasgupta, Sanjoy, et al. <em>Algorithms</em>. McGraw-Hill Higher Education, 2008.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa759dba64a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic Programming — Maximum Contiguous Subsequence Sum]]></title>
            <link>https://medium.com/@maildeepikasivakumar/dynamic-programming-maximum-contiguous-subsequence-sum-546782f493d7?source=rss-c490f2389628------2</link>
            <guid isPermaLink="false">https://medium.com/p/546782f493d7</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <dc:creator><![CDATA[Deepika]]></dc:creator>
            <pubDate>Mon, 16 Dec 2024 23:40:56 GMT</pubDate>
            <atom:updated>2024-12-16T23:41:36.478Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dynamic Programming — Maximum Contiguous Subsequence Sum</h3><h4>Let us find the maximum sum yielded by a contiguous subsequence using dynamic programming.</h4><p>If you have not already, I highly recommend reading the introduction to Dynamic Programming <a href="https://medium.com/@maildeepikasivakumar/dynamic-programming-an-introduction-0c0c73d7e8d9">here</a>.</p><h4>Problem definition <em>(DPV, Chapter 6.1)</em></h4><p>A contiguous subsequence of a list S is a subsequence made up of consecutive elements of S.</p><p>For instance, if S is: 5, 15, -30, 10, -5, 40, 10 . Then 15, -30, 10 is a contiguous subsequence but 5, 15, 40 is not.</p><p><strong><em>Input:</em></strong> A list of numbers, a1, a2, …, an</p><p><strong><em>Output:</em></strong> The contiguous subsequence with the maximum sum and the sum (a subsequence of length zero has sum zero)</p><p>For the preceding example, the answer would be 10, -5, 40, 10, with a sum of 55.</p><h4>Let’s brute force the bits and bytes out of it!</h4><p>We iterate over each element, iterate over the rest and find the sum of the subsequences, finding the maximum of all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fdtjf-C34L9Np5m9nslGjg.jpeg" /><figcaption>MCSS brute force — Image by Author</figcaption></figure><p>The time complexity is through the roof, and who wants O(n^2) if we can do linear ?</p><h4>Dynamic Programming to the rescue</h4><p>As always,</p><ol><li>Let’s place our input and output arrays on the saucepan.</li><li>Find the optimal solution at that juncture.</li><li>Ask THE perfect questions (secret ingredient)!</li><li>Trust the guys before us with our life and turn off the stove.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*05cE3odC-DDFvX3Cif0uow.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gYcFUsoDpIi-v0M2kkHBfg.jpeg" /><figcaption>MCSS DP solution — Image by Author</figcaption></figure><p>From this, we can identify the recurring theme and crack the questions.</p><p>Let us define, S[i] = Maximum sum yielded by contiguous subsequence until ith position, ending with element A[i].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n00G97T9a9LCAZvZEfe-CQ.jpeg" /><figcaption>MCSS equation and questions —Image by Author</figcaption></figure><p>At last, we find the output by finding at which position i, maximum sum was yielded. (Note: The max sum need not always be at the last position. Imagine instead of A[n] = 10, what if it was A[n] = -5, S[n] would be 40. Then the overall max sum is 45, yielded by {10, -5, 40}, ending at i=5)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*A05I9TIYrbkwIj-wkhIa2w.jpeg" /><figcaption>MCSS Dynamic Programming Algorithm — Image by Author</figcaption></figure><p>And that’s solving maximum contiguous subsequence sum in O(n) linear time, done and dusted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*2xB36qYxf9p_APcBtju0-g.jpeg" /><figcaption>Calvin and Hobbes by Bill Watterson</figcaption></figure><h4>Citations:</h4><p>Dasgupta, Sanjoy, et al. <em>Algorithms</em>. McGraw-Hill Higher Education, 2008.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=546782f493d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic Programming — An introduction]]></title>
            <link>https://medium.com/@maildeepikasivakumar/dynamic-programming-an-introduction-0c0c73d7e8d9?source=rss-c490f2389628------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c0c73d7e8d9</guid>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Deepika]]></dc:creator>
            <pubDate>Mon, 16 Dec 2024 23:39:42 GMT</pubDate>
            <atom:updated>2024-12-19T03:05:06.337Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dynamic Programming — An introduction</h3><h4>Are you intimidated by dynamic programming? Then this post will help you ask out DP for a cup of coffee!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*KomsAstR8u7vveFEO3_7XQ.jpeg" /><figcaption>Image by Author</figcaption></figure><p>Dynamic programming or DP is a household name for Computer Science students. It is tagged as one of the most difficult algorithmic techniques to learn and naturally is one heavily weighted topic in Algorithm courses. So, no wonder students curse DP!</p><p><strong><em>So, what is with all the hype with Dynamic Programming?</em></strong></p><p>It is an algorithmic technique where you solve a complex problem, by breaking it down into smaller sub-problems, and then find optimal solutions which would lead us to the optimal solution for the larger problem. At least, this is what it is according to <a href="https://en.wikipedia.org/wiki/Dynamic_programming">Wikipedia</a>.</p><p><strong><em>But what I learned behind all this jargon?</em></strong></p><p>I found that the foundation for DP is TRUST! Its not the regular trust. In the world of DP, as a sub-problem, you are trusting the guy before you as if your life depended on it!</p><p>However, it doesn’t end there, there is one more secret ingredient attached. Read more to find out!</p><p><strong><em>Let us look at an effortless example to understand trust here!</em></strong></p><p>There is a problem at hand, where we are supposed to construct a humungous(miles long!) perfect square. Imagine, I decide to break this down, out of the assumption that if I can make a 100 perfect small squares, keep joining them together and make bigger ones and at last I will get my one <em>Bigg </em>square.</p><p>Do you see where I am getting to? If I were to say with 100% confidence that the large square(<em>complex problem</em>) is THE perfect one, it means I trust the smaller guys(<em>sub-problems</em>) that make up this square to be perfect(<em>optimal</em>) ones! See, how I cleverly injected the jargon back!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YglVDrOHCQXBX5GVB75rAw.jpeg" /><figcaption>Dynamic Programming is unforgiving — Quote by <a href="https://en.wikiquote.org/wiki/George_Santayana">George Santayana</a>.</figcaption></figure><p>Let us dive into an actual DP problem!</p><h3>Finding the nth Fibonacci number</h3><p>Every number in the Fibonacci sequence except the first two, can be given by the sum of the previous two numbers.</p><p>Eg: 0, 1, 1(0+1), 2(1+1), 3(1+2), 5(2+3), 8(3+5), 13(5+8)…</p><p>Here, we have broken the task into smaller sub-problems where we iteratively calculate from 1 until n. When we reach n, all we need is n-1 and n-2. n is trusting his peers n-1 and n-2 that they did their job optimally of finding Fib(n-1) and Fib(n-2) and now that he can use their solution to give his final optimal solution Fib(n).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y__efewzxeWZE4YY0KvtaQ.jpeg" /><figcaption>Fibonacci algorithm — Image by Author.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LbNY8rs-CsMPXT27TBR74Q.jpeg" /><figcaption>Fibonaccis building trust on each other — Image by author.</figcaption></figure><h3>The secret ingredient!</h3><p>Though we trust the previous guys to have done their job well, they have found the optimal solution until their point. But that need not be what is right when we have to figure out what is best for us. So, we ask questions!</p><p>For every DP problem that I have solved until now, I did so only because I was able to crack THE perfect question(s) to ask! Cracking that is all that matters, the rest will follow you to your grave.</p><p>Whenever you’re struggling to crack the question, remember,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ZHs8wzx-Uo12AuuAca7nCg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c0c73d7e8d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>