<?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 Nilay Chauhan on Medium]]></title>
        <description><![CDATA[Stories by Nilay Chauhan on Medium]]></description>
        <link>https://medium.com/@nilay127chauhan?source=rss-53c4d4f50fb4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-xZFTOXbR5LngoK7pioJFg.jpeg</url>
            <title>Stories by Nilay Chauhan on Medium</title>
            <link>https://medium.com/@nilay127chauhan?source=rss-53c4d4f50fb4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 20 May 2026 10:36:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nilay127chauhan/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[Job Sequencing Problem]]></title>
            <link>https://medium.com/@nilay127chauhan/job-sequencing-problem-eaa38ad7e522?source=rss-53c4d4f50fb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa38ad7e522</guid>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Nilay Chauhan]]></dc:creator>
            <pubDate>Tue, 10 Sep 2019 10:56:51 GMT</pubDate>
            <atom:updated>2019-09-10T10:56:51.444Z</atom:updated>
            <content:encoded><![CDATA[<p>In job sequencing problem the objective is to find the sequence of jobs,which is completed within their deadlines and give maximum profit.</p><p>If a set of <strong><em>n</em></strong> jobs are given which are associated with deadlines and profit is earned and a job is completed by its deadline. These jobs need to be ordered in such a way that there is maximum profit.</p><p>Lets take one example. As shown in figure 1.1 an array of jobs is given where every job has a deadline and associated profit if the job is finished before the deadline. It is also given that every job takes single unit of time, so the minimum possible deadline for any job is 1. How to maximize total profit if only one job can be scheduled at a time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*y5Zsn85873nVuhSJ1Bf2iQ.png" /><figcaption>figure 1.1</figcaption></figure><p>A simple solution is to generate all subsets of given set of jobs and check individual subset for feasibility of jobs in that subset. Keep track of maximum profit among all feasible subsets. The time complexity of this solution is exponential.We can also solve this problem using greedy method which is more optimal than simple solution.So lets solve this problem via greedy method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*np9Ll4NeAezRwkUDd5ReEQ.png" /><figcaption>figure 1.2</figcaption></figure><p>To solve the job sequencing problem via greedy method follow this steps:</p><ol><li><em>Sort all jobs in decreasing order of profit.</em></li><li><em>Initialize the result sequence as first job in sorted jobs.</em></li><li><em>Do following for remaining n-1 jobs.</em></li><li><em>If the current job can fit in the current result sequence without missing the deadline, add current job to the result. Else ignore the current job.</em></li></ol><p>As you can see in the figure 1.1 the jobs are already in decreasing order of profit.Here job 1 has the highest profit and the deadline is 3 so set that job between 2–3 as shown in figure 1.2.Job 2 has second highest profit and the deadline is 4 so set that job between 3–4 and do same to all jobs.So the final sequence is J4-J3-J1-J2 and the total profit is 110.</p><p>You can prefer the code for this algorithm at <a href="https://www.geeksforgeeks.org/job-sequencing-problem/">https://www.geeksforgeeks.org/job-sequencing-problem</a>.</p><p>Time complexity of this solution is O(n²).It can optimized by Disjoint Data Structure.</p><p>Hope you like the article.Thank you :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa38ad7e522" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Traveling Salesman Problem]]></title>
            <link>https://medium.com/@nilay127chauhan/traveling-salesman-problem-74b67f872b7a?source=rss-53c4d4f50fb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/74b67f872b7a</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nilay Chauhan]]></dc:creator>
            <pubDate>Sat, 31 Aug 2019 06:17:30 GMT</pubDate>
            <atom:updated>2019-08-31T06:17:30.804Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is TSP?</h3><p>Traveling Salesman Problem describe the salesman who is travelling between N cities.Salesman knows the route and the cost of cities so he has to find the possible shortest route that visits every city exactly one and returns to the starting city.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*rYI_u91Qr4Jex6oJTDGrbw.png" /><figcaption>figure 1.1</figcaption></figure><p>As shown in figure 1.1 the salesman is traveling 4 cities and the cost of every city is given.We can solve this problem by brute-force approach and using dynamic programming.In brute-force approach if the number of vertices is N so (N-1)! routes are possible.Instead if brute-force approach dynamic programming is more optimal solution then brute-force approach.Let’s talk about both approaches one by one.</p><h3>1.Brute-force approach:</h3><p>Brute-force approach is nothing but trying out all possible solutions one by one though it is time consuming but it is also very easy method to solve TSP problem.</p><p>In figure 1.1 four cities are shown as graph and the cost of each edges are also shown there.The salesman can start from any city that he wish but here let us assume that the salesman start from city 1 and travel each cities(nodes) and come back to city 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GfuQOftE9vW1zp7CmfbOiw.png" /><figcaption>figure 1.2</figcaption></figure><p>As shown in figure 1.2 let’s take the starting point(city 1) as the root node and other three points(city 2,3,4) as the leaf nodes of the node 1.Do the same thing to every leaf node until you reach the starting point(city 1 or node 1).Then find the total cost of every possible routes and the minimum cost is our solution.</p><p>Here in figure 1.2 the minimum cost is 80 so the possible routes are 1–2–4–3–1 and 1–3–4–2–1.Both routes has the same cost 80 so the salesman can travel from any route from that.Now lets talk about dynamic programming approach.</p><h3>2.Dynamic programming approach:</h3><p>Let the given set of vertices be {1, 2, 3, 4,….n}. Let us consider 1 as starting and ending point of output. For every other vertex i (other than 1), we find the minimum cost path with 1 as the starting point, i as the ending point and all vertices appearing exactly once.</p><p>Let the cost of this path be cost(i), the cost of corresponding Cycle would be cost(i) + dist(i, 1) where dist(i, 1) is the distance from i to 1. Finally, we return the minimum of all [cost(i) + dist(i, 1)] values.To calculate cost(i) using Dynamic Programming, we need to have some recursive relation in terms of sub-problems. Let us define a term C(S, i) be the cost of the minimum cost path visiting each vertex in set S exactly once, starting at 1 and ending at i.</p><p>We start with all subsets of size 2 and calculate C(S, i) for all subsets where S is the subset, then we calculate C(S, i) for all subsets S of size 3 and so on. Note that 1 must be present in every subset.</p><pre>If size of S is 2, then S must be {1, i},<br> C(S, i) = dist(1, i) <br>Else if size of S is greater than 2.<br> C(S, i) = min { C(S-{i}, j) + dis(j, i)} where j belongs to S, j != i and j != 1.</pre><p>For a set of size n, we consider n-2 subsets each of size n-1 such that all subsets don’t have nth in them.<br>Using the above recurrence relation, we can write dynamic programming based solution. There are at most O(n*2^n) sub-problems, and each one takes linear time to solve. The total running time is therefore O(n^2*2^n). The time complexity is much less than O(n!), but still exponential. Space required is also exponential. So this approach is also infeasible even for slightly higher number of vertices.</p><p>For more information you can visit <a href="https://www.geeksforgeeks.org/travelling-salesman-problem-set-1/">geeksforgeeks.org</a> and <a href="https://www.youtube.com/watch?v=XaXsJJh-Q5Y">https://www.youtube.com/watch?v=XaXsJJh-Q5Y</a>.</p><p>Thank you :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74b67f872b7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>