<?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 Jeet Savsani on Medium]]></title>
        <description><![CDATA[Stories by Jeet Savsani on Medium]]></description>
        <link>https://medium.com/@jeetsavsani42?source=rss-71d4d37551dc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*k-RD_MTsFETj2JeZ</url>
            <title>Stories by Jeet Savsani on Medium</title>
            <link>https://medium.com/@jeetsavsani42?source=rss-71d4d37551dc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:00:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jeetsavsani42/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[Tips on Constructive Algorithms]]></title>
            <link>https://medium.com/@jeetsavsani42/tips-on-constructive-algorithms-1ced4963d080?source=rss-71d4d37551dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ced4963d080</guid>
            <category><![CDATA[datastrucutre]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[competitive-programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Jeet Savsani]]></dc:creator>
            <pubDate>Tue, 27 Jul 2021 05:06:44 GMT</pubDate>
            <atom:updated>2021-07-27T05:06:44.433Z</atom:updated>
            <content:encoded><![CDATA[<p>Constructive algorithms are a common sight in both olympiads and online programming contests. If you’re looking for some examples, check out the CodeForces problem set, filtering for “constructive algorithms”.</p><h3>Definition</h3><p>What’s a constructive algorithm, exactly? I think it’s most helpful to give an example problem:</p><p><em>Let </em>1≤N≤1051≤N≤105<em> and </em>1≤K≤log2(N)1≤K≤log2(N)<em> be fixed. Imagine performing a binary search on the values </em>1…N1…N<em>. Give a value X, </em>1≤X≤N1≤X≤N<em> which would be found in exactly K steps using binary search.</em></p><p>There’s a bunch of variations on binary search, so assume I chose a particular one in this example.</p><p>We’re supposed to generate an example number that satisfies the above condition (found in exactly the K steps of a binary search). Of course, contests add parameters to these conditions, so that multiple test cases can be given. In almost all constructive algorithm problems, there are many possible solutions, and usually, any example that satisfies the conditions is accepted.</p><p>Since there are multiple solutions, you have to find a pattern that can be generated programmatically, and implement it. These problems are usually ad-hoc, with little knowledge of data structures and algorithms needed. People with strong mathematical creativity especially shine in this category of problems. The normal strategy for these problems is to manually solve a few example inputs and generalize your thinking process.</p><p>If you don’t come from a mathematical background, I can offer some hacky strategies on solving these problems without requiring much creativity on your side…</p><h3>Strategy</h3><p>Notice that the conditions in this problem can be tested with a simple script. You shouldn’t worry about complexity on your script, since we’ll only care about small values of NN, as larger answers will be difficult to inspect manually.</p><p>Now that we have an algorithm that checks if an answer is correct, we can create another function that generates all possible answers, and use both functions to generate a (slow!) solution.</p><p>This is very valuable — instead of having to solve examples yourself, you can just use this solution to see what correct answers look like for different parameter values. So time to put on your detective hat, and try to find a pattern in the outputs you see!</p><p>Let’s say we’re testing N=16,1≤K≤4N=16,1≤K≤4 in the problem above</p><p>N=16,K=1N=16,K=1: only X=8 works.</p><p>N=16,K=2N=16,K=2: both X=4 and X=12 work.</p><p>N=16,K=3N=16,K=3: X=2, X=6, X=10, X=14 work.</p><p>N=16,K=4N=16,K=4: X=1, X=3, ...</p><p>Focus on the very first input we get for each KK: it’s 8, 4, 2, 1! It seems like there’s a pattern that we can use: we start with N and divide by 2 (rounding down) K times.</p><p>Now that we have a pattern, we ought to prove it… In case you are time-constrained or have difficulty proving it in the first place, you can just go ahead and use the script: write out your proposed solution, and test as many parameter values as you can with your two solutions. You are probably going to miss most parameter values, but that’s okay: patterns rarely break for N &gt;= 4030, and it’s worth the penalty to see if you’re right.</p><p>If a problem of this type has a well-hidden pattern, this strategy shines: you can test patterns as fast as you can write them up. If you didn’t have this script ready, you would have to execute the algorithm on paper, which is both slower and more error-prone.</p><p>A drawback of this approach is that you might spend time writing scripts without getting any further insight. So consider the risk before attempting this approach — try the other problems first perhaps?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ced4963d080" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>