<?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 Gopika on Medium]]></title>
        <description><![CDATA[Stories by Gopika on Medium]]></description>
        <link>https://medium.com/@gop?source=rss-4d04fa771d36------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zopBIO5y1qQs7vE4mllDig.jpeg</url>
            <title>Stories by Gopika on Medium</title>
            <link>https://medium.com/@gop?source=rss-4d04fa771d36------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 17:19:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gop/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[Transactions & Concurrency (Part I)- DBMS: The Basics]]></title>
            <link>https://medium.com/@gop/transactions-concurrency-part-i-dbms-the-basics-01881bb02c2d?source=rss-4d04fa771d36------2</link>
            <guid isPermaLink="false">https://medium.com/p/01881bb02c2d</guid>
            <category><![CDATA[dbms]]></category>
            <category><![CDATA[dbmsinterview]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Gopika]]></dc:creator>
            <pubDate>Tue, 02 Sep 2025 17:20:32 GMT</pubDate>
            <atom:updated>2025-09-02T17:22:04.863Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction:</h3><p>For any given large scale application, whether it be an e-commerce website or an banking application, there tend to be multiple users accessing these applications and performing one task or another simultaneously (concurrently). When we have users performing multiple operations and thereby accessing the same backend database for the application at the same time, we need someway to manage the conflicts that could arise when two or more users are manipulating the same field or data entry value.</p><p>What happens when one user writes and then another user reads from the same resource? What if both users try to write to the same resource? There are several problems we can run into, these are refered to as conflicts</p><h4>Database Conflicts:</h4><p><strong>Inconsistent Reads (Write-Read Conflict)</strong>: A user reads only part of what was updated.</p><p><strong>Lost Update (Write-Write Conflict)</strong>: Two users try to update the same record at the same time so one of the updates gets lost</p><p><strong>Dirty Reads (Write-Read Conflict)</strong>: One user reads an update that was never committed.</p><p><strong>Unrepeatable Reads (Read-Write Conflict)</strong>: A user reads two different values for the same record because another user updated the record in between the two reads.</p><h4>Transactions:</h4><p>A <strong>transaction</strong> is a <strong>single, logical unit of work</strong> that consists of one or more database operations (like INSERT, UPDATE, DELETE, SELECT) that must either <strong>all succeed</strong> or <strong>all fail</strong>.</p><p>To guarantee the integrity of data, database transactions follow these ACID properties:</p><ol><li><strong>Atomicity</strong> — All or nothing. If part of a transaction fails, the whole transaction is rolled back to the previous safe state.</li></ol><p><strong>example</strong>: <em>Imagine an ATM withdrawal:</em></p><p>First, Deduct $100 from your account. Second, Dispense $100 cash.</p><p>If the cash machine jams, <strong>the deduction is rolled back</strong> since you don’t lose money without cash.</p><p><strong>2. Consistency</strong> — The database moves from one valid state to another maintaining db rules.</p><p><strong>example</strong>: <em>A bank rule says your balance can’t be negative.</em></p><p>If a withdrawal would make your balance -50, the <strong>transaction is rejected</strong>.<br> The database always stays consistent.</p><p><strong>3. Isolation</strong> —When multiple transactions occur at the same time, isolation prevents them from interfering with each other, making it seem as though transactions are processed sequentially. (independently of each other)</p><p><strong>example</strong>: <em>Two people buy the </em><strong><em>last movie ticket</em></strong><em> at the same time. </em>Even if they click “Buy” together, <strong>only one transaction succeeds. </strong>Transaction of person B will either wait until A’s is completed or vice versa but both cannot book the same seat.</p><p><strong>4. Durability</strong> — Once committed, the changes are permanent even in case of power outage or db crash.</p><p><strong>example</strong>: <em>You transfer $100 and get a “Success” message. </em>Even if the power goes out right after, the transfer is <strong>saved to disk</strong> and won’t disappear.</p><h4>Concurrency:</h4><p><strong>Concurrency</strong> is when <strong>multiple transactions or operations run at the same time (concurrently), </strong>these transactions may be reading or writing or updating the same field, however they must do so in the correct sequence and without interfering with each other’s correctness.</p><p>Concurrency is needed to:</p><ul><li>Improve <strong>performance</strong> and <strong>throughput</strong> (multiple users can use the database at once) especially on large scale applications.</li><li>Decreases Latency (response time per transaction): Multiple transactions can run at the same time, so one transaction’s latency need not be dependent on another unrelated transaction still in progress.</li><li>Challenges include <strong>race conditions</strong>, <strong>deadlocks </strong>and so on.</li></ul><h4><strong>Concurrency Control Techniques:</strong></h4><p>used to ensure all concurrent transactions follow ACID properties and maintain data integrity.</p><ol><li><strong>Lock-Based Protocols:</strong></li></ol><p>Transactions <strong>lock data</strong> before using it.</p><ul><li>Other transactions must wait until the lock is released.</li></ul><p><strong>Example:</strong><br> Two students try to update the same library book record at once.</p><ul><li>Transaction A locks the record, updates it, and releases the lock.</li><li>Transaction B can only update after A finishes.</li></ul><p>2. <strong>Timestamp-Based Protocols:</strong> Transactions are assigned timestamps to ensure they execute in a specific order. for instance, if a person initially with a bank balance of 0 withdraws money and deposits 50 rupees simultaneously (suppose in a hypothetical situation the deposit has been made to his bank account from a relative and his withdrawal has been made via phone upi at the same time), he must only withdraw after the money has been deposited, otherwise the transaction would fail and he must try again.</p><p><strong>3. Optimistic Concurrency Control (OCC)</strong></p><ul><li>Transactions <strong>don’t lock (both may access same resource at the same time) </strong>during execution.</li><li>At commit time, system checks if another transaction changed the same data.</li><li>If conflict → rollback; if not → commit. Suppose Two users edit the same online document. Both work “optimistically” assuming no conflict. When saving, the system checks if the document changed. If yes, one user retries.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WKXS0weXOx26YyQf" /><figcaption>Photo by <a href="https://unsplash.com/@sunder_2k25?utm_source=medium&amp;utm_medium=referral">Sunder Muthukumaran</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Conclusion:</h3><p>This article references concepts from <em>The UC Berkeley DBMS Lectures CS186 and Database System Concepts by Silberschatz </em>and is intended as a technical reference and learning resource. If you spot any mistakes or have suggestions, please share them in the comments — it will help me and others learn better.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01881bb02c2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multithreading in Java: The Basics]]></title>
            <link>https://medium.com/@gop/multithreading-in-java-the-basics-178a71ecae35?source=rss-4d04fa771d36------2</link>
            <guid isPermaLink="false">https://medium.com/p/178a71ecae35</guid>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[introductory]]></category>
            <dc:creator><![CDATA[Gopika]]></dc:creator>
            <pubDate>Mon, 01 Sep 2025 06:08:06 GMT</pubDate>
            <atom:updated>2025-09-01T06:38:12.426Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction:</strong></h3><p>Multithreading is a programming technique that allows a computer program to run multiple parts of its code at the same time. Each part, called a thread, can perform a separate task while sharing the same memory and resources of the program. This approach is widely used in modern software to make better use of hardware with multiple processor cores and to handle tasks like user interaction, background processing, and network communication efficiently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*vsQEiVCLhRDhdJQCtu7jNw.png" /><figcaption>Figure 1.1</figcaption></figure><h4>THREADS:</h4><p>We know that a thread is a piece of a program in execution, so when we allow multiple threads to run (perform tasks) simultaneously , accessing the same computing resources, that’s referred to as multithreading.</p><p>A thread can be <em>running</em> or it could be <em>ready to run as soon as it gets CPU time. A </em>running thread can be <em>suspended </em>which temporarily suspends it’s activity. A suspended thread can then be resumed, allowing it to pick up where it left off. A thread can be <em>blocked </em>when waiting for a resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*7c3MiTlSAx83VcO90dLQqg.png" /></figure><h3>HOW DOES JAVA SUPPORT MULTITHREADING?</h3><p>The java run-time system depends on threads for many things, and all class libraries are designed with multithreading in mind. Java uses threads to enable the entire environment to be asynchronous. This helps to allow for efficient usage of CPU resources.</p><h4>1) Context switch &amp; Thread priority:</h4><p>Java assigns each thread a priority that determines how that thread should be treated wrt others. A thread’s priority is used to decide when to switch from one running thread to the next. During a context switch, the operating system saves the current process’s state, including values set in CPU registers and other vital information, into its Process Control Block (PCB), and then loads the state of a new process from its own PCB into the CPU’s registers. This action allows the CPU to pause one task and resume another, a fundamental process for enabling multitasking in a computer system. This is called a context switch.</p><h4>2) THE THREAD CLASS AND THE RUNNABLE INTERFACE:</h4><p>To create a new thread in Java, your program must either extend the Thread class or implement the Runnable interface.</p><p>the methods used are as follows:</p><ul><li>start(): Starts a thread by calling the run() method in a separate thread of control.</li><li>run(): Entry point for the thread. This method is overridden when extending Thread or implementing Runnable</li><li>sleep(long milliseconds): Causes the currently executing thread to pause for a specified duration in milliseconds.</li><li>join(): Waits for a thread to complete its execution before the calling thread resumes.</li><li>interrupt(): Interrupts a thread. This sets the thread&#39;s interrupted status and can cause InterruptedException if the thread is in a waiting, sleeping, or joining state.</li><li>isAlive(): Returns true if the thread has been started and has not yet died.</li><li>setPriority(): Returns the priority of the thread.</li></ul><h4>IMPLEMENTATION OF THREADS IN JAVA:</h4><ol><li>By implementing Runnable Interface: Define a class that implements Runnable, place the thread code in run(), and pass an instance to a Thread object.</li><li>By Extending Thread class: Create a class that extends Thread and override run().</li></ol><h4>EXAMPLE:</h4><pre>class MyRunnableClass implements Runnable {<br>    public void run() {<br>        for (int i = 1; i &lt;= 5; i++) {<br>            System.out.println(&quot;Runnable Thread: &quot; + i);<br>            try { Thread.sleep(500); } catch (InterruptedException e) {}<br>        }<br>    }<br>}<br><br>class MyThread extends Thread {<br>    public void run() {<br>        for (int i = 1; i &lt;= 5; i++) {<br>            System.out.println(&quot;Thread Class: &quot; + i);<br>            try { Thread.sleep(500); } catch (InterruptedException e) {}<br>        }<br>    }<br>}<br><br>public class Main {<br>    public static void main(String[] args) {<br>        Thread t1 = new Thread(new MyRunnableClass()); // runnable based thread<br>        MyThread t2 = new MyThread();                  // thread based thread<br><br>        t1.start();<br>        t2.start();<br>    }<br>}</pre><h3>Conclusion:</h3><p>Multithreading in Java allows programs to run multiple tasks at the same time, improving efficiency and responsiveness. Threads can be created in two main ways: by implementing the Runnable interface or by extending the Thread class. Both approaches achieve the same goal, but implementing Runnable is often preferred because the <strong>task (logic)</strong> is separate from the <strong>thread (execution mechanism)</strong> and it supports multiple inheritance. Understanding thread creation, execution, and scheduling is an essential step toward writing programs that make better use of modern multi-core systems.</p><h4>disclaimer:</h4><p>This article references concepts from <em>Java: The Complete Reference</em> by Herbert Schildt and is intended as a technical reference and learning resource. If you spot any mistakes or have suggestions, please share them in the comments — it will help me and others learn better.</p><h4>further reading:</h4><ul><li><em>Java: The Complete Reference</em> by Herbert Schildt — Comprehensive guide to Java, including threads and concurrency.</li><li><a href="https://java-latte.blogspot.com/2015/07/create-thread-using-method-reference-in-java-8.html">Java-Latte: Create Thread Using Method Reference in Java 8 —</a> Explains thread creation approaches with Java 8 features.</li><li>Java Official Documentation — Concurrency — Oracle’s official Java concurrency tutorial.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=178a71ecae35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arrays in Data Structures & Algorithms : Optimal Approaches]]></title>
            <link>https://medium.com/@gop/arrays-in-data-structures-algorithms-optimal-approaches-7211f2cd7c33?source=rss-4d04fa771d36------2</link>
            <guid isPermaLink="false">https://medium.com/p/7211f2cd7c33</guid>
            <category><![CDATA[data-structuresalgorithms]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[dsa-training]]></category>
            <dc:creator><![CDATA[Gopika]]></dc:creator>
            <pubDate>Wed, 26 Feb 2025 13:34:38 GMT</pubDate>
            <atom:updated>2025-02-26T13:35:47.493Z</atom:updated>
            <content:encoded><![CDATA[<h3>Arrays in Data Structures &amp; Algorithms : Optimal Approaches</h3><h3><strong>Mastering Array-Based Problems: Optimal Approaches &amp; Strategies:</strong></h3><p>Arrays are fundamental in programming, but solving problems efficiently requires the right approach. From <strong>Kadane’s Algorithm</strong> for maximum subarray sums to <strong>sliding window</strong> for subarrays with constraints, each technique optimizes performance. Techniques like <strong>prefix sum</strong>, <strong>hashmaps</strong>, and <strong>two pointers</strong> help tackle complex challenges efficiently. Whether it’s finding the <strong>longest consecutive sequence</strong> or solving <strong>two-sum</strong> in O(n), choosing the right strategy makes a huge difference.</p><p>Here’s a summary of all the approaches I’ve learnt so far doing DSA problems which I believe would make a good learning resource :</p><h3>Common Array-Based Problems &amp; Optimal Approaches</h3><p>Here’s a <strong>comprehensive table</strong> covering common array problems, their best approaches, and time complexity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*9SXBpaRNimmCpJKYgWnmCw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*QVD_IFgKZvuiQC1wz4TrTw.png" /></figure><h3>How to Choose the Best Approach?</h3><ol><li><strong>Subarray Sum / Range Queries? → Prefix Sum or HashMap</strong></li><li><strong>Sliding Window?</strong> → Look for constraints like <strong>“at most K”</strong> or <strong>“smallest subarray”</strong></li><li><strong>Sorting Constraints?</strong> → Consider <strong>Two Pointers</strong> or <strong>Sorting + Binary Search</strong></li><li><strong>Duplicates / Frequency Issues?</strong> → HashMap or <strong>Negation Trick</strong></li><li><strong>Finding an Element in </strong><strong>1 to N Range?</strong> → <strong>Cycle Sort, XOR, or Sum Methods</strong></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7211f2cd7c33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[THE BASICS : VIRTUAL TABLES IN C++:]]></title>
            <link>https://medium.com/@gop/virtual-tables-in-c-d213568d9ddc?source=rss-4d04fa771d36------2</link>
            <guid isPermaLink="false">https://medium.com/p/d213568d9ddc</guid>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[virtual-table]]></category>
            <category><![CDATA[c]]></category>
            <dc:creator><![CDATA[Gopika]]></dc:creator>
            <pubDate>Wed, 22 Jan 2025 09:32:01 GMT</pubDate>
            <atom:updated>2025-01-22T09:33:27.399Z</atom:updated>
            <content:encoded><![CDATA[<h3>THE BASICS : VIRTUAL TABLES IN C++</h3><h3>So what are virtual tables ?</h3><p>In C++, virtual tables (v-tables) are a mechanism that supports runtime polymorphism. They allow derived classes to override functions from base classes, enabling dynamic behavior based on the object type. Let&#39;s understand this concept using a simple example with birds like &quot;crow&quot; and &quot;fly&quot; behavior.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yMzUi064wUIWBOcJ01wZEg.png" /></figure><p><strong>Example Explanation:</strong></p><p>Base Class and Virtual Function:</p><p>The base class (e.g., Bird) declares a virtual function for a behavior (e.g., fly()).</p><p>Basically,</p><p>Virtual functions ensure that the function to be executed is determined at runtime, depending on the actual type of the object (e.g., Crow).</p><ul><li>Derived Class:</li></ul><p>Derived classes like Crow override the base class&#39;s virtual function to provide specific behavior.</p><ul><li>Virtual Table Mechanism:</li></ul><p>Every class with virtual functions has a v-table, which is essentially a table of pointers to the virtual functions that objects of the class can call.</p><h3>How it works :</h3><p>Each object of such a class contains a pointer to the class&#39;s v-table. When a virtual function is called on an object, the v-table is consulted to determine the correct function to invoke.</p><ul><li>Example Code:</li></ul><pre>#include &lt;iostream&gt;<br>using namespace std;<br><br>// Base class<br>class Bird {<br>public:<br>    virtual void fly() { // Virtual function<br>        cout &lt;&lt; &quot;Bird flies in general.&quot; &lt;&lt; endl;<br>    }<br>    virtual ~Bird() {} // Virtual destructor for proper cleanup<br>};<br><br>// Derived class<br>class Crow : public Bird {<br>public:<br>    void fly() override { // Override the base class function<br>        cout &lt;&lt; &quot;Crow flies in a unique way.&quot; &lt;&lt; endl;<br>    }<br>};<br><br>int main() {<br>    Bird* bird1 = new Bird(); // Base class object<br>    Bird* bird2 = new Crow(); // Derived class object<br><br>    bird1-&gt;fly(); // Calls Bird&#39;s fly()<br>    bird2-&gt;fly(); // Calls Crow&#39;s fly() due to v-table<br><br>    delete bird1;<br>    delete bird2;<br><br>    return 0;<br>}<br><br></pre><pre>o/p : Bird flies in general.<br> Crow flies in a unique way. <br></pre><h3>Explanation:</h3><ul><li>When Bird is instantiated:</li></ul><p>Its v-table pointer points to the v-table of the Bird class.</p><p>The v-table contains a pointer to Bird::fly().</p><ul><li>When Crow is instantiated:</li></ul><p>Its v-table pointer points to the v-table of the Crow class.</p><p>The v-table contains a pointer to Crow::fly(), overriding Bird::fly().</p><p>When calling fly() using bird1-&gt;fly() or bird2-&gt;fly(), the program looks up the v-table pointer in the object to determine which function to call.</p><h3>Key points :</h3><p>Virtual tables allow dynamic dispatch, enabling calls to the correct function for the actual object type.</p><p>If fly() were not declared as virtual, the function calls would be resolved at compile time (static dispatch), and bird2-&gt;fly() would incorrectly call Bird::fly().</p><h3>Conclusion:</h3><p>Virtual tables in C++ are like a directory that helps objects decide which version of a function to call at runtime.</p><p>This ensures that if a `Crow` object is treated as a `Bird`, it still uses `Crow`’s custom behavior when the `fly()` function is called.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d213568d9ddc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>