<?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 Nishi Jain on Medium]]></title>
        <description><![CDATA[Stories by Nishi Jain on Medium]]></description>
        <link>https://medium.com/@nishi_jain?source=rss-75108b69586a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fK_6xl9QNs-Kaw4P0XGZWg.png</url>
            <title>Stories by Nishi Jain on Medium</title>
            <link>https://medium.com/@nishi_jain?source=rss-75108b69586a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 00:05:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nishi_jain/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[LRU Cache Implementation]]></title>
            <link>https://medium.com/@nishi_jain/lru-cache-implementation-a013bb58df54?source=rss-75108b69586a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a013bb58df54</guid>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Nishi Jain]]></dc:creator>
            <pubDate>Thu, 12 Oct 2017 10:56:32 GMT</pubDate>
            <atom:updated>2017-10-12T15:41:24.631Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is a cache ?? Why do we need it ????</h3><p>A cache is a buffer of pages OS maintains in-order to avoid expensive memory access operations. Usually cache are much more faster than main memory. Since caches are very small in size as compared to main memory, there is probability that we need to swap pages between cache and main memory. Whenever a page which is not found in cache and needs to br brought in from main memory, it is called as cache miss. LRU cache implementation is a FIFO strategy used to minimize the cache miss.</p><p>The Least Recently Used Caching scheme is used to remove the least recently used page when the cache is full whenever a new page is referenced which is not there in the cache. If the page is there in the cache then it is moved to the start of the cache. Therefore cache stores the pages in order in which they are referenced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*AH-jtC0ACtbuMl3z-XXZ1w.png" /></figure><p>LRU cache is implemented using following data structures:<br>1. <strong>Queue</strong>: A cache is implemented as a queue using doubly linked list. The size of the queue is the size of the cache. Most recently used pages are near the front end and least recently used pages are near the rear end of the queue.<br>2. <strong>HashMap: </strong>It stores the address of the nodes in the cache<strong>. </strong>It helps to find node address in O(1) time.</p><h3>Algorithm</h3><p>When a page is referenced..<br><strong>1. Check if the page is in cache</strong><br> If the page is in memory, detach the node and bring it to the front of the queue.<br><strong>2. If the page is not in cache</strong><br>If the queue is not full, add a new node to the front of the queue and update the corresponding node address in the hash. If the queue is full, remove the node from the rear of the queue and add new node to the front of the queue.</p><h3>Code</h3><p>LRU cache implementation in java.</p><pre>import java.util.*;</pre><pre>class Node{<br>   <br>   int key; <br>   <br>   //<em>pointer to the previous node</em><br>   Node prev;</pre><pre>   //<em>pointer to the next node</em><br>   Node next;</pre><pre>   Node(int key){<br>     this.key = key;<br>   }</pre><pre>}</pre><pre><em>/* LRU Cache implemented as queue using doubly linked list*/<br></em>public class LRUCache {</pre><pre>    HashMap&lt;Integer,Node&gt; map = new HashMap&lt;Integer,Node&gt;();<br>   <br>    <em>// assume that max 10 pages can be stored in a cache</em>   <br>    int capacity;</pre><pre>    // <em>number of pages that are currently present in cache</em><br>    int count = 0;</pre><pre>    Node head = null;</pre><pre>    Node end = null;</pre><pre>    LRUCache(int capacity){</pre><pre>      this.capacity = capacity;</pre><pre>    }<br></pre><pre>    void deQueueNode(){  </pre><pre>      // <em>check if queue empty</em><br>      if(count == 0){<br>         return ;<br>      }</pre><pre>      // <em>if there is only one Node in the queue</em><br>      if(count == 1){<br>        head = end = null;<br>      }</pre><pre>      end = end.prev;<br>      end.next = null;<br>      count--;</pre><pre>    }</pre><pre>    // <em>updates the head of the doubly linked list queue (i.e. cache)<br>    </em>void setHead(Node n){</pre><pre>      n.next = head;<br>      n.prev = null;</pre><pre>      if(head != null){<br>        head.prev = n;<br>      }</pre><pre>      head = n;</pre><pre>    }</pre><pre>    // <em>add the node to</em> <em>the doubly linked list queue (i.e. cache)</em><br>    Node enQueueNode(int key){</pre><pre>      Node temp;</pre><pre>      // <em>the cache is full, remove rear node and add node to front<br>      </em>if(count == capacity){</pre><pre>       map.remove(end.key);<br>       deQueueNode();</pre><pre>      }</pre><pre>      temp = new Node(key);<br>      setHead(temp);</pre><pre>      return temp;</pre><pre>    }</pre><pre>    void remove(Node n){</pre><pre>      n.prev.next = n.next;</pre><pre>      if(n.next != null){</pre><pre>       n.next.prev = n.prev;</pre><pre>      } else{</pre><pre>       end = n.prev;</pre><pre>      }</pre><pre>    }</pre><pre>    Node ReferencePage(int key){</pre><pre>      Node temp;</pre><pre>      // <em>check if the page exists in cache else get it from memory             and update the cache<br>      </em>if(map.containsKey(key)){</pre><pre>        temp = map.get(key);<br>        if(temp != head){</pre><pre>         remove(temp);<br>         setHead(temp);</pre><pre>        }</pre><pre>      } else{</pre><pre>         temp = enQueueNode(key);<br>         map.put(key, temp);</pre><pre>      }</pre><pre>      return temp;</pre><pre>    }</pre><pre>    public static void main(String args[]){</pre><pre>      LRUCache cache = new LRUCache(4);</pre><pre>      cache.ReferencePage(1);<br>      cache.ReferencePage(2);<br>      cache.ReferencePage(3);<br>      cache.ReferencePage(1);<br>      cache.ReferencePage(4);<br>      cache.ReferencePage(5);</pre><pre>      System.out.println(“Head of cache “ + cache.head.key);<br>      System.out.println(“Next of cache head” + cache.head.next.key);<br>      System.out.println(“End of cache “ + cache.end.key);</pre><pre>    }</pre><pre>}</pre><pre><strong><em>OUTPUT:<br>  </em></strong>Head of the cache: 5<br>  Next of cache head: 4<br>  End of cache: 2</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a013bb58df54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I developed my First Web Game]]></title>
            <link>https://medium.com/@nishi_jain/how-i-developed-my-first-web-game-3e5df85936f5?source=rss-75108b69586a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e5df85936f5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[snakesnladder]]></category>
            <category><![CDATA[canvas]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Nishi Jain]]></dc:creator>
            <pubDate>Mon, 11 Sep 2017 16:34:43 GMT</pubDate>
            <atom:updated>2017-09-11T16:34:43.403Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Friends ! I just created my first game and want to help you create one of yours. You can play it on <a href="http://www.nishijain.com/snakeNLadder">www.nishijain.com/snakeNLadder</a>. All our actions results from our thoughts and thoughts are all that matters. You are working on your thoughts of game development and are already through your first step. I will try to help you in your journey of developing a game and make it easier and more fun for you.</p><p>Dive into this roller-coaster step-by-step and let me describe you the challenges and the importance of each step:</p><ol><li><strong>What you want to make: </strong>Decide which game you want to make. In case you want to create any one of the classical traditional games like Ludo, snakes and ladders etc. you need not to decide game rules but if you want to create a new game from scratch, pen down all the rules for the game and how to play it. Keep all the possible moves and their outcomes in mind when you have your own game idea.</li><li><strong>Plan your game: </strong>When I say plan, I expect you to take pen and paper and plan every aspect of your game. This is the most crucial step of game development. Few aspects that you must consider while planning: <br><strong>a)</strong> It is a single-player, two-player( computer and other player) or a multi-player game. The complexity increases in case of multi-player game. I advice you to create single-player or two-player game(computer and you) in first version and convert to multi-player in version 2. <br><strong>b) </strong>Flow of the game. From the welcome page to the game over page. You should map the working model of the game from your mind to paper, mentioning every single detail. This will make development more easier.<br><strong>c) </strong>Plan to create a basic working model first, improvements and enhancements can be done progressively.</li></ol><p>This is the most crucial step for any project. Better the plan, easier the execution. WARNING: If you don’t plan your game properly there are high chances that you will fail in later stages.</p><p><strong>3.</strong> <strong>Design: </strong>Look and feel of the game makes it more interesting. Games are meant to be enchanting and should demand user-involvement. Design each page of the screen before you proceed with development. Keep it bright, full of animations and colorful.</p><p><strong>4. Game development: </strong>Get your hands dirty in code. Generally people directly jump to this step and mostly fail. This step is the execution of previous three stages. Games are fun to play but are difficult to make. HTML 5 Canvas, CSS animations and audios are the key concepts used in development.</p><p>5. <strong>Test and Launch your game: </strong>Once you have made it, test it, fix it, share it, ask for feedbacks, flaunt it on social media and feel proud.</p><p>Game development is not easy. You may fumble at each step but don’t give up. Try doing simple things first.</p><blockquote>‘Your work is the presentation of your thoughts, dress them beautifully.’<br> — Nishi Jain</blockquote><p>All the best for your upcoming game. Since this is my first blog, any feedbacks are welcomed. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e5df85936f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>