<?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 Majithia Khushbu on Medium]]></title>
        <description><![CDATA[Stories by Majithia Khushbu on Medium]]></description>
        <link>https://medium.com/@majithiakhushbu29?source=rss-2592db7c7f73------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*t1O1gsigyHojVGHk2e80xQ.jpeg</url>
            <title>Stories by Majithia Khushbu on Medium</title>
            <link>https://medium.com/@majithiakhushbu29?source=rss-2592db7c7f73------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:54:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@majithiakhushbu29/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[0/1 KNAPSACK USING DYNAMIC PROGRAMMING]]></title>
            <link>https://medium.com/@majithiakhushbu29/0-1-knapsack-using-dynamic-programming-38eb93f1fa0f?source=rss-2592db7c7f73------2</link>
            <guid isPermaLink="false">https://medium.com/p/38eb93f1fa0f</guid>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Majithia Khushbu]]></dc:creator>
            <pubDate>Fri, 23 Aug 2019 10:31:34 GMT</pubDate>
            <atom:updated>2019-08-23T10:39:19.458Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>WHAT IS DYNAMIC PROGRAMMING ??</strong></h3><p>Like divide-and-conquer method, Dynamic Programming solves problems by combining the solutions of <strong>sub problems.</strong> Moreover, Dynamic Programming algorithm solves each sub-problem just once and then saves its answer in a table, thereby <strong>avoiding the work of re-computing the answer every time.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*noM56L6tENEJEz72.png" /></figure><p>THUS, IT <strong>ALWAYS GIVES OPTIMAL RESULT UNLIKE THE GREEDY METHOD.</strong></p><p>NOW LET US SEE WHAT IS A <strong>KNAPSACK</strong> PROBLEM</p><p>In it, I have a knapsack bag with some capacity and some items with their respective weights and values and I have to fill this knapsack bag with these items with <strong>maximum value</strong> in such a manner that the <strong>total weight of the items chosen should not be greater than the capacity of the knapsack.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*Y9g8MU5BSDD203NoDo71Fw.png" /></figure><p>Here I am discussing its type <strong>0/1 knapsack</strong> where an <strong>item cannot be broken</strong> which means we should take the item <strong>as a whole or should leave</strong> it unlike its other type <strong>fractional knapsack</strong> where <strong>part of an item</strong> can be taken.</p><p>It is solved using dynamic programming because solving it using greedy programming does<strong> not give optimal solution.</strong></p><h3>HOW TO SOLVE A KNAPSACK PROBLEM ???</h3><p>Consider we are given-</p><ul><li>A knapsack of weight capacity ‘w’</li><li>’n’ number of items each having some weight and value</li></ul><h4><strong>Step-01:</strong></h4><ul><li>Draw a table say ‘T’ with (n+1) number of rows and (w+1) number of columns.</li><li>Fill all the boxes of 0th row and 0th column with zeroes as shown-</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*faRLASenJesQa2bUeDJwOQ.png" /></figure><h4>Step-02:</h4><ul><li>Start filling the table row wise top to bottom from left to right.</li><li>Use the following formula-</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*E2kmzmpOLSse6HN3BI1Vfw.png" /></figure><p>T(i , j) = maximum value of the selected items if we can take items 1 to i and we have weight restrictions of j.</p><h4>Step-03:</h4><p>After filling the table completely, value of the last box represents the maximum possible value that be put in the knapsack.</p><h4>Step-04:</h4><p>To identify the items that must be put in the knapsack to obtain the maximum profit,</p><ul><li>Considering the last column of the table, start scanning the entries from bottom to top.</li><li>If an entry is encountered whose value is not same as the value which is stored in the entry immediately above it, then mark the row label of that entry.</li><li>After scanning all the entries, the marked labels represent the items that must be put in the knapsack.</li></ul><p><strong>Let us understand it through an example</strong></p><p>For the given set of items and<strong> knapsack capacity = 5 kg</strong>, find the optimal solution for the 0/1 knapsack problem making use of dynamic programming approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*s6Pm-rXLsEz5ukt_2YLBkA.png" /></figure><h4><strong>SOLUTION:-</strong></h4><h4>Given-</h4><ul><li>Knapsack capacity (w) = 5 kg</li><li>Number of items (n) = 4</li></ul><h4>Step-01:</h4><ul><li>Draw a table say ‘T’ with (n+1) = 4 + 1 = 5 number of rows and (w+1) = 5 + 1 = 6 number of columns.</li><li>Fill all the boxes of 0th row and 0th column with 0.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*YltZRMfqJ0ssmderdUNMUw.png" /></figure><h4>Step-02:</h4><p>Start filling the table row wise top to bottom from left to right using the formula-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*E2kmzmpOLSse6HN3BI1Vfw.png" /></figure><h4><strong>FINAL SOLUTION:-</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*7ObO8ny2M2KRmumT5o3QOw.png" /></figure><ul><li>The last entry represents the maximum possible value that can be put in the knapsack.</li><li>Thus, maximum possible value that can be put in the knapsack = <strong>7</strong></li></ul><h4>Identifying the items that must be put in the knapsack-</h4><ul><li>Considering the last column, start scanning the entries from bottom to top.</li><li>If an entry is encountered whose value is not same as the value which is stored in the entry immediately above it, then mark the label of row of that entry.</li></ul><p>Following this,</p><ul><li>We mark the rows labelled “1” and “2”.</li><li>Thus, items that must be put in the knapsack to obtain the maximum value 7 are-</li></ul><p><strong>Item-1 and Item-2</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*6JUN8FOVbj2XBiCH1JUbEg.png" /></figure><p>Thus we have got an optimal solution by getting no loss.</p><h3>Time Complexity-</h3><ul><li>It takes <strong>θ(nw)</strong> time to <strong>fill (n+1)(w+1) table entries</strong> where each entry takes constant time <strong>θ(1)</strong> for its <strong>computation</strong>.</li><li>It takes <strong>θ(n)</strong> time for <strong>tracing</strong> the solution as the tracing process traces the n rows starting from row n and then moving up by 1 row at every step.</li><li>Thus, overall <strong>θ(nw)</strong> time is taken to solve 0/1 knapsack problem using dynamic programming approach.</li></ul><h3>THANK YOU :)</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38eb93f1fa0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GREEDY METHOD IN DAA]]></title>
            <link>https://medium.com/@majithiakhushbu29/greedy-method-in-daa-4ae8aab7fdf3?source=rss-2592db7c7f73------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ae8aab7fdf3</guid>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Majithia Khushbu]]></dc:creator>
            <pubDate>Fri, 23 Aug 2019 09:33:02 GMT</pubDate>
            <atom:updated>2019-09-09T02:10:58.601Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong><em>GREEDY METHOD IN DATA ANALYSIS AND ALGORITHMS</em></strong></h3><blockquote>Different algorithmic problems require different technique as its solution which can be one of the following:-</blockquote><blockquote>1. Divide and conquer</blockquote><blockquote>2. Randomized algorithms</blockquote><blockquote>3. Greedy algorithms</blockquote><blockquote>4. Dynamic programming</blockquote><blockquote>But among all these algorithmic approaches, the simplest and straightforward approach is the <strong>Greedy method. </strong>In this approach, the decision is taken on the basis of current available information without worrying about the effect of the current decision in future AND THAT IS THE REASON WHY GREEDY ALGORITHM<strong> <em>DOES NOT GIVE AN OPTIMAL SOLUTION.</em></strong></blockquote><p><em>It always makes the choice that seems to be the best at that moment which means that it makes a </em><strong><em>locally-optimal choice</em></strong><em> in the hope that this choice will lead to a globally-optimal solution.</em></p><p><strong>IT NEVER RECONSIDERS THE CHOICE TAKEN PREVIOUSLY.</strong></p><p><em>Let us understand this approach using the example of </em><strong><em>MINIMUM SPANNING TREE</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*wfwoKqGXEl7_ZQQkO3O5fQ.png" /></figure><p><em>Here, in order to find the shortest distance, we use greedy method, i.e. at any given point, we find the shortest distance from among the current node to all of its connected nodes and choose that path and finally we are able to traverse all the nodes with the minimum distance at the end.</em></p><p><strong>ADVANTAGES:-</strong></p><p>· <em>Easy to implement</em></p><p><em>· Faster to execute</em></p><p><em>Now, let us see where the greedy method </em><strong><em>FAILS </em></strong><em>to give the optimal solution</em></p><ol><li><em>It completely fails in </em><strong><em>TRAVELLING SALESMAN PROBLEM </em></strong><em>because in the greed of choosing the shortest path, it ultimately ends up in travelling more distance.</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*HlEMSbYBwwq-BZqUz9Ropw.png" /></figure><p>2.<em> In case of the </em><strong><em>KNAPSACK</em></strong><em> problem</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*0TLv91LCQ_prnyreNZZDng.png" /></figure><p><em>Suppose my Knapsack bag’s capacity is </em><strong><em>4 KG</em></strong><em>, then ideally I should choose </em><strong><em>items B and C</em></strong><em> where I could get </em><strong><em>total value of 2</em></strong><em> but using greedy method, it will choose </em><strong><em>item A </em></strong><em>as it is the first item to be considered and its weight is less than the bag’s capacity and now I will get </em><strong><em>total value as 1.65</em></strong><em>. SO I WILL NOW HAVE </em><strong><em>LOSS OF 1 KG.</em></strong></p><p><strong>APPLICATIONS OF GREEDY METHOD:-</strong></p><ol><li><em>Dijkstra’s algorithm for finding shortest path to all nodes given a start node</em></li><li><em>Prim’s algorithm for finding a minimum spanning tree</em></li><li><em>Huffman trees for data compression</em></li><li><em>Job sequencing with deadline</em></li><li><em>Breath First Traversal</em></li></ol><h3><strong>THANK YOU:)</strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ae8aab7fdf3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>