<?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 Paramhans Singh on Medium]]></title>
        <description><![CDATA[Stories by Paramhans Singh on Medium]]></description>
        <link>https://medium.com/@paramsingh13?source=rss-cad68cf5970c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*72epNj60txOvL8BKO_RWgg.jpeg</url>
            <title>Stories by Paramhans Singh on Medium</title>
            <link>https://medium.com/@paramsingh13?source=rss-cad68cf5970c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 16 May 2026 03:04:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paramsingh13/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[Linked List-Data Structure]]></title>
            <link>https://medium.com/nerd-for-tech/linked-list-data-structure-d89115b896df?source=rss-cad68cf5970c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d89115b896df</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[linked-lists]]></category>
            <dc:creator><![CDATA[Paramhans Singh]]></dc:creator>
            <pubDate>Sat, 24 Sep 2022 16:21:05 GMT</pubDate>
            <atom:updated>2022-10-05T03:50:08.785Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this blog, we will discuss about another data structure i.e. Linked List</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J38nYZU7gzu-4lQmtjlSUw.jpeg" /></figure><h3><strong>What is Linked List?</strong></h3><blockquote>A Linked List is a data structure used for storing collections of data. A linked list has the following properties:</blockquote><p>● Successive elements are connected by pointers.</p><p>● Can grow or shrink in size during the execution of a program.</p><p>● Can be made just as long as required (until systems memory exhausts).</p><p>● Does not waste memory space (but takes some extra memory for pointers). It allocates memory as the list grows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Jbgwqih6ZUbuJK8dKzKDNA.png" /></figure><h3><strong>Basic Properties of Linked List:</strong></h3><p>● Each element or node of a list is comprising of two items:</p><blockquote>○ Data</blockquote><blockquote>○ Pointer(reference) to the next node.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*sPiZVXjDe7cAd3cKQqNmqw.png" /></figure><p>● In a Linked List, the elements are not stored at contiguous memory locations.</p><p>● The first node of a linked list is known as Head.</p><p>● The last node of a linked list is known as Tail.</p><p>● The last node has a reference to null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*lt2X6ZGRznN50m7ACMxLjg.png" /></figure><h3><strong>Representation of a Linked List</strong></h3><p>This representation of a linked list depicts that each node consists of two fields. The first field consists of data, and the second field consists of pointers that point to another node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rzaiZwelH80w8Nw1ey-EWA.png" /></figure><blockquote>Here, the start pointer stores the address of the first node, and at the end, there is a null pointer that states the end of the Linked List.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*RAEMAXJki9pu0wk8C1N9nw.jpeg" /></figure><h3><strong>Creation of Node and Declaration of Linked Lists</strong></h3><p><strong>(JAVA)</strong></p><blockquote>public class Node&lt;T&gt; {</blockquote><blockquote>T data;</blockquote><blockquote>Node&lt;T&gt; next;</blockquote><blockquote>Node(T data){</blockquote><blockquote>this.data = data;</blockquote><blockquote>next = null;</blockquote><blockquote>}</blockquote><blockquote>}</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*7XXzAnt5fsEg930v6SFDWQ.png" /></figure><h3><strong>Types of Linked List</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*ZPypiQvj7iFiecOWcYNsKg.png" /></figure><p>● Singly-Linked List: Generally “linked list” means a singly linked list. Each node contains only one link which points to the subsequent node in the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*lt2X6ZGRznN50m7ACMxLjg.png" /></figure><p>● Doubly-Linked List: It’s a two-way linked list as each node points not only to the next pointer but also to the previous pointer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*MTUcSXI8ciQZiSF2DeH8kw.png" /></figure><p>● Circular-Linked List: There is no tail node i.e., the next field is never null and the next field for the last node points to the head node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*3njqftUPNYTjO1_bhbU7EA.png" /></figure><p>● Circular Doubly-Linked List: Combination of both Doubly linked list and circular linked list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*KxbpI9aajURmFh7O2hYUGw.png" /></figure><h3><strong>Essential Operations on Linked Lists</strong></h3><ul><li>Traversing: To traverse all nodes one by one.</li><li>Insertion: To insert new nodes at specific positions.</li><li>Deletion: To delete nodes from specific positions.</li><li>Searching: To search for an element from the linked list</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*oa4IGOQqbIYbjbk5V1mF5Q.jpeg" /></figure><p><strong>A. Insertion of A Node in Linked List (Iteratively)</strong></p><p><strong>(JAVA)</strong></p><blockquote>public static Node&lt;Integer&gt; insert(Node&lt;Integer&gt; head, int data, int pos){</blockquote><blockquote>Node&lt;Integer&gt; newNode = new Node&lt;Integer&gt;(data);</blockquote><blockquote>if(pos == 0){</blockquote><blockquote>newNode.next = head;</blockquote><blockquote>return newNode;</blockquote><blockquote>}</blockquote><blockquote>int i = 0;</blockquote><blockquote>Node&lt;Integer&gt; temp = head;</blockquote><blockquote>while(i &lt; pos — 1){</blockquote><blockquote>temp = temp.next;</blockquote><blockquote>i++;</blockquote><blockquote>}</blockquote><blockquote>newNode.next = temp.next;</blockquote><blockquote>temp.next = newNode;</blockquote><blockquote>return head;</blockquote><blockquote>}</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*RQd2uBUt-h2h0IMe-JXrOw.png" /></figure><p><strong>B. Insertion of Node in Linked List (Recursively)</strong></p><p><strong>(JAVA)</strong></p><blockquote>public static LinkedListNode&lt;Integer&gt; insert(LinkedListNode&lt;Integer&gt; head,int pos,int elem){</blockquote><blockquote>if (pos==0){</blockquote><blockquote>LinkedListNode&lt;Integer&gt; newNode = new LinkedListNode&lt;Integer&gt;(elem);</blockquote><blockquote>newNode.next=head;</blockquote><blockquote>return newNode;</blockquote><blockquote>}</blockquote><blockquote>if (head==null){</blockquote><blockquote>return head;</blockquote><blockquote>}</blockquote><blockquote>head.next=insert(head.next, pos-1, elem);</blockquote><blockquote>return head;</blockquote><blockquote>}</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*LoDTxbV_Vd766q6aQu3WgQ.png" /></figure><p><strong>C. Deletion of A Node in Linked List</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Fx_Fmnzo1NZgaZcf6KsPjA.jpeg" /></figure><p><strong>(JAVA)</strong></p><blockquote>public static LinkedListNode&lt;Integer&gt; deleteNodeRec(LinkedListNode&lt;Integer&gt; head, int pos) {</blockquote><blockquote>if (head==null){</blockquote><blockquote>return head;</blockquote><blockquote>}</blockquote><blockquote>if (pos==0){</blockquote><blockquote>head=head.next;</blockquote><blockquote>return head;</blockquote><blockquote>}</blockquote><blockquote>LinkedListNode&lt;Integer&gt; ans =deleteNodeRec(head.next, pos-1);</blockquote><blockquote>head.next=ans;</blockquote><blockquote>return head;</blockquote><blockquote>}</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*M6SL0PoRB2BeYLyNJUA_DQ.png" /></figure><h3><strong>Why use Linked List over Array?</strong></h3><p>Till now, we were using array data structure to organize the group of elements that are to be stored individually in the memory. However, Array has several advantages and disadvantages which must be known in order to decide the data structure which will be used throughout the program.</p><p>Array contains following limitations:</p><ol><li>The size of array must be known in advance before using it in the program.</li><li>Increasing size of the array is a time taking process. It is almost impossible to expand the size of the array at run time.</li><li>All the elements in the array need to be contiguously stored in the memory. Inserting any element in the array needs shifting of all its predecessors.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*UJSgX_5Z9AudmKfq0HOEow.png" /></figure><p>Linked list is the data structure which can overcome all the limitations of an array. Using linked list is useful because,</p><ol><li>It allocates the memory dynamically. All the nodes of linked list are non-contiguously stored in the memory and linked together with the help of pointers.</li><li>Sizing is no longer a problem since we do not need to define its size at the time of declaration. List grows as per the program’s demand and limited to the available memory space.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*ynTmgPwWLyCvK1ANvg5UUQ.png" /></figure><blockquote>I hope this blog gives you a clear understanding about linked list in data structures. If this blog helps you understand the concept so share it with your friends and feel free to share your views and drop feedback about the blog. Drop the claps if you liked the blog.</blockquote><blockquote>Hit the follow button for more such content and stay connected to know about more data structures.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d89115b896df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nerd-for-tech/linked-list-data-structure-d89115b896df">Linked List-Data Structure</a> was originally published in <a href="https://medium.com/nerd-for-tech">Nerd For Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trees-Data Structure]]></title>
            <link>https://faun.pub/trees-data-structure-5f9281385c50?source=rss-cad68cf5970c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f9281385c50</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[trees]]></category>
            <dc:creator><![CDATA[Paramhans Singh]]></dc:creator>
            <pubDate>Sun, 04 Sep 2022 17:55:46 GMT</pubDate>
            <atom:updated>2022-09-08T01:16:11.670Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>In this blog, we will discuss about another data structure i.e. Trees</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*K173emMH_S5YmVGDJLbYPA.jpeg" /></figure><h3><strong>What is Tree?</strong></h3><blockquote>A tree data structure is a <strong>non-linear</strong> data structure because it does not store in a sequential manner. It is a <strong>hierarchical structure</strong> consisting of a collection of nodes such that each node of the tree stores a value and a list of references to other nodes (the “children”).</blockquote><h3><strong>Why we need Tree as Data-Structure?</strong></h3><p>Other data structures such as arrays, linked list, stack, and queue are linear data structures that store data sequentially. In order to perform any operation in a linear data structure, the time complexity increases with the increase in the data size. But, it is not acceptable in today’s computational world.</p><p>Different tree data structures allow quicker and easier access to the data as it is a non-linear data structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*M1wVV2FrTRQrjFdh--oQOw.jpeg" /></figure><h3><strong>Why Tree is considered a non-linear Data-Structure?</strong></h3><blockquote>The data in a tree are not stored in a sequential manner i.e., they are not stored linearly. Instead, they are arranged on multiple levels or we can say it is a hierarchical structure. For this reason, the tree is considered to be a non-linear data structure.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*SCSyMwmK5pf-SiooDv-v5w.png" /></figure><h3><strong>Basic Terminologies in Tree Data-Structure:</strong></h3><ul><li><strong>Child Node:</strong> If the node is a descendant of any node, then the node is known as a child node. Like E, F, G are the children of L.</li><li><strong>Root Node:</strong> The node at the top of the tree is called root. There is only one root per tree and one path from the root node to any node. Example: P is the root node.</li><li><strong>Edge</strong>: It is the link between any two nodes.</li><li><strong>Leaf Node:</strong> The node which does not have any child node is called the leaf node.</li><li><strong>Sub-tree: </strong>Sub tree represents the descendants of a node.</li><li><strong>Descendant:</strong> The immediate successor of the given node is known as a descendant of a node. Like descendants of L are E, F, and G.</li><li><strong>Sibling:</strong> Children of the same parent node are called siblings.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*54AFwYcU4iq7-J8QL8Rn2w.png" /></figure><h3><strong>Example of Tree Data-Structure</strong></h3><p>Here,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*87h2uhCJ5qztBNwfck2b6g.jpeg" /></figure><p>Node A is the root node</p><p>D is the parent of H and I</p><p>F and G are the siblings</p><p>H, I, F and G are the leaf nodes</p><h3>Binary Search Tree Representation</h3><blockquote>Binary Search tree exhibits a special behavior. A node’s left child must have a value less than its parent’s value and the node’s right child must have a value greater than its parent value.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*l1zlkpT510DsplME6-tF_g.png" /></figure><h3><strong>Implementation of Tree Node</strong></h3><p><strong>(JAVA)</strong></p><p>import java.util.ArrayList;</p><p>public class TreeNode&lt;T&gt;{</p><p>public T data ;</p><p>public ArrayList&lt;TreeNode&lt;T&gt;&gt; children;</p><p>public TreeNode( T data){</p><p>this.data=data;</p><p>children=new ArrayList&lt;&gt;();</p><p>}</p><p>}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_AaRglzFLdqAty8tn2zGdg.jpeg" /></figure><h3>Basic Operations</h3><p>The basic operations that can be performed on a binary search tree data structure, are the following −</p><ol><li><strong>Insert</strong> − Inserts an element in a tree/create a tree.</li><li><strong>Search</strong> − Searches an element in a tree.</li><li><strong>Preorder Traversal</strong> − Traverses a tree in a pre-order manner.</li><li><strong>In-order Traversal</strong> − Traverses a tree in an in-order manner.</li><li><strong>Post-order Traversal</strong> − Traverses a tree in a post-order manner.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*9irQvyxWB7HlKhe4Jd3rQw.gif" /></figure><h3>Types of Tree Data-Structures</h3><p>The different types of tree data structures are as follows:</p><p>1.<strong> General tree</strong></p><p>A general tree data structure has no restriction on the number of nodes. It means that a parent node can have any number of child nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*uft2HV8MPglMQwv_cNcsdQ.png" /></figure><p>2. <strong>Binary tree</strong></p><p>Here, binary name itself suggests two numbers, i.e., 0 and 1. In a binary tree, each node in a tree can have utmost two child nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*VHqWAVOEKsLN1trZVgke5A.png" /></figure><p>3.<strong> Balanced tree</strong></p><p>If the height of the left sub-tree and the right sub-tree is equal or differs at most by 1, the tree is known as a balanced tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*Z0VJlb2BGzzIG7UMGAHZzQ.png" /></figure><h3>Properties of Tree Data-Structure</h3><p><strong>I. Recursive data structure:</strong> The tree is also known as a <strong><em>recursive data structure</em></strong>. A tree can be defined as recursively because the distinguished node in a tree data structure is known as a <strong><em>root node</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Uh3Zyx8Uac7TBl63JT3LiQ.png" /></figure><p><strong>II. Number of edges:</strong> If there are n nodes, then there would n-1 edges. Each arrow in the structure represents the link or path.</p><p><strong>III. Depth of node x:</strong> The depth of a node is the number of edges from the root to the node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*y9vVAZoOezIINsxtpAzLEw.png" /></figure><p><strong>IV. Height of node x:</strong> The height of a node is the number of edges from the node to the deepest leaf (that is the longest path from the node to a leaf node).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*cqJPP4N7cTZn6X9x9pQv-w.png" /></figure><h3><strong>Applications of Tree Data-Structure:</strong></h3><p>The applications of tree data structures are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MdVEubCHQdif-oddF4CG3w.jpeg" /></figure><ol><li><strong>Spanning trees:</strong> It is the shortest path tree used in the routers to direct the packets to the destination.</li><li><strong>Binary Search Tree:</strong> It is a type of tree data structure that helps in maintaining a sorted stream of data.</li><li><strong>Heap:</strong> It is also a tree data structure implemented using arrays. It is used to implement priority queues.</li><li><strong>Tries:</strong> It is a special kind of tree that is used to store the dictionary. It is a fast and efficient way for dynamic spell checking.</li><li><strong>Organize data:</strong> It is used to organize data for efficient insertion, deletion and searching. For example, a binary tree has a log N time for searching an element.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*4YCgOXnlkfnVj7xH83GEQQ.jpeg" /></figure><blockquote>I hope this blog gives you a clear understanding about trees in data structures. If this blog helps you understand the concept so share it with your friends and feel free to share your views and drop feedback about the blog. Drop the claps if you liked the blog.</blockquote><blockquote>Hit the follow button for more such content and stay connected to know about more data structures.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*mIZANKhJB0NF015c.png" /></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇</h4><h4>🚀Developers: Learn and grow by keeping up with what matters, <a href="https://faun.to/8zxxd">JOIN FAUN.</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f9281385c50" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/trees-data-structure-5f9281385c50">Trees-Data Structure</a> was originally published in <a href="https://faun.pub">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Graph — Data Structure]]></title>
            <link>https://medium.com/codex/graph-data-structure-ddbaba50accf?source=rss-cad68cf5970c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddbaba50accf</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[graphs-are-fun]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Paramhans Singh]]></dc:creator>
            <pubDate>Sun, 04 Sep 2022 05:23:24 GMT</pubDate>
            <atom:updated>2022-09-08T01:52:53.479Z</atom:updated>
            <content:encoded><![CDATA[<h3>Graph — Data Structure</h3><h4>In this blog, we will discuss one of the data structures i.e. Graphs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*3hSAy-MRkYgKIp6ybUdjjw.png" /></figure><p>A Graph is a non-linear data structure that consists of nodes and edges. The nodes are sometimes referred to as vertices and edges are the lines that connect any two nodes or vertices in the graph.</p><p>A more technical definition could be:</p><blockquote>“A <strong>Graph</strong> is a pair of sets. G = (V, E). V is the set of vertices. E is a set of edges. E is made up of pairs of elements from V (unordered pair)”</blockquote><p>Graphs are used to solve many real-life problems. Graphs are used to represent networks. The networks may include paths in a city or telephone network or circuit network. Graphs are also used on social networks like LinkedIn, and Facebook.</p><h3><strong>Graph Terminology</strong></h3><ul><li><strong>Path: </strong>It is the sequence of vertices in which each pair of successive vertices is connected by an edge.</li><li><strong>Cycle: </strong>It is a path that starts and ends on the same vertex.</li><li><strong>Simple Path: </strong>It is a path that does not cross itself that is, no vertex is repeated (except the first and the last). Also, simple paths do not contain cycles.</li><li><strong>Length of a Path: </strong>It is the number of edges in the path. Sometimes it’s the sum of weights of the edges also in case of weighted graphs.</li><li><strong>Degree of a Vertex: </strong>It is the number of edges that are incident to the vertex.</li></ul><p>Now that we have understood what graph data structure is and its terminology, so let’s move ahead and see how we can represent graphs.</p><h3><strong>Graph and its representations</strong></h3><p>A graph is a data structure that consists of the following two components:</p><p>1. A finite set of vertices also called as nodes. <br> 2. A finite set of ordered pair of the form (u, v) called as edge. The pair is ordered because (u, v) is not the same as (v, u) in case of a directed graph (di-graph). The pair of the form (u, v) indicates that there is an edge from vertex u to vertex v. The edges may contain weight/value/cost.</p><p>The following two are the most commonly used representations of a graph. <br> 1. Adjacency Matrix <br> 2. Adjacency List <br> There are other representations also like, Incidence Matrix and Incidence List. The choice of graph representation is situation-specific. It totally depends on the type of operations to be performed and ease of use.</p><h4><strong>Adjacency Matrix:</strong></h4><p>Adjacency Matrix is a 2D array of size V x V where V is the number of vertices in a graph. Let the 2D array be adj[][], a slot adj[i][j] = 1 indicates that there is an edge from vertex i to vertex j. Adjacency matrix for undirected graphs is always symmetric. Adjacency Matrix is also used to represent weighted graphs. If adj[i][j] = w, then there is an edge from vertex i to vertex j with weight w.</p><p>The adjacency matrix for the above example graph is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Rhx9zGDfRb8Yqcdj219KFQ.jpeg" /></figure><p><em>Pros:</em> Representation is easier to implement and follow. Removing an edge takes O (1) time.</p><p><em>Cons:</em> Consumes more space O (N²). Even if the graph is sparse (contains less number of edges), it consumes the same space.</p><h3><strong>Types of Graph</strong></h3><p>Following are the different types of graph:</p><ol><li><strong>Weighted Graph</strong></li></ol><p>A weighted graph is a graph in which edges have a weight. So when I say edges have a weight, what I mean to say is that they have some numbers which typically shows the cost of traversing in a graph. When we are concerned with the minimum cost of traversing the graph then what we do is find the path that has the least sum of those weights.</p><p>Example: weights can be the distances between cities or can be the fare of traveling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*UEzuesIoy-pvQFd01YSKaA.png" /></figure><p>Example of a Weighted Graph</p><p><strong>2. Unweighted Graph</strong></p><p>Unweighted graph is a graph in which edges have no weight. In such a case, edges simply show connections.</p><p>Example: edges can show the path or route between cities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*EFQWwJwsgQAD2dyTXfZ77Q.png" /></figure><p>Example of an Unweighted Graph</p><p><strong>3. Undirected Graph</strong></p><p>These type of graphs have no implied direction on edges between the nodes. Edge can be traversed in either direction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*jiMqrGwKrtLrlE9g7woORQ.png" /></figure><p>Example of a Undirected Graph</p><p><strong>4. Null Graph</strong></p><p>A graph is known as a null graph if there are no edges in the graph.</p><p><strong>5. Trivial Graph</strong></p><p>Graph having only a single vertex, it is also the smallest graph possible.</p><p><strong>6. Regular Graph</strong></p><p>The graph in which the degree of every vertex is equal to the other vertices of the graph. Let the degree of each vertex be <strong>K</strong> then the graph</p><p><strong>7. Complete Graph</strong></p><p>The graph in which from each node there is an edge to each other node.</p><h3><strong>Tree v/s Graph</strong></h3><p>Trees are the restricted types of graphs, just with some more rules. Every tree will always be a graph but not all graphs will be trees. Linked List, Trees and Heaps all are special cases of graphs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*SCSyMwmK5pf-SiooDv-v5w.png" /></figure><blockquote>I hope this blog gives you a clear understanding about graphs in data structures. If this blog helps you understand the concept so share it with your friends and feel free to share your views and drop feedback about the blog. Drop the claps if you liked the blog.</blockquote><blockquote>Hit the follow button for more such content and stay connected to know about more data structures.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddbaba50accf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/graph-data-structure-ddbaba50accf">Graph — Data Structure</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>