<?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 Vijay Magvaniya on Medium]]></title>
        <description><![CDATA[Stories by Vijay Magvaniya on Medium]]></description>
        <link>https://medium.com/@vmmagvaniya?source=rss-f5bce8e40ad6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2rqEt5rNL4_ClLG7</url>
            <title>Stories by Vijay Magvaniya on Medium</title>
            <link>https://medium.com/@vmmagvaniya?source=rss-f5bce8e40ad6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:32:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vmmagvaniya/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[Making change problem by using Greedy method:-]]></title>
            <link>https://medium.com/@vmmagvaniya/making-change-problem-by-using-greedy-method-15eff7fc0f76?source=rss-f5bce8e40ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/15eff7fc0f76</guid>
            <dc:creator><![CDATA[Vijay Magvaniya]]></dc:creator>
            <pubDate>Sat, 31 Aug 2019 17:16:27 GMT</pubDate>
            <atom:updated>2019-09-06T04:45:02.701Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*g70X1uAMDNDAZX2PZVeKsA.png" /></figure><p>So, here we first try to understand What is Greedy method?</p><p>It is one type of problem solving technique in this Method we take decision at that point without thinking further steps or in simple way what happen if i choose it.</p><p>Example:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GN0VXCaM6P7o9d02b4_-JQ.jpeg" /></figure><p>Person p1 wants to reach up D1 but there is two pathes are available by using Greedy approach we choose path 2 because at that point we think only which one is minimum without thinking more but we path 1 takes less time or less cost whatever.</p><p>Now using this method we try to solve making change problem.</p><p>It is a coin change problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*OOMa9ll-7jdFs1UC53tuQg.jpeg" /></figure><p>Suppose,you are a seller and one customer comes to you and take some items . Now that customer gives you 100 rupees coin and take some items of 24 rupees .Now you have to return 76 rupees to that customer.</p><h4>How you give?</h4><h4>Which coins you give?</h4><h4>And how many coins you give?</h4><p>Here I assume that we have infinite no of coins.</p><p>Coins are 1,2,5,10,50,100,200,500,1000 etc available.</p><p>So here we try to give minimum no of coins to that customer.For change of 79 rupees you give 50 rupees one coin,one coin of 20 rupees,one coin of 5 rupees and two coins of 2 rupees.</p><p>This approach is use by us in daily life.In this approach we compare give rupees with the denominator one by one and start with latest denominator which we have and we assume we have infinite no of coins.So we can give one coin more than one time.</p><h4>Here how we get coins?</h4><p>D={1000,500,200,100,50,20,10,2,1}</p><p>N=79</p><p>So that</p><p>79&gt;50</p><p>We can give 50 rupees coin</p><p>New N=79–50=29</p><p>29&lt;50</p><p>Compare with next denominator</p><p>29&gt;20</p><p>New N=29–20=9</p><p>And same way 9&gt;5</p><p>So that new N=9–5=4</p><p>And at last 4&gt;2</p><p>N=2 which is equal to same denominator 2 so we can give another 2 rupees coins now N become 0.</p><p>So we get get the solution .</p><p>Which is ans={50,20,5,2,2}</p><p>By using this method we can get optimal solution,but not always.</p><h4>Because when denominators are not in proper sequence at time this method may not give optimal solution.</h4><p>Suppose d={10,7,5,2,1}</p><p>For change of 14 rupees by using this method we get ans={10,2,2} three coins but that is not optimal because another solution also possible which is ans1={7,7} So that.</p><p>By using one very powerful technique we get always optimal solution which is Dynamic programming for more on this method click on</p><p><a href="https://algorithms.tutorialhorizon.com%20%E2%80%BA%20...Dynamic%20Programming%20-%20Coin%20Change%20Problem%20-%20Algorithms%20%7C%20@tutorialhorizon/">https://algorithms.tutorialhorizon.com › ...Dynamic Programming - Coin Change Problem - Algorithms | @tutorialhorizon</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15eff7fc0f76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Techniques to find the complexity of reoccurrence relations:-]]></title>
            <link>https://medium.com/@vmmagvaniya/techniques-to-find-the-complexity-of-reoccurrence-relations-77dea36b60e3?source=rss-f5bce8e40ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/77dea36b60e3</guid>
            <dc:creator><![CDATA[Vijay Magvaniya]]></dc:creator>
            <pubDate>Tue, 27 Aug 2019 03:34:40 GMT</pubDate>
            <atom:updated>2019-08-27T10:22:41.968Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*D6fDMoWIoyFZal2V-mXm3Q.jpeg" /></figure><p>If you are seeing this for first time then one question may arise in your mind “what are the reoccurrence relations?”</p><p>A recurrence is an equation or inequality that describes a function in terms of its values on smaller inputs. To solve a Recurrence Relation means to obtain a function defined on the natural numbers that</p><p>satisfy the recurrence.</p><p>Example:-</p><p>T (n) =2 T(n/2)+ n</p><p>Now, we are going to discuss about the techniques :-</p><ol><li>Substitution Method</li></ol><p>2. By using Master theorem</p><p>3. Recurrence tree Method</p><p>There is also some method but we will discuss above three.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*4t8dowM3kT9dUlO3_IdQJw.jpeg" /></figure><h4>1.Subtitution Method</h4><h4>As a name suggest that we have to do substitution in equation.</h4><h4>But How?</h4><p>That we see by using example so that become more clear.</p><h4>Example:-</h4><p>Given recurrence relation is</p><p>T(n)=T(n-1)+c</p><p>T(1)=c2</p><h4>Ans:-</h4><p>T(n)=T(n-1)+c1</p><p>At this step we have to find the value of T(n-1) and put in previous equation.</p><p>So that …</p><p>T(n-1)=T(n-2)+c1….(1)</p><p>And put into 1st equation</p><p>T(n)=T(n-2)+2c1</p><p>Now find T(n-2) and put</p><p>T(n-2)=T(n-3)+c1</p><p>After substitution</p><p>T(n)=T(n-3)+3c1</p><p>Like wise up to kth equation</p><p>T(n)=T(n-k)+kc1</p><p>Now ,we know the value of T(1)</p><p>So that we try to make n-k=1</p><p>After that</p><p>T(n)=T(1)+(n-1)c1</p><p>T(n)=c2+(n-1)c1</p><p>T(n)=c2+(n)c1-c1</p><p>So that we get…</p><h4>T(n)=O(n)</h4><p>Now we have to discuss second method</p><h4>2.By using Master theorem</h4><h4>Master theorem:-</h4><p>The Master Theorem applies to recurrences of the following form:</p><h4>T (n) = aT (n/b) + f(n)</h4><p>where a ≥ 1 and b &gt; 1 are constants and f(n) is an asymptotically positive function.</p><p>There are 3 cases:-</p><h4>Case 1:-</h4><p>“if f(n)=θ(n^c) where c&lt;logb(a) then T(n)=θ(n^logb(a)”</p><h4>Case 2:-</h4><p>“if f(n)=θ(n^c *log^k (n)) where k&gt;=0 and c=logb(a) then T(n)=θ(n^c *log^(k+1) (n)) ”</p><h4>Case 3:-</h4><p>“if f(n)=θ(n^c) where c&gt;logb(a) then T(n)=θ(n^c)”</p><p>Now,it is time to solve some examples of base on this theorem.</p><p>So that lets do it…</p><h4>Ex1:-</h4><p>T (n) = 3T (n/2) + n^2<br>Here, c&gt;logb(a)</p><p>So that case 3 is applicable</p><p>So that,</p><p>T (n) = Θ(n^2)</p><h4>Ex2:-</h4><p>T (n) = 4T (n/2) + n^2</p><p>Here, c=logb(a)</p><p>So that case 2 is applicable</p><p>So that,</p><p>T (n) = Θ(n^2*log n)</p><h4>Ex3:-</h4><p>T (n) = 0.5T (n/2) + n^2</p><h4>Here , a is not &gt;=1</h4><p>So that we can’t apply this theorem…</p><p>Now, let’s look for third method.</p><h4>3.Recurrence tree Method</h4><p>Like <a href="https://www.gatevidyalay.com/masters-theorem-solving-recurrence-relations/">Master’s Theorem</a>, Recursion Tree is another method for solving the recurrence relations.</p><p>A recursion tree is a tree where each node represents the cost of a certain recursive sub-problem.</p><p>We sum up the values in each node to get the cost of the entire algorithm.</p><h4>Steps to solve Recurrence relations using Recursion tree method-</h4><h4>Step-01:</h4><ul><li>Draw a recursion tree based on the given recurrence relation.</li></ul><h4>Step-02:</h4><ul><li>Determine-Cost of each level</li><li>Total number of levels in the recursion tree</li><li>Number of nodes in the last level</li><li>Cost of the last level</li></ul><h4>Step-03:</h4><ul><li>Add cost of all the levels of the recursion tree and simplify the expression so obtained in terms of asymptotic notation</li></ul><p>Now for more clarification do some examples:-</p><p>Example:-</p><p>Solve the following recurrence relation using recursion tree method-</p><p>T(n) = 2T(n/2) + n</p><p>Ans:-</p><h4>Step-01:</h4><p>Draw a recursion tree based on the given recurrence relation.</p><p>The given recurrence relation shows-</p><ul><li>A problem of size n will get divided into 2 sub-problems of size n/2.</li><li>Then, each sub-problem of size n/2 will get divided into 2 sub-problems of size n/4 and so on.</li><li>At the bottom most layer, the size of sub-problems will reduce to 1.</li></ul><p>This is illustrated through following recursion tree-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*7OO0vZdb7bTs7FN_xQB0Aw.png" /></figure><p>The given recurrence relation shows-</p><ul><li>The cost of dividing a problem of size n into its 2 sub-problems and then combining its solution is n.</li><li>The cost of dividing a problem of size n/2 into its 2 sub-problems and then combining its solution is n/2 and so on.</li></ul><p>This is illustrated through following recursion tree where each node represents the cost of the corresponding sub-problem-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*W_Sd5oKTUi_Jbp4vw6s0TA.png" /></figure><h4>Step-02:</h4><p>Determine cost of each level-</p><ul><li>Cost of level-0 = n</li><li>Cost of level-1 = n/2 + n/2 = n</li><li>Cost of level-2 = n/4 + n/4 + n/4 + n/4 = n and so on.</li></ul><h4>Step-03:</h4><p>Determine total number of levels in the recursion tree-</p><ul><li>Size of sub-problem at level-0 = n/20</li><li>Size of sub-problem at level-1 = n/21</li><li>Size of sub-problem at level-2 = n/22</li></ul><p>Continuing in similar manner, we have-</p><ul><li>Size of sub-problem at level-i = n/2i</li></ul><p>Suppose at level-x (last level), size of sub-problem becomes 1. Then-</p><p>n / 2x = 1</p><p>2x = n</p><p>Taking log on both sides, we get-</p><p>xlog2 = logn</p><p>x = log2n</p><p>∴ Total number of levels in the recursion tree = log2n + 1</p><h4>Step-04:</h4><p>Determine number of nodes in the last level-</p><ul><li>Level-0 has 20 nodes i.e. 1 node</li><li>Level-1 has 21 nodes i.e. 2 nodes</li><li>Level-2 has 22 nodes i.e. 4 nodes</li></ul><p>Continuing in similar manner, we have-</p><ul><li>Level-log2n has 2log2n nodes i.e. n nodes</li></ul><h4>Step-05:</h4><p>Determine cost of last level-</p><p>Cost of last level = n x T(1) = θ(n)</p><h4>Step-06:</h4><p>Add costs of all the levels of the recursion tree and simplify the expression so obtained in terms of asymptotic notation-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*8wl139WdbzRx4JCW-HnlAg.png" /></figure><p>= n x log2n + θ (n)</p><p>= nlog2n + θ (n)</p><p>= θ (nlog2n)</p><p>By this way we can solve recurrence relations.</p><p>“if you like this then share and follow me…”</p><h4>Thank you!!!!!</h4><p>References:-</p><p><a href="https://www.gatevidyalay.com/recursion-tree-solving-recurrence-relations/">https://www.gatevidyalay.com/recursion-tree-solving-recurrence-relations/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77dea36b60e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>