<?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 Dhruvi on Medium]]></title>
        <description><![CDATA[Stories by Dhruvi on Medium]]></description>
        <link>https://medium.com/@dhruvi01231?source=rss-4fb0e00acf89------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Dhruvi on Medium</title>
            <link>https://medium.com/@dhruvi01231?source=rss-4fb0e00acf89------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:40:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dhruvi01231/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[Prim's Algorithm]]></title>
            <link>https://medium.com/@dhruvi01231/prims-algorithm-f827e93926ac?source=rss-4fb0e00acf89------2</link>
            <guid isPermaLink="false">https://medium.com/p/f827e93926ac</guid>
            <dc:creator><![CDATA[Dhruvi]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 19:15:05 GMT</pubDate>
            <atom:updated>2019-09-04T19:15:05.723Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Prim&#39;s Algorithm</strong></p><p>In this article we see prime’s algorithm.</p><p>Prim’s algorithm is a minimum<a href="https://en.wikipedia.org/wiki/Minimum_spanning_tree"> </a>spanning tree algorithm that takes a graph as input and finds the subset of the edges of that graph which</p><ul><li>form a tree that includes every vertex</li><li>has the minimum sum of weights among all the trees that can be formed from the graph</li></ul><p>The steps for implementing Prim&#39;s algorithm are as follows:</p><p>Initialize the minimum spanning tree with a vertex chosen at random.Find all the edges that connect the tree to new vertices, find the minimum and add it to the treeKeep repeating step 2 until we get a minimum spanning tree.</p><p>We can see the example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*ctOJ38PyWjSI3kRoh6H_VQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*grlnmmo_W_L93uAr_J0woA.png" /></figure><p>Total Cost = 10 + 25 + 22 + 12 + 16 + 14</p><p>= 99</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f827e93926ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Knapsack problem using Greedy method.]]></title>
            <link>https://medium.com/@dhruvi01231/knapsack-problem-using-greedy-method-b576ea9702b5?source=rss-4fb0e00acf89------2</link>
            <guid isPermaLink="false">https://medium.com/p/b576ea9702b5</guid>
            <dc:creator><![CDATA[Dhruvi]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 18:52:48 GMT</pubDate>
            <atom:updated>2019-09-04T18:52:48.100Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Knapsack problem using Greedy method.</strong></p><p>In this article I am going to explain you about knapsack problem and how to get optimal solution.</p><p>What is a knapsack problem?</p><p>The knapsack problem is a problem in which we are given a set of items,each with weight and a value,determine the number of each item to include in a collection so that the total weight is less than or equal to given limit and the total value is as large as possible.</p><p>knapsack problem comes under two categories</p><p>0/1 knapsack problemFractional</p><p>knapsack problem</p><p>We cannot get optimal solution in 0/1 knapsack using Greedy method.But Greedy method will always provide an optimal solution with fractional knapsack problem</p><p>Now ,Let us see the example for the Fractional knapsack problem using Greedy method</p><p>Let us consider that the capacity of the knapsack is W=60 and the list of provided items are shown below.</p><p>Item- A B C D</p><p>Value- 180 100 120 120</p><p>Weight- 30 10 20 24</p><p>Ratio (v/w)- 6 10 6 5</p><p>next the items should be sorted in descending order on the basis of ratio of value by weight in order to get maximum profit .</p><p>resultant values are</p><p>Item- A B C D</p><p>Value- 100 180 120 120</p><p>Weight- 10 30 20 24</p><p>Ratio(v/w)- 10 6 6 5</p><p>Solution:</p><p>First of all B is chosen as the weight of B is less than capacity of knapsack.Next item A is chosen as the available capacity of the knapsack is the greater than the weight of A.Now ,C is chosen as the next item .However the whole item cannot be chosen as the remaining capacity of the knapsack is less than the weight of C.</p><p>hence, fraction of C (i.e (60–50)/20)</p><p>Now, the capacity of the knapsack is equal to the selected items.Hence, no more item can be selected.</p><p>The total weight of the selected items is 10 +30 +20*(10/20) = 50</p><p>And the total profit is 100+180+120*(10/20)=280+60=340</p><p>This is the optimal solution.We cannot gain more profit selecting any different combination of items.</p><p>So, this was how we can solve knapsack problem using greedy approach.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b576ea9702b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>