<?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 4024_DHOLIYA SHREYA on Medium]]></title>
        <description><![CDATA[Stories by 4024_DHOLIYA SHREYA on Medium]]></description>
        <link>https://medium.com/@23bt04024?source=rss-08519d679891------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*E-R6owGP8wMqaEej</url>
            <title>Stories by 4024_DHOLIYA SHREYA on Medium</title>
            <link>https://medium.com/@23bt04024?source=rss-08519d679891------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:41:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@23bt04024/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[Why Finite Automata Fail Modern Password Rules?]]></title>
            <link>https://medium.com/@23bt04024/why-finite-automata-fail-modern-password-rules-305fae231565?source=rss-08519d679891------2</link>
            <guid isPermaLink="false">https://medium.com/p/305fae231565</guid>
            <category><![CDATA[cto]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[finite-automata]]></category>
            <category><![CDATA[pushdown-automata]]></category>
            <category><![CDATA[pumping-lemma]]></category>
            <dc:creator><![CDATA[4024_DHOLIYA SHREYA]]></dc:creator>
            <pubDate>Tue, 21 Apr 2026 17:03:54 GMT</pubDate>
            <atom:updated>2026-04-21T17:03:54.482Z</atom:updated>
            <content:encoded><![CDATA[<p>-by Shreya Dholiya</p><blockquote><em>A deep dive into why designing a formal password system is harder than it looks — and what Theory of Computation tells us about it.</em></blockquote><p>A few months ago, I was sitting in a Theory of Computation lecture half-paying attention while the professor talked about finite automata — those neat little state machines with circles and arrows. I thought: cool, abstract stuff, probably not useful in real life.</p><p>Then the exam question landed:</p><blockquote>design a formal model for a password system and justify whether a Finite Automaton is sufficient.</blockquote><p>Suddenly it wasn’t abstract anymore. Password systems — the things we use every day — turn out to be a fascinating intersection of theoretical CS and practical engineering. And the answer is a lot more interesting than a simple yes or no.</p><p>Whether you’re a CS student, a curious developer, or just someone wondering why websites keep rejecting your perfectly good password — let’s dig in.</p><h3>First, What Even Is a Formal Model?</h3><p>In theoretical computer science, a “formal model” is a precise mathematical way of describing which strings a system accepts or rejects. Think of it like a bouncer with a very specific rulebook. The bouncer doesn’t think — they just check rules.</p><p>A password system is literally a language recognizer: given a string w (your attempted password), does it belong to the language L of all valid passwords? If yes — access granted. If no — you get that familiar “must contain at least one special character” message.</p><p><strong>Formally: </strong>L = { w ∈ Σ* | w satisfies all password constraints }</p><p>where Σ = { a–z, A–Z, 0–9, special characters }</p><p>The real question is: what kind of machine do we need to recognize this language?</p><h3>The Password Constraints — Let’s Get Specific</h3><p>A realistic password system might enforce all of the following. Notice how they naturally split into two groups:</p><h4>The “Regular” Constraints — FA Can Handle These</h4><ul><li>Minimum length of 8 characters</li><li>Maximum length of 20 characters</li><li>At least one uppercase letter</li><li>At least one lowercase letter</li><li>At least one digit</li><li>At least one special character (!@#$%^&amp;*)</li><li>No two consecutive identical characters (no “aa” or “11”)</li></ul><p><strong>Why FA Works Here</strong></p><p>All these constraints depend only on:</p><ul><li>Local checks</li><li>Limited history</li></ul><p>We can encode them using <strong>states</strong>.</p><h4>The “Complex” Constraints — FA Breaks Down Here</h4><ul><li>The password must NOT be a palindrome (e.g., “abcba” is invalid)</li><li>The number of digits must equal the number of uppercase letters</li></ul><h3>Building the DFA — What FA Can Actually Do</h3><p>Here’s my favourite analogy for a Finite Automaton: imagine a security guard who has a checklist but absolutely no notepad, no memory beyond their current mental state, and no ability to look backwards.</p><p>That guard can tick boxes as they go: “Seen an uppercase? Check. Seen a digit? Check.” But they cannot say “the fifth character was X” — they only know their current state, not the history.</p><p>For the regular constraints, the formal DFA looks like this:</p><p>M = (Q, Σ, δ, q₀, F)</p><p>Q = length_counter × 4-bit bitmask</p><p>length_counter ∈ {0, 1, … 20, 21+} → 22 values</p><p>bitmask ∈ {0000 … 1111} → 16 values</p><p><strong>Total states = 22 × 16 = 352</strong></p><p>The bitmask is the clever part. Each of the 4 bits tracks one character class: uppercase seen, lowercase seen, digit seen, special character seen. State 0000 = nothing seen yet. State 1111 = all four types seen.</p><p>This leads to a finite — though large — number of states, which is all that matters. A DFA exists, so the constraint is regular. Adding the “no consecutive repeats” rule just multiplies states by ~95 (the alphabet size). Still completely finite.</p><h3>Where the FA Breaks — The Interesting Part</h3><p><em>Now comes the part where the theory gets genuinely beautiful.</em></p><p>Two of our constraints cannot be handled by any FA, no matter how many states you give it. And we can prove it.</p><h4>Problem 1: The Palindrome Check</h4><p>A palindrome reads the same forwards and backwards — “abcba”, “racecar”, “level.” To reject these, you need to compare the first character with the last, the second with the second-to-last, and so on.</p><p>That requires remembering the entire first half while reading the second. An FA has a fixed number of states decided at design time — it cannot grow its memory based on input length.</p><p><em>Let’s see where things start breaking — with a formal proof.</em></p><p><strong>Claim: </strong>The language of palindromes over {a, b} is not regular.</p><p><strong>Proof (Using Pumping Lemma):</strong></p><p>Assume it is regular with pumping length p.</p><p><strong>Step 1: </strong>Let s = aᵖ b aᵖ (a palindrome, |s| ≥ p).</p><p><strong>Step 2: </strong>By pumping lemma: s = xyz, |xy| ≤ p, |y| ≥ 1. Since |xy| ≤ p, y lies in the</p><p>first block of a’s, so y = aᵏ for some k ≥ 1.</p><p><strong>Step 3: </strong>Pumping gives xy²z = aᵖ⁺ᵏ b aᵖ ≠ palindrome. ✗</p><p><strong>Conclusion: </strong>Contradiction. ∴ palindromes are NOT regular. ■</p><p>In plain English: if you keep repeating (pumping) part of a palindrome, it stops being a palindrome. An FA can’t detect this — it has no memory of the original structure.</p><h4>Problem 2: Equal Count Constraint</h4><p><em>Number of digits = number of uppercase letters</em></p><p>At first glance, it seems like a basic rule.</p><p>But think deeper:</p><ul><li>Input length can be arbitrarily large</li><li>Count can grow infinitely</li></ul><p>This requires <strong>unbounded counting</strong></p><p><strong>Why FA Cannot Do This</strong></p><p>Finite Automata have:</p><ul><li>Fixed number of states</li><li>No external memory</li></ul><p>So:</p><ul><li>After some length → states repeat</li><li>Different counts map to the same state</li></ul><p>Which leads to loss of Information.</p><h4>Problem 3: Nested Patterns</h4><p>Example:</p><p>a^n.b^n</p><p>It requires:</p><ul><li>Matching counts</li><li>Maintaining order</li></ul><p><strong>Why FA Fails</strong></p><ul><li>It cannot remember how many ‘a’s appeared</li><li>And cannot ensure equal ‘b’s</li></ul><p>Again → <strong>memory limitation</strong></p><h3>So What’s the Verdict? Is FA Sufficient?</h3><p><strong>The honest answer: </strong>it depends on which constraints you’re implementing.</p><p>• FA is sufficient for everything real-world systems actually use — length checks, character class presence, no consecutive repeats. The 352-state DFA works perfectly.</p><p>• FA is NOT sufficient for palindrome rejection or counting equality. These require PDA or higher.</p><p>In practice, real password validators are written in code — Python, JavaScript — which is Turing-complete by nature. But understanding which constraints are regular vs. context-free tells you something fundamental about what you’re building and why.</p><h3>The Better Model: Pushdown Automata</h3><p>For the complex constraints, we upgrade to a Pushdown Automaton (PDA): an FA with a stack — an infinitely tall pile of sticky notes you can write on and read back.</p><p>Back to the security guard analogy: a PDA is a guard with a checklist AND a notepad, where the notepad follows last-in, first-out discipline. This lets them handle palindromes by pushing the first half onto the stack and popping as they read the second half.</p><p>For the counting constraint (digits = uppercase), even a PDA struggles when the two types are interleaved unpredictably. This edges into context-sensitive territory, handled by linear bounded automata or full Turing Machines.</p><h3>Why This Actually Matters</h3><p>I started with an embarrassing story about zoning out in lecture. Here’s the follow-up: after working through this problem, I now genuinely think about the Chomsky hierarchy whenever I write validation logic.</p><p>Is this constraint regular? Can I express it as a regex? Or does it need actual imperative code with memory?</p><p>Theory of computation isn’t just abstract math. It’s a framework for understanding what’s easy and what’s fundamentally hard. Password systems, DNA sequence matching, natural language parsing, compiler design — all are questions about language recognition at their core.</p><p>The next time a website rejects your password for not having enough uppercase letters, you’ll know exactly which type of automaton is saying no.</p><h3>References &amp; Further Reading</h3><p>• Michael Sipser — Introduction to the Theory of Computation (Ch. 1–2 for FA, Ch. 2 for PDA, Ch. 1.4 for Pumping Lemma)</p><p>• Hopcroft, Motwani, Ullman — Introduction to Automata Theory, Languages, and Computation</p><p>• Stanford CS103 — Automata Theory (free course materials online)</p><p>• Noam Chomsky — On Certain Formal Properties of Grammars (1959) — the original hierarchy paper</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=305fae231565" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Budget Allocation in Marketing, Selection of Campaigns: The Knapsack Problem]]></title>
            <link>https://medium.com/@23bt04024/budget-allocation-in-marketing-selection-of-campaigns-the-knapsack-problem-fe5ac788663c?source=rss-08519d679891------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe5ac788663c</guid>
            <dc:creator><![CDATA[4024_DHOLIYA SHREYA]]></dc:creator>
            <pubDate>Sun, 05 Oct 2025 13:39:30 GMT</pubDate>
            <atom:updated>2025-10-05T13:41:26.602Z</atom:updated>
            <content:encoded><![CDATA[<p>-by Shreya Dholiya</p><p>Imagine this scenario. You are a marketing manager in a growing business with a limited budget across several advertising options, all of which generate a return. Additionally, the company’s marketing budget is not eternal. The question to be resolved is, “which combination of campaigns will yield the best return on each rupee?” And now we introduce the incredibly exciting knapsack problem; generally considered the most popular computer science problem, which you never imagined would relate to the decisions in modern marketing.</p><h3><strong>The Knapsack Analogy is a Perfect Fit for Marketing</strong></h3><p>The marketing budget may be thought of as a backpack or “knapsack”, and the campaigns are the individual items that go into the knapsack. Each campaign will have a cost (“weight”) and a return (“value”) associated with it. The objective is to select the combination of campaigns (items) that when their total cost does not exceed the marketing budget (the weight capacity of the knapsack) yields the highest (maximum) profit (total return). As formulated, this is a resource allocation problem with constraints, just as the knapsack problem is.</p><h3><strong>Framing the problem, although mathematical is quite intuitive!</strong></h3><p>Now let us use a simple example to frame this problem.</p><p>Let’s assume you have the following:</p><p>· 3 campaign options: Google Ads, Social Media, Email</p><p>· Cost — ₹40K, ₹50K, ₹10K.</p><p>· Estimated return — ₹120K, ₹130K, ₹30K.</p><p>· Budget — ₹100K.</p><p>· In knapsack formulation:</p><p>wi= the cost(in other words weight) for campaign i,</p><p>vi = the value of return from campaign i,</p><p>W= total budget (or weight) available,</p><p>xi = 1 if campaign i is chosen, 0 if it is not.</p><h4><strong>Objective:</strong></h4><p>maximize</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/56/0*GqWuI9X7ZY8n17Z9" /></figure><p>subject to</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/99/0*IXgnkt4RtcFrgPNw" /></figure><p>and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/141/0*yMN82GKfqIcYETf_" /></figure><p>This ultimately allows you to plug in your campaign options, campaign costs and budget mathematically, in order to find the sweet spot or the best campaign portfolio.</p><p>[Example reference: <a href="https://www.studocu.com/in/document/srm-institute-of-science-and-technology/btech-cse-core/strategic-marketing-budget-allocation-using-knapsack-algorithm-ra2312704010048/129138804">https://www.studocu.com/in/document/srm-institute-of-science-and-technology/btech-cse-core/strategic-marketing-budget-allocation-using-knapsack-algorithm-ra2312704010048/129138804</a>]</p><h3><strong>Algorithmic strategies: Greedy and Dynamic programming</strong></h3><ul><li><strong>Greedy approach:</strong> Calculate the return vs cost ratio (ri/ci) for each campaign. Sort the campaigns from highest to lowest ratio, and campaign costs. Pick campaigns in order from the top of the list until you have used your budget. This can be done quickly (time complexity of O(nlogn)) and is a powerful and simple rule of thumb to use, although the ideal ‘optimum’ can be theoretically missed occasionally.</li></ul><p>So here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*51bohlafpsq6vPvClltUBQ.png" /></figure><ul><li><strong>Dynamic programming:</strong> If you are looking for guaranteed optimum (especially with many campaigns and tighter budget) you can also apply dynamic programming methods. Essentially, dynamic programming methods create a table of all the possible options, and very efficiently consider all combinations to arrive at a solid solution. By using dynamic programming, you will not miss that one magical combination just because the greedy process misses it because it was an outlier. Pre-post example.</li><li>Recurrence relation: <em>dp</em>[<em>i</em>][<em>w</em>]=max(<em>dp</em>[<em>i</em>−1][<em>w</em>],<em>dp</em>[<em>i</em>−1][<em>w</em>−<em>weight</em>[<em>i</em>]]+<em>value</em>[<em>i</em>])</li></ul><p>[Formula reference: <a href="https://fiveable.me/introduction-algorithms/unit-11/knapsack-problem-variations/study-guide/ijVYVStOF5PtUzT1">https://fiveable.me/introduction-algorithms/unit-11/knapsack-problem-variations/study-guide/ijVYVStOF5PtUzT1</a>]</p><h3><strong>Practical Marketing Implementation: Intelligent Decision Making</strong></h3><p>Marketing organizations from top companies, on a regular basis, use the knapsack framework for:</p><p>· Channel mix optimization: Selecting between Google Ads, influencer partnerships, TV advertising, and out of home campaigns.</p><p>· Multi-market allocation: Optimizing budgets across geographies/brands.</p><p>· Campaign timing and sequencing: Deciding not just which campaigns, but when to run the campaigns for maximum effectiveness.</p><p>Given the presence of so much data, companies can plug in real life conversion rates, reach and measure impact from their models, allowing almost real-time budget shifting as data emerges.</p><h3><strong>A Practical Example: A budget in motion</strong></h3><p>With the numbers from above and a greedy approach:</p><p>1. Calculate return/cost: (Google Ads = 3, social media = 2.6, Email = 3).</p><p>2. Rank campaigns: Google Ads/Email tie, then Social.</p><p>3. Select: Select Google Ads (₹40K), Email (₹10K) and social media (₹50K). Amount of budgeting used = ₹100K or ₹180K. Total return = ₹120K + ₹30K + ₹130K = ₹280K.</p><p>But: If the budget was ₹90K, the greedy method may miss that by swapping social media for Email or Google, the budget would return stronger marginal returns — where dynamic programming shines with complexity and broad options.</p><h3><strong>Limitations and Future Direction</strong></h3><p>· Computational Complexity: The classic knapsack problem is “NP-hard”, so as the number of campaigns and number of constraints accumulate, the computational time will as well. Fortunately, if the numbers are moderate, many modern algorithms address this well.</p><p>· Uncertainty: The performance of a campaign can be quite different from the estimates; this means you need to continuously re-validate your assumptions and as much as possible, use real-time data.</p><p>· Fractional and Sequenced Campaigns: Sometimes, campaigns can be funded partially or sequenced which result in more advanced models given the “fractional” or the “dynamic” knapsack.</p><h3><strong>Conclusion: Smart Allocation, Big Returns</strong></h3><p>If you think budget allocation is some sort of educated guess let me disabuse you of that notion. Knapsack algorithms have allowed marketers to sidestep gut-instinct planning in favour of a scientifically disciplined approach to maximizing ROI. Whether you prefer the speed of heuristics or the full dynamic programming versions, the knapsack framework will help you make every rupee in marketing budget turn into a meaningful business impact.</p><h3><strong>References</strong></h3><p>· Pferschy, U., Schauer, J., &amp; Maier, G. (2014). Media Mix Optimization — Applying a Quadratic Knapsack Model. <em>Proceedings of ICORES 2014. </em>[<a href="https://www.scitepress.org/Papers/2014/48258/48258.pdf">https://www.scitepress.org/Papers/2014/48258/48258.pdf</a>]</p><p>· <a href="https://en.wikipedia.org/wiki/Knapsack_problem">https://en.wikipedia.org/wiki/Knapsack_problem</a></p><p>· <a href="https://www.studocu.com/in/document/srm-institute-of-science-and-technology/btech-cse-core/strategic-marketing-budget-allocation-using-knapsack-algorithm-ra2312704010048/129138804">https://www.studocu.com/in/document/srm-institute-of-science-and- technology/btech-cse-core/strategic-marketing-budget-allocation-using-knapsack-algorithm-ra2312704010048/129138804</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe5ac788663c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>