<?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 Tanvi Bhatia on Medium]]></title>
        <description><![CDATA[Stories by Tanvi Bhatia on Medium]]></description>
        <link>https://medium.com/@tanvibhatia?source=rss-3d1537b97a30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*DqqelYfS7BNlscKQN1GneQ.jpeg</url>
            <title>Stories by Tanvi Bhatia on Medium</title>
            <link>https://medium.com/@tanvibhatia?source=rss-3d1537b97a30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:36:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tanvibhatia/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[Part 3 — Linked List Data structure in js]]></title>
            <link>https://medium.com/@tanvibhatia/part-3-linked-list-data-structure-in-js-5d2098d6f131?source=rss-3d1537b97a30------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d2098d6f131</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[linked-lists]]></category>
            <dc:creator><![CDATA[Tanvi Bhatia]]></dc:creator>
            <pubDate>Mon, 18 Nov 2019 10:19:46 GMT</pubDate>
            <atom:updated>2019-11-18T10:19:46.303Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 3 — Linked List Data structure in js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AnqpGt9aWJY12wjeE_qXyw.png" /></figure><h3>Introduction</h3><p>A Linked list is a linear data structure in which every element contains information about the data it holds and a pointer to next element. Each such element in a linked list is called as node. The nodes may be at different memory locations, unlike arrays where all the elements are stored continuously.</p><h3>Types of Linked Lists</h3><p>A linked list is designed depending on its use. The 3 most common types of a linked list are:</p><ol><li><strong>Singly Linked List — </strong>This is the most common type of linked list, where each node has <strong>one pointer</strong> to the next node in the sequence. This means that the list can only be traversed from the beginning to the end in <strong>one direction</strong>. In this section, we will focus on implementation and operations of a singly linked-list.</li><li><strong>Doubly Linked List — </strong>A doubly linked list has 2 pointers, one pointing to the next node and one to the previous node. This allows for moving in both directions while traversing.</li><li><strong>Circular Linked List — </strong>A circular linked list is like a regular one except for the last element of the list pointing to the first. This has the advantage of allowing to go back back to the first element while traversing a list without starting over.</li></ol><h3><strong>Implementation</strong></h3><p>In order to implement a linked list, we have to define a root node while creating a linked list which will point to null initially. To insert data in a linked list, we will create a Node constructor which will create a node with data and next pointer.</p><p>Below is the implementation :</p><pre>function LinkedList() {<br>    this.root = null;<br>}</pre><pre>function Node(value) {<br>    this.value = value;<br>    this.next = null;<br>}</pre><pre>// This will create an empty linked-list<br>let list = new LinkedList();</pre><p>An empty linked-list can be created using above implementation but we still cannot add any data to our linked-list. In the operations section, we will add more operations to the linked-list such as insert, insertAt , removeAt, search, findMiddle, etc.</p><h3>Operations</h3><p>Numerous operations can be performed on a linked-list. For the understanding sake, we will focus on basic operations listed below:</p><pre>Insert at the end of the list - <strong>insertEnd()</strong><br>Find a value in the list - <strong>search(value)</strong><br>Find Length of a linked-list - <strong>getSize()</strong><br>Delete value from Linked List - <strong>deleteValue(value)</strong><br>Print middle element of a linked list - <strong>printMiddle()</strong><br>Get Nth node in a LinkedList - <strong>getNthNode()</strong><br>Print List values - <strong>printList()</strong></pre><h4>Insert At the end of the list</h4><pre>LinkedList.prototype.insertAt = function insertAt(value, node){<br>	if(node == null){<br>		return new Node(value);<br>	} else {<br>		node.next = insertAt(value, node.next);<br>		return node;<br>	}<br>}<br><br>LinkedList.prototype.insert = function(value, node){<br>	this.root = this.insertAt(value, this.root);<br>}</pre><h4>Find a value in the list</h4><pre>LinkedList.prototype.search = function search(value, node) {<br>    if(node === undefined){<br>        node = this.root;<br>    }<br>    if(node === null) {<br>        return &quot;Not found&quot;;<br>    }<br>    if(node.value === value) {<br>        return node;<br>    } else {<br>        return search(value, node.next);<br>    }<br>  return &quot;Not found&quot;;<br>}</pre><h4>Find Length of a linkedList</h4><pre>LinkedList.prototype.getSize = function(){<br>    let current = this.root;<br>    let count = 0;<br>    while(current !== null){<br>	count++;<br>	current = current.next;<br>    }  <br>    return count;<br>}</pre><h4>Delete value from Linked List</h4><pre>LinkedList.prototype.deleteValue = function(value){<br>	let current = this.root;<br>	if(current === null){<br>		return new Error(&quot;cannot delete from an empty list&quot;);<br>	}<br>	if(current.value === value){<br>		this.root = current.next;<br>		return;<br>	}<br>	let prev;<br>	while(current.next !== null){<br>		prev = current;<br>		current = current.next;<br>		if(current.value === value){<br>			let temp = current.next;<br>			prev.next = temp;<br>			return;<br>		}<br>	}<br>	return &quot;value not found&quot;;<br>}</pre><h4>Print middle element of a linked list</h4><pre>LinkedList.prototype.printMiddle = function(){<br>	let slowRef = this.root;<br>	let fastRef = this.root;<br>	while( fastRef !== null &amp;&amp; fastRef.next !== null){<br>		slowRef = slowRef.next;<br>		fastRef = fastRef.next.next;<br>	}<br>	console.log(slowRef.value);<br>}</pre><h4>Get Nth node in a LinkedList</h4><pre>LinkedList.prototype.getNthNode = function(n){<br>	let current = this.root;<br>	let i = 0;<br>	while(current !== null){<br>        if(n === i){<br>        	return current.value;<br>        }<br>		current = current.next;<br>		i++;<br>	}<br>	return &quot;not found&quot;;<br>}</pre><h4>Print List</h4><pre>LinkedList.prototype.print = function printNode(node = this.root){<br>    if(node == null) return;<br>    console.log(node.value);<br>    printNode(node.next);<br>}</pre><h3>Time Complexity</h3><p>Linked list is again a linear data structure hence to access any element, we have to iterate through each node one by one until we reach the required element. The time complexity is therefore <strong>O(n)</strong>.</p><p>In case of insertion and deletion, time complexity varies depending upon the location. If we are inserting or deleting from the beginning, time complexity will be O(1). For all other cases, it’s O(n).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*oUdjqjTauG44Hr2UzdS__g.png" /></figure><h3>Usage</h3><ol><li>Linked-lists are generally used to implement other data structures such as stacks, queues and non-linear ones like trees and graphs.</li><li>It has uses in hash chaining for the implementation in open chaining.</li><li>Polynomials can be represented and manipulated by using linked lists.</li><li>It can be used to perform operations on long integers.</li></ol><h3>Conclusion</h3><p>In this section, we got a good understanding of linked list, its implementation and uses. There are a lot of operations related to a linked list. I will recommend you to spend good amount of time in understanding and implementing such operations on a linked list. In the next section, we will continue our exploration with other linear and non-linear data structures. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d2098d6f131" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2— Queue Data Structure in js]]></title>
            <link>https://medium.com/@tanvibhatia/part-2-queue-data-structure-in-js-c5256c523c10?source=rss-3d1537b97a30------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5256c523c10</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[queue]]></category>
            <dc:creator><![CDATA[Tanvi Bhatia]]></dc:creator>
            <pubDate>Mon, 28 Oct 2019 08:57:17 GMT</pubDate>
            <atom:updated>2019-10-29T05:52:28.100Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*haWT3MxhllbrLXN6WEk8FQ.png" /></figure><h3>Introduction</h3><p>A queue is a linear data structure that stores data in FIFO(First In First Out) order i.e. whatever goes in first comes out first. Earlier we have seen stack ds which supports LIFO(Last in first out) order i.e. insertion and deletion will both happen from one end. However, in the case of the queue, the insertion will happen from one end(rear) and removal will happen from another end(front). Queue means exactly the same as it means in the real world.</p><h3>Operations</h3><p>There are 2 primary operations in a Stack. Enqueue operation and dequeue operation. Enqueue operation is to add data to the rear end of the queue. Dequeue is to remove data from the front of the queue. Some additional operations are front (or peek) to check the first element of the queue, isEmpty to check whether queue is empty, etc.</p><h3>Implementation</h3><p>We can simply create a queue with the Array Data structure. The array support push method by default. In order to support additional methods, we will create a Queue Object with the methods we need. Our queue API will have the following methods:</p><pre>enqueue<br>dequeue<br>front<br>isEmpty<br>search</pre><p>Implementation goes as below:</p><pre>function Queue(){<br>   this.items = [];<br>}<br>Queue.prototype.enqueue = function(ele){<br> this.items.push(ele);<br>}<br>Queue.prototype.isEmpty = function(){<br> return this.items.length === 0;<br>}<br>Queue.prototype.dequeue = function(){<br> if(this.isEmpty()){<br>  return &quot;Empty Queue&quot;;<br> }<br> this.items.splice(0,1);<br>}<br>Queue.prototype.front = function(){<br>   if(this.isEmpty){<br>      return &quot;Empty Stack&quot;;<br>   }<br>   return this.items[0];<br>}<br>Queue.prototype.search = function(item){<br>   if(this.isEmpty){<br>      return &quot;Empty Queue&quot;;<br>   }<br>   for(let i = 0; i &lt; this.items.length; i++){<br>      if(this.items[i] === item){<br>      return `item ${item} found at index ${i}`;<br>   }<br>   return &quot;item ${item} not found in the queue&quot;<br>}</pre><h3>Time Complexity</h3><h3>Access and Search Operation</h3><p>In order to access an element in the queue, we have to keep shifting elements until we find the one we are looking for. The worst-case is element is present at the rear end of the queue.N movements are required. The best case is element is present at the front of the queue hence 1 movement is required. The average case is n/2 which can be represented asymptotically as O(n);</p><h3>Insert, delete and front Operation</h3><p>Insertion can be done only at the rear end hence complexity is O(1),</p><p>Similar to insertion, front and deletion are possible from the front of the queue hence time complexity will be O(1).</p><p>For accessing an element, we have to keep moving elements until we fin=d the match. The worst-case will be O(n), best case will be O(1). The average case will be O(n/2) which can be asymptotically represented as O(n).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/0*7IqI1o88-Sdni8Ux.png" /></figure><h3>Applications</h3><p>Queues are commonly used where things don&#39;t need to be processed immediately but in First in, First out order. Below is a list of some applications of a queue.</p><ol><li><strong>CPU resource sharing- </strong>When multiple processes are sharing common CPU resources, queue data structures are used to enqueue process until the resource is busy.</li><li><strong>Asynchronous Data transfer- </strong>When data is transferred asynchronously between two processes, generally queues are used to keep a track of the process.</li></ol><h3>Conclusion</h3><p>In this section, we learned about the queue as an abstract data type, its implementation, and common applications. As usual, I would recommend you to practice its implementation and related problems to get a good hold of it. In the next section, we will learn about the linked list and its implementation. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5256c523c10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2 — Stack Data Structure in js]]></title>
            <link>https://medium.com/@tanvibhatia/part-2-stack-data-structure-in-js-4f7803b9f02e?source=rss-3d1537b97a30------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f7803b9f02e</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tanvi Bhatia]]></dc:creator>
            <pubDate>Thu, 17 Oct 2019 10:45:37 GMT</pubDate>
            <atom:updated>2019-10-24T10:36:02.009Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 1— Stack Data Structure in js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*3On_fWDPTnPGHyYLQcVNQA.png" /></figure><h4>Introduction</h4><p>Stack is a data structure that stores data in LIFO(Last In First Out) order i.e. last value inserted will be at the top and the first one to come out. It is one of the linear data structures i. e. data is stored in a particular order. Only the top item of a stack is accessible at a time. Imagine a stack of plates. In order to add or remove a plate from the stack, you will have to start from the top.</p><h4>Operations</h4><p>There are 2 primary operations in a Stack. Push operation and pop operation. We can add additional methods to check if the stack is empty, peek a value, print stack values, etc.</p><h4>Implementation</h4><p>We can simply create a stack with the Array Data structure. Array supports push and pop methods by default. In order to support additional methods, we will create a Stack Object with the methods we need. Our stack API will have the following methods:</p><pre>push<br>pop<br>peek<br>isEmpty<br>search</pre><p>Implementation goes as below:</p><pre>function Stack(){<br>   this.items = [];<br>}</pre><pre>Stack.prototype.isEmpty = function(){<br>   return this.items.length === 0;<br>}</pre><pre>Stack.prototype.push = function(item){<br>   this.items.push(item)<br>}</pre><pre>Stack.prototype.pop = function(){<br>   if(this.isEmpty){<br>      return &quot;Empty Array&quot;;<br>   }<br>   return this.items.pop();<br>}</pre><pre>Stack.prototype.peek = function(){<br>   if(this.isEmpty){<br>      return &quot;Empty Stack&quot;;<br>   }<br>   return this.items[this.items.length - 1]<br>}</pre><pre>Stack.prototype.search = function(item){<br>   if(this.isEmpty){<br>      return &quot;Empty Stack&quot;;<br>   }<br>   for(let i = 0; i &lt; this.items.length; i++){<br>      if(this.items[i] === item){<br>      return `item ${item} found at index ${i}`;<br>   }<br>   return &quot;item ${item} not found in the stack&quot;<br>}</pre><h4>Time Complexity</h4><h4><strong>Access and Search Operation</strong></h4><p>In order to access an element in the stack, we have to keep removing elements until we find the one we are looking for. The worst-case is element is present at the bottom of stack.N movements are required. The best case is element is present at the top hence 1 movement is required. The average case is n/2 which can be represented asymptotically as O(n);</p><h4>Insert, delete and peek Operation</h4><p>Insertion, deletion and peek can only be done from the top of the stack hence time complexity will be O(1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*uTE9Z3egubXE-LH6joWChg.png" /></figure><h4>Usage</h4><p>Stacks are commonly used in lots of complex algorithms to reduce the complexity of the problems. Below is a list of some common problems which use the stack. I will recommend you to practice solutions of each of these problems to master stack and its applications.</p><ol><li><strong>Implement Stack using queue</strong></li><li><strong>The stock-span problem</strong></li><li><strong>UNDO functionality</strong></li><li><strong>Parentheses checker</strong></li><li><strong>Expression parsing</strong></li></ol><h4>Conclusion</h4><p>In this section, we got a good understanding of stack as an abstract data type, its implementation, and common applications. Before moving further, my recommendation would be to practice its implementation and related problems to get a good hold of it. In the next section, we will continue our exploration with other linear and non-linear data structures. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f7803b9f02e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[This is part 1 of the series Data structures in Javascript.]]></title>
            <link>https://medium.com/@tanvibhatia/this-is-part-1-of-the-series-data-structures-in-javascript-750b08180a61?source=rss-3d1537b97a30------2</link>
            <guid isPermaLink="false">https://medium.com/p/750b08180a61</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tanvi Bhatia]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 09:54:54 GMT</pubDate>
            <atom:updated>2019-11-18T10:21:32.404Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Structures in Javascript — Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6BFz98EzF0y2MSAUzHu4nQ.png" /></figure><p>In this section, we will start with an introduction to the data structure and its types. I have created a part 5 series of various data structures and their implementation in javascript. In the following sections, we will go through each data structure and its implementation in detail. Let&#39;s begin</p><h4>Introduction</h4><p>A journey from a bad programmer to a good programmer starts with understanding the fundamentals. Good programmers understand the need for organizing the application data in the best way possible. Learning data structures is a very important step towards being a better programmer.</p><blockquote>Smart data structure and dumb code work a lot better than the other way round.</blockquote><blockquote>- <strong>Eric. S Raymond</strong></blockquote><p>A data structure is a way to organize data for efficient access and modification. Data should be structured in such a way that it reduces the complexity and increases the efficiency.</p><p>According to Wikipedia</p><blockquote>A <strong>data structure</strong> is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.</blockquote><p>There are various types of data structures. The choice of a particular one can be considered based on the following points:</p><ol><li>It should process the data efficiently when necessary.</li><li>It should represent the inherent relationship of the data in the real world.</li></ol><h4>Why learn Data Structures?</h4><blockquote>“Bad programmers worry about the code. Good programmers worry about data structures and their relationships.”</blockquote><blockquote>Linus Torvalds</blockquote><p>To understand the importance of structuring data, let’s take an example from the real world. Imagine a language dictionary. How easy it is for us to search for a word since its organized in an alphabetical sequence. Had the words been stored in any random manner, how much time and effort it will take to look for a word.</p><p>Same is true for software applications. Both time and effort are required to process any instruction. Every CPU cycle that is saved will affect both the time and energy consumed and can be put to better use in processing other instructions.</p><p>A program built using improper data structures will be inefficient or unnecessarily complex. It is, therefore, necessary to have a good knowledge of data structures and understand where to use the best one.</p><h4>Types of Data structures</h4><p>Data structures can be broadly categorized into 2 categories :</p><p>1. <strong>Linear</strong> — Linear data structures store elements in sequential order. Every element in linear ds contains an element before or after it. eg Array, LinkedList, stack, queue, etc.</p><p>2- <strong>Non- linear </strong>— Non-linear structures does not store elements in a certain manner or order. It could be hierarchial. Elements which are stored in a non- linear data structure have certain relationship among them while being stored or retrieved. eg Trees, Graphs, etc.</p><h4>Conclusion</h4><p>In the programming world, data dominates. How we store, access and manage data matters as it directly affects speed, scalability, and maintainability of the software application. My motto in this series is to make you understand the usage and implementation of different data structures from a front-end perspective. I will be using Javascript language for implementation. Stay tuned!</p><p><strong>Next sections</strong></p><p><a href="https://medium.com/@tanvibhatia/part-2-stack-data-structure-in-js-4f7803b9f02e?sk=49faff972dd3d9da48702aa784916fff">Part 1 — Stack data structure in Javascript</a></p><p><a href="https://medium.com/@tanvibhatia/part-2-queue-data-structure-in-js-c5256c523c10">Part 2 — Queue data structure in Javascript</a></p><p><a href="https://medium.com/@tanvibhatia/part-3-linked-list-data-structure-in-js-5d2098d6f131?source=friends_link&amp;sk=7e9b3bdf386886681c067fc8b71c4b56">Part 3 — Linked list data structure in Javascript</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=750b08180a61" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>