<?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[Data Structure - Medium]]></title>
        <description><![CDATA[A complete tutorial on data strutures. - Medium]]></description>
        <link>https://medium.com/data-structure?source=rss----7d45d48618a1---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Data Structure - Medium</title>
            <link>https://medium.com/data-structure?source=rss----7d45d48618a1---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 10:40:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/data-structure" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[#6. Pointers]]></title>
            <link>https://medium.com/data-structure/6-pointers-4e61beaf0d5f?source=rss----7d45d48618a1---4</link>
            <guid isPermaLink="false">https://medium.com/p/4e61beaf0d5f</guid>
            <category><![CDATA[pointers]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[H@rsh Kumar]]></dc:creator>
            <pubDate>Sat, 06 Jul 2019 08:25:40 GMT</pubDate>
            <atom:updated>2019-07-06T08:25:40.172Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AdNVc-xfnGUHLOPJ" /><figcaption>Photo by <a href="https://unsplash.com/@oowgnuj?utm_source=medium&amp;utm_medium=referral">Jungwoo Hong</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A pointer is a variable that stores memory address. Like all variables it also has a name, has to be declared and occupies some space in memory. It is called pointer because it points to a particular location in the memory by storing the address of that location. The use of the pointer makes the code more efficient and compact. Some of the uses of pointers are —</p><ul><li>Accessing array elements.</li><li>Returning more than one value from a function.</li><li>Accessing more than one value from a function.</li><li>Implementing data structures like linked-list, trees, and graphs.</li></ul><h3>Declaration of a Pointer Variables:</h3><p>Like other variables, pointer variables should also be declared before being used. The general syntax of the declaration is —</p><pre>data_type *pointer_name;</pre><p>Here, pointer_name is the name of the pointer variable, which should be a valid C identifier. The asterisk ‘ * ’ preceding this name informs the compiler that the variable is declared as a pointer. Here, data_type is known as the base type of pointer. For example,</p><pre>int *ptr;<br>float *fptr;<br>char *cptr;</pre><p>Here, ptr is a pointer that should point to a variable of type int; similarly fptr is a pointer that should point to float a variable.</p><blockquote>Note: we can also combine the declaration of simple variables and pointer variables.</blockquote><p>Pointers are also variables so the compiler will reserve space for them and they will also have some address. All pointers irrespective of their base type will occupy the same space in memory since all of them contain address only. The size of the pointer depends on the architecture and may vary on different machines.</p><h3>Assigning Address to a Pointer Variable:</h3><p>When we declare a pointer variable it contains garbage value i.e. it may be pointing anywhere in the memory. So we should always assign an address before using it in the program. The use of an unassigned pointer may give unpredictable results and even cause the program to crash.</p><p>Pointers may be assigned the address of a variable using assignment statement. For example,</p><pre>int *ptr,var = 10;<br>float *fptr, sal = 1400.50;<br>ptr = &amp;var;<br>fptr = &amp;sal;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*Gd1s7eT8WN1qT7PywPVzHw.png" /></figure><p>Now, ptr contains the address of the variable age i.e. it points to variable age. similarly with the fptr .</p><blockquote>Note: If we assign the address of some other data type than compiler won’t show any error but the output will be incorrect.</blockquote><p>It is also possible to assign the value of one pointer to the other, provided their base type is same. For example, if we have integer pointer p1 then we can assign the value of ptr to it.</p><p>We can assign constant <strong>zero </strong>to a pointer of any type. A symbolic constant <strong>NULL </strong>is defined in the header file stdio.h, which denotes the value zero. The assignment of NULL to a pointer guarantees that is does not point to any valid memory location.</p><h3><strong>Dereferencing Pointer Variables:</strong></h3><p>We can access a variable indirectly using pointers. For this, we will use the indirection operator ( * ). By placing the indirection operator before a pointer variable, we can access the variable whose address is stored in the pointer. For example,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef33b3d22ab9680824075d21ff10500b/href">https://medium.com/media/ef33b3d22ab9680824075d21ff10500b/href</a></iframe><h3>Pointer To Pointer:</h3><p>We know that pointer is a variable that can contain a memory address. The pointer variable takes some space in memory and therefore it also has an address. We can store the address of a pointer in some other variable which is known as a <strong>pointer to pointer.</strong> Similarly, we can have a pointer to pointer to a pointer variable and this concept can be extended to any limit. Pointer to a pointer variable is generally used while passing pointer variables to the function. The syntax of declaring a pointer to pointer is as —</p><pre>data_type **variable_name;</pre><p>The double asterisk used in the declaration informs the compiler that a pointer to pointer is being declared. For example,</p><pre>int num= 5;<br>int *ptr1 = &amp;num;<br>int **ptr2 = &amp;ptr1;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*-tiemAbMrv8VtuhiEgysFg.png" /><figcaption>the pointer to the pointer variable</figcaption></figure><p>we know that *ptr1 gives the value of num , similarly *ptr2 gives the value of ptr1 . Now let us see what value will be given by **ptr2 .</p><ul><li>**ptr2</li><li>*(*ptr2)</li><li>*ptr1 (since *ptr2 = ptr1)</li><li>num</li></ul><p>Hence we can see that **ptr2 will give the value of num .</p><p>In the next lecture, we will cover the uses of pointers in the programs.</p><p>For full course please visit the publication.</p><p><a href="https://medium.com/data-structure">Data Structure</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e61beaf0d5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-structure/6-pointers-4e61beaf0d5f">#6. Pointers</a> was originally published in <a href="https://medium.com/data-structure">Data Structure</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#5. Two Dimensional Arrays]]></title>
            <link>https://medium.com/data-structure/5-two-dimensional-arrays-c98e3bcc464f?source=rss----7d45d48618a1---4</link>
            <guid isPermaLink="false">https://medium.com/p/c98e3bcc464f</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[2d-arrays]]></category>
            <dc:creator><![CDATA[H@rsh Kumar]]></dc:creator>
            <pubDate>Tue, 02 Jul 2019 19:02:33 GMT</pubDate>
            <atom:updated>2019-07-02T19:02:32.933Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FAnd42paKlLmU6SY" /><figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;utm_medium=referral">Clément H</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this lecture, we are covering 2-D arrays. If you haven&#39;t gone through other lectures, I suggest you take a look at the full course at <a href="https://medium.com/data-structure">https://medium.com/data-structure</a></p><p>Two-dimensional arrays are like array inside an array. It forms a matrix structure in which each index of the array contains another array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*5hP5_WFcl4C-fk2rNkJWjQ.png" /><figcaption>2-D array representation</figcaption></figure><h3>Declaration and Accessing Individual Elements of 2-D Arrays:</h3><p>The syntax of the declaration of a 2-D array is similar to the 1-D array, but here we have two subscripts. The syntax is -</p><pre>data_type array_name[row_size][column_size]</pre><p>Here row_size specifies the number of rows and column_size specifies the number of columns in the array. The total number of elements in the array are row_size * column_size . For example,</p><p>int a[3][4];</p><p>Here a is a 2-D array with 3 rows and 4 columns. The individual elements of this array can be accessed by applying two subscripts, where the first subscript denotes the row number and the second subscript denotes the column number. The structure of arr looks like this,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*algZCYefzQcl6Rk8Q9QeLg.jpeg" /></figure><h3>Processing 2-D Arrays:</h3><p>For processing 2-D arrays, we use two nested loops. The outer loop corresponds to ‘row’ and the inner loop corresponds to the ‘column’. For example,</p><p>int arr[4][5];</p><ul><li>Reading values in arr</li></ul><pre>for(i=0;i&lt;4;i++){<br>   for(j-0;j&lt;5;j++){<br>      scanf(&quot;%d&quot;,&amp;arr[i][j]);<br>   }<br>}</pre><ul><li>For displaying values of arr</li></ul><pre>for(i=0;i&lt;4;i++){<br>   for(j=0;j&lt;5;j++){<br>      printf(&quot;%d&quot;,arr[i][j]);<br>   }<br>}</pre><h3>Initialization of 2-D Arrays:</h3><p>2-D arrays can be initialized in a way similar to that of 1-D arrays. For example,</p><pre>int arr[4][3] = {1,2,3,4,5,6,7,8,9,10,11,12};</pre><p>These values are assigned to the elements in a row-wise manner, so the values of elements are:</p><pre>arr[0][0] = 1<br>arr[0][1] = 2<br>....<br>arr[3][2] = 12</pre><p>While initializing we can group the elements row-wise using inner braces. For example,</p><pre>int arr[4][3] = { {1,2,3,4}, {5,6,7,8}, {9,10,11,12}};</pre><blockquote>Note: It is optional to specify the first dimension while initializing but the second dimension should always be present. For example,</blockquote><pre>int arr[][3] = { {1,0}, {2,20,10}, {4}}</pre><blockquote>A 2-D array is also known as a <strong>matrix.</strong></blockquote><p>Now let have a simple program to add two matrices, the order of both matrices should be the same.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/757af31f72e3ffdd61b4c978f91dfc32/href">https://medium.com/media/757af31f72e3ffdd61b4c978f91dfc32/href</a></iframe><p>That’s it for this lecture. You can view the full course on the publication page.</p><p><a href="https://medium.com/data-structure">Data Structure</a></p><p>In the next lecture will we cover the concepts of <strong>Pointers </strong>and its uses in the data structure. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c98e3bcc464f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-structure/5-two-dimensional-arrays-c98e3bcc464f">#5. Two Dimensional Arrays</a> was originally published in <a href="https://medium.com/data-structure">Data Structure</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#4. The World of Arrays]]></title>
            <link>https://medium.com/data-structure/4-the-world-of-arrays-3d9850575d8b?source=rss----7d45d48618a1---4</link>
            <guid isPermaLink="false">https://medium.com/p/3d9850575d8b</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[c-program]]></category>
            <dc:creator><![CDATA[H@rsh Kumar]]></dc:creator>
            <pubDate>Tue, 02 Jul 2019 16:14:15 GMT</pubDate>
            <atom:updated>2019-07-02T16:14:15.704Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DTypMcNrxp0Zx2m3" /><figcaption>Photo by <a href="https://unsplash.com/@curtismacnewton?utm_source=medium&amp;utm_medium=referral">Curtis MacNewton</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Now, After learning a lot of introduction, you are in a position to deep dive into the Array. So, let roll out the beginning.</p><h3>What is an Array?</h3><p>An Array is a collection of similar type of data items and each data item is called an element of the array. The data type of the elements may be any valid data type like char, int or float. The elements of the array share the same variable name but each element has a different index number known as a subscript.</p><p>For example, let “ages” be an array of size 10 containing the age of different employees of the company. Then the individual elements of this array are:</p><pre>ages[0],ages[1],ages[2],ages[3],ages[4],....,ages[7],ages[8],ages[9]</pre><blockquote>Note: In C language, the subscripts start from zero, so age[0] is the first element, age[1] is the second element of the array and so on.</blockquote><h3>Types of Arrays:</h3><p>Now, here comes the different categories of array based on dimensions:</p><ol><li>One Dimensional Array (1D Array).</li><li>Two Dimensional Array (2D Array).</li><li>Multi-Dimensional Array (3D, 4D, … )</li></ol><blockquote>Basically, there are only 2 categories of an array as One dimensional and Multidimensional. But for ease, here I am categorizing it into 3 parts.</blockquote><h3>One Dimensional Array:</h3><p>The one-dimensional array is simply an array of one subscript like ages[n], (where n denotes the length of the array).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*qkjB6Jcahygf1xF4AsfiLQ.png" /><figcaption>one-dimension array</figcaption></figure><h4>Declaration of 1-D Array:</h4><p>Like other simple variables, arrays should also be declared before they are used in the program. The syntax for declaration of an array is -</p><pre>data_type array_name[size]</pre><p>Here, array_name denotes the name of the array and it can be any valid C identifier, data-type is the data type of the elements of the array. The size specifies the number of elements that can be stored in the array. It may be +ve integer constant or constant integer expression. Eg.</p><pre>int age[10]<br>float salary[20+10]<br>char grade[(20*10)/10]</pre><p>when the array is declared, the compiler allocates space in memory sufficient to hold all the elements of the array should be known at the compile time. Hence we can’t use variables for specifying the size of the array in the declaration. The symbolic constants can be used to specify the size of the array. For example,</p><pre>#define SIZE 10<br>main(){</pre><pre>  int size = 15;<br>  float sal[SIZE]; // valid<br>  int marks[SIZE]; // Invalid<br>}</pre><h4>Accessing 1-D Array Elements:</h4><p>The elements of an array can be accessed by specifying the array name followed by subscript in the bracket. In C, the array subscript starts from 0. Hence if there is an array of size 5 then the valid subscripts will be from 0 to 4.</p><blockquote>The last valid subscript is one less than the size of the array. The last valid subscript is known as the upper bound of the array.</blockquote><p>Now, let’s see a simple program that uses array. This will also make clear how to use an array and access data from that array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0084371be3c25f2272b5e9a442a89e8d/href">https://medium.com/media/0084371be3c25f2272b5e9a442a89e8d/href</a></iframe><pre>Output : Total Salary 7000</pre><h4>Processing 1-D Arrays:</h4><p>For processing arrays, we generally use a for loop and the loop variable is used at the place of the subscript. The loop variable is increased by 1 each time so that we can access and process the next element in the array. The total number of passes in the loop will be equal to the number of elements in the array and in each pass we will process one element. Suppose ‘arr’ is an array of type int then —</p><p>For reading values of arr:</p><pre>for(i=0; i&lt;10; i++)<br>  scanf(&quot;%d&quot;,&amp;arr[i]);</pre><p>For displaying values of arr:</p><pre>for(i=0; i&lt;10; i++)<br>  printf(&quot;%d&quot;,arr[i]);</pre><p>Adding all the elements of arr:</p><pre>sum = 0;<br>for(i=0; i&lt;10; i++)<br>  sum += arr[i];</pre><h4>Initialization of 1-D Arrays:</h4><p>After declaration, the elements of the local array have garbage value while the elements of global and static arrays are automatically initialized to zero. We can explicitly initialize arrays at the time of declaration. The syntax for initialization of an array is —</p><pre>data_type array_name[size] = {value1, value2, value3, ... , valueN};</pre><p>Here array_name is the name of the array variable, size is the size of the array and value1, value2, .... valueN are the constant values known as initializers, which are assigned to the array elements one after another. These values are separated by commas and there is a semicolon after ending braces. For example,</p><pre>int marks[5] = {50, 85, 50, 65, 70}</pre><blockquote>Note: while initializing a 1-D array, it is optional to specify the size of the array. If the size is omitted during initialization then the compiler assumes the size of the array equal to the number of initializers.</blockquote><h4>Important points to be considered:</h4><ul><li>If during the initialization the number of initializers is less then the size of the array, then all the remaining elements of the arrays are assigned value zero. For example,</li></ul><pre>int marks[5] = {80, 70}</pre><p>Here, the size of the array is 5 while there are only 2 initializers. After this initialization, the value of the remaining elements of the array is assigned with value zero.</p><ul><li>If the number of initializers is more than the size given in brackets then the compiler will show an error.</li><li>We cannot copy all the elements of an array to another array by simply assigning it to the other array. For example,</li></ul><pre>int arr1[] = {1,2,3,4,5,6}<br>int arr2[6];<br>arr2 = arr1  // Invalid Statement</pre><p>we will have to copy all the elements of the array one by one using a loop.</p><pre>for(i=0;i&lt;6;i++)<br>  arr2[i] = arr1[i];</pre><h4>1-D Arrays and Functions:</h4><ol><li><strong>Passing individual elements to a function:</strong></li></ol><p>We know that an array element is treated as any other simple variable in the program. So like other variables, we can pass individual elements as arguments to a function. For example,</p><pre>void func(int num){<br>  ------------<br>}<br>void main(){<br>  int arr[] = {1,2,3};<br>  func(arr[0]);  // passing individual element of an array<br>}</pre><p>2. <strong>Passing the whole Array to a function:</strong></p><p>We can pass the whole array as an actual argument to a function. The corresponding formal argument should be declared as an array variable of the same data type.</p><pre>main(){<br>   int arr[10];<br>   .............<br>   .............<br>   func(arr);<br>}<br>func(int val[10]){<br>  ..............<br>  ..............<br>}</pre><blockquote>Note: It is optional to specify the size of the array in the formal argument (i.e the argument defined in the function)</blockquote><blockquote>The mechanism of passing an array to a function is quite different from that of passing a simple variable. In the case of simple varibles, the called function creates a copy of the variable and works on it, so any changes made in the function do not affect the original variable. When an array is passed as an actual argument, the called function actually get access to the original array and work on it, so any changes made inside the function affect the original array.</blockquote><p>That’s all for the 1-D array, in the next lecture we will cover the 2-D array.</p><p>For a full course on Data Structure go to the publication. Please share and clap if you like the lectures.</p><p><a href="https://medium.com/data-structure">Data Structure</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d9850575d8b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-structure/4-the-world-of-arrays-3d9850575d8b">#4. The World of Arrays</a> was originally published in <a href="https://medium.com/data-structure">Data Structure</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#3. Overview of different data structures and where they are used?]]></title>
            <link>https://medium.com/data-structure/overview-of-different-data-structures-and-where-they-are-used-95bc4587f446?source=rss----7d45d48618a1---4</link>
            <guid isPermaLink="false">https://medium.com/p/95bc4587f446</guid>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[H@rsh Kumar]]></dc:creator>
            <pubDate>Sun, 30 Jun 2019 12:12:39 GMT</pubDate>
            <atom:updated>2019-07-02T16:17:01.505Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-eErGMF_0xZhAmIA" /><figcaption>Photo by <a href="https://unsplash.com/@grohsfabian?utm_source=medium&amp;utm_medium=referral">Fabian Grohs</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this section, we will cover different data structures and how to select among them for our program.</p><blockquote>There are many data structures available to be used. So how can we select among them to make our program efficient.</blockquote><p>Before getting into the selection process first, let’s briefly explore all the data structures.</p><h3><strong>Arrays :</strong></h3><p>An array is a collection of similar type of data items and each data item is called an element of the array. The data type of elements may be any valid primitive data type like char, int, float, etc. The elements of an array share the same variable name but each element has a different index number known as a <strong>subscript.</strong></p><p>Elements of an array are stored in a single block of memory, storing the element in a linear manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*7RN0uNj_VYiprxrRVHfc8Q.png" /><figcaption>Array representation</figcaption></figure><p>In the figure above elements U, B, F, D, A, E, C are stored linearly having memory location of 200, 2001, 202, 203, 204, 205, 206 respectively. Since char takes only 1 bit of memory. Arrays are used where there is a need to store similar types of data.</p><h3>Strings:</h3><p>Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character ‘\0’ known as a <strong>null </strong>character. The <strong>null</strong> character tells the end of the character sequence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*qkjB6Jcahygf1xF4AsfiLQ.png" /><figcaption>Memory representation of String</figcaption></figure><h3>Linked List:</h3><p>Linked lists are about the simplest data structure beyond arrays. They aren’t very efficient for many purposes but have very good performance for certain specialized applications.</p><p>A Linked list is made up of nodes where each node has two parts, the first one is the actual data of the list and the second one is the link part that points to the next node of the list or we can say that it contains the address of the next node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*6ReSYwX-z-n4jWPCRSxqBw.png" /><figcaption>Linked List representation</figcaption></figure><p>The Head of the list contains the address of the first node of the list. The last link part of the last node contains NULL, which specifies the end of the list.</p><h3>Stack:</h3><p>A stack is a linear list in which insertion and deletions of an element are allowed only at one end of the list, called the <strong>top </strong>of the stack. Stacks are like the dishes are kept one over another to make a pile of dishes, now when the dish is required firstly the dish at the top is removed.</p><p>The behavior of stack is <strong>Last In First Out (LIFO). </strong>Stacks can be implemented by either an array or linked list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*7aBdyQdahI6dMLDc2yFdkQ.jpeg" /><figcaption>Stack representation</figcaption></figure><p>In the Stack, the insertion operation of the element is called <strong>Push </strong>and the deletion operation is called <strong>Pop</strong>.</p><h3>Queue:</h3><p>The queue is another linear list in which elements can be inserted only at one end called <strong>rear </strong>of the queue and deletion at the other end called <strong>front </strong>of the queue. We can see examples of a queue in daily life like a queue of a person waiting at a counter. In the queue of people, the person that enters first in the queue will come out first.</p><p>The behavior of the queue is First In First Out (FIFO). Queues can also be implemented by either an array or linked list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*Syg93-QJMWSfMI3LIpUVUw.png" /><figcaption>Queue representation</figcaption></figure><p>In the Queue, the insertion operation is called <strong>enqueue </strong>and deletion operation is called <strong>dequeue</strong>.</p><h3>Tree:</h3><p>A Tree is a non-linear data structure containing nodes in a hierarchical manner. A Tree can be defined recursively as -</p><p>There is a finite set of nodes such that:</p><ul><li>There is a distinguished node called root and</li><li>The remaining nodes are partitioned into n&gt;0 disjoint sets T1, T2, ….Tn where each of these is a tree. The sets T1, T2, ….Tn are the subtrees of the root.</li></ul><p>There are many terminologies in a tree which we will cover in detail later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*Xkv2hFSGNZK_irO2hIafvQ.png" /><figcaption>Tree representation</figcaption></figure><p>Trees are useful for information retrieval and searching in it is very fast.</p><h3>Graphs:</h3><p>A graph is simply a collection of nodes with edges between(some of) them. The graph can be either directed or undirected.</p><p>A tree is actually a type of graph, but not all graphs are trees. Simply put, a tree is a connected graph without cycles.</p><p>The graph might consist of multiple isolated subgraphs. If there is a path between every pair of vertices, it is called a <strong>connected graph</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*DYDao3CGDPHxa3G0bMTx_Q.png" /><figcaption>Graph representation</figcaption></figure><h3>How to select among different data structures?</h3><p>Now the picture comes in mind about different data structures but what to use when for our programs. Choosing data structures according to what you want to do make the program more efficient and easy to code.</p><p>However, to write an optimized program, it is important to think further about how the data will be used. For example, consider that you need to write a program where you have to store a long list of integer values that are updated periodically (add and remove) and where you want to quickly find the minimum and maximum value. If a programmer thinks about what he needs to store, s/he may decide to use an <strong>array</strong>. If the programmer thinks in terms of what he wants to do with the data, s/he may decide to use a <strong>list</strong> (an array that is dynamically resized) because <strong>add</strong> and <strong>remove </strong>operations will be performed periodically. This could be a better solution. However, if the programmer thinks further in terms of what he wants to do with the data, he may decide to use a <strong>red-black tree, </strong>which guarantees an <strong><em>O</em>(<em>log</em>(<em>n</em>))</strong> worst-case time cost for the four operations <strong>add</strong>, <strong>remove</strong>, <strong>minimum</strong> and <strong>maximum</strong><em>. </em>This could be a much better solution!</p><p>So, you can use any data structure for the program depending upon the future operation are going to do on that data.</p><p>That’s it for this lecture. In the next lecture will we deep dive into arrays.</p><p><a href="https://medium.com/data-structure/4-the-world-of-arrays-3d9850575d8b">#4. The World of Arrays</a></p><p>For further reading please check the publication here.</p><p><a href="https://medium.com/data-structure">Data Structure</a></p><p>Also, follow me <a href="https://medium.com/u/faf2df36587">H@rsh Kumar</a> for the latest updates.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95bc4587f446" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-structure/overview-of-different-data-structures-and-where-they-are-used-95bc4587f446">#3. Overview of different data structures and where they are used?</a> was originally published in <a href="https://medium.com/data-structure">Data Structure</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#2. Importance and Types of Data Structures]]></title>
            <link>https://medium.com/data-structure/importance-and-types-of-data-structures-7f90c6259826?source=rss----7d45d48618a1---4</link>
            <guid isPermaLink="false">https://medium.com/p/7f90c6259826</guid>
            <category><![CDATA[data-structures-important]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[data-structures-types]]></category>
            <dc:creator><![CDATA[H@rsh Kumar]]></dc:creator>
            <pubDate>Sun, 30 Jun 2019 09:36:19 GMT</pubDate>
            <atom:updated>2019-07-01T15:54:31.384Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U8bLfBx8TNn4McMc" /><figcaption>Photo by <a href="https://unsplash.com/@shemul?utm_source=medium&amp;utm_medium=referral">Shahadat Shemul</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>After Introduction to data structure now let’s see why it is important for every programmer to know. If you haven’t gone through Introduction, I suggest you to first go through the introduction and then continue.</p><p><a href="https://medium.com/data-structure/what-is-data-structure-and-why-its-so-important-c19e09b953e0">What is Data Structure and why it’s so important?</a></p><p>Now let’s deep dive into the data structure.</p><h3>Why Data Structure is Important factor in program development?</h3><blockquote>There is a famous equation “ Data Structure + Algorithm = programs”. This equation says that programs are built using a data structure for storing data and different algorithms for manipulating those data for use.</blockquote><p>Data Structure is the core of any program (either “Hello World” or advance) where the variables, constants, results, any other values are stored in memory for use. Different data structure tells the program how to store it in memory and forming some relations among the data. For example, <strong>Array </strong>is used to store data in a sequentially arranged block of memory where each block is of different size depending upon the type of data storing in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*7RN0uNj_VYiprxrRVHfc8Q.png" /><figcaption>memory representation of an array</figcaption></figure><blockquote>Data Structure is also used to build many different algorithms as a backbone.</blockquote><h3>Types of Data Structures:</h3><p>There are different types of data structures available based upon certain features of memory allocation or memory location.</p><h4>Data Structure based on Memory location:</h4><ol><li><strong>Linear Data Structures:</strong></li></ol><p>A data structure is linear if all the elements are arranged in a linear order. In this, each element has only one successor and only one predecessor. The only exceptions are the first and the last elements; the First element does not have a predecessor and the last element does not have a successor.</p><p>Examples: Array, String, LinkedList, Stack, Queue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*6ReSYwX-z-n4jWPCRSxqBw.png" /><figcaption>Linear Data Structure (LinkedList)</figcaption></figure><p>2. <strong>Non-Linear Data Structures:</strong></p><p>In a non-linear data structure, there is no linear order in the arrangement of the elements.</p><p>Examples: Trees and Graphs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*z-rf8BqlhX7YhpBWHy1O2w.png" /><figcaption>Non-linear data structure (Graph)</figcaption></figure><h4>Data Structures based on memory allocation:</h4><ol><li><strong>Static Data Structures:</strong></li></ol><p>In Static data Structures, the memory is allocated at compilation time only. Therefore, the maximum size is fixed and it can’t be changed at run time. Static data structures allow fast access to elements but insertion and deletion are expensive. Examples: Array.</p><p>2. <strong>Dynamic Data Structures:</strong></p><p>In Dynamic data structure, the memory is allocated at run time. Therefore these data structures have a flexible size. The dynamic data structure allows fast insertion and deletion of elements but access to elements is slow. Examples: Linked List.</p><p>Now, In the next section, we are going to overview different data structures and in the upcoming section, we will deeply explore each data structures.</p><p><a href="https://medium.com/data-structure/overview-of-different-data-structures-and-where-they-are-used-95bc4587f446">Overview of different data structures and where they are used?</a></p><p>For the full course visits the publication below.</p><p><a href="https://medium.com/data-structure">Data Structure</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f90c6259826" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-structure/importance-and-types-of-data-structures-7f90c6259826">#2. Importance and Types of Data Structures</a> was originally published in <a href="https://medium.com/data-structure">Data Structure</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[#1. What is Data Structure and why it’s so important?]]></title>
            <link>https://medium.com/data-structure/what-is-data-structure-and-why-its-so-important-c19e09b953e0?source=rss----7d45d48618a1---4</link>
            <guid isPermaLink="false">https://medium.com/p/c19e09b953e0</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[H@rsh Kumar]]></dc:creator>
            <pubDate>Sun, 30 Jun 2019 05:53:29 GMT</pubDate>
            <atom:updated>2019-07-01T15:53:49.090Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f8TVuLyvlX0aeJXS" /><figcaption>Data Structure</figcaption></figure><p>Before getting dive into what is a data structure, first, let’s see what is data type and how it is related to data structures.</p><h3>Data Type :</h3><p>A data type is something that defines a domain of allowed values and the operations that can be performed on those values.</p><p>For example in C language, the <strong>int </strong>data type can take values in range and operations that can be performed are addition, subtraction, multiplication, division and all those stuff which can be done with numbers in mathematics.</p><blockquote>Similarly, there are many other data types like float, double, String, char, boolean, etc.</blockquote><p>These data types are built-in data types also known as primitive data types and the values and operations for them are pre-defined in the programming language.</p><p>If an application needs to use a data type other than the primitive data types of language, then it is the programmer’s responsibility to specify the values and operations for that data type and implement it. For example, there is no built-in type <strong>dates</strong> in c, and if we need to process <strong>dates</strong>, we have to define and implement a data type for a date.</p><h3>Abstract Data Types (ADT) :</h3><p>An abstract data type is a mathematical model or concept that defines a data type logically. It specifies a set of data and collection of operations that can be performed on that data.</p><p>The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations.</p><blockquote>These process of hiding details is also known as <strong>Abstraction.</strong></blockquote><p>For example, consider <strong>Stack </strong>ADT</p><p><strong>Stack: </strong>A stack contains elements of the same type arranged in sequential order and following operations can be performed on the stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*lem98yX4AzPhM_0tQbaaEw.png" /><figcaption>Stack data structure</figcaption></figure><ol><li><strong>Initialize() : </strong>Initialize the stack to be empty.</li><li><strong>Push(): </strong>Insert an element at one end of the stack called <strong>top.</strong></li><li><strong>Pop(): </strong>Remove and return the element at the top of the stack, if it is not empty.</li><li><strong>Peek(): </strong>Return the element at the top of the stack without removing it, if the stack is not empty.</li><li><strong>Size(): </strong>Return the number of elements in the stack (i.e size of the stack).</li><li><strong>isEmpty(): </strong>Return true if the stack is empty, otherwise return false.</li><li><strong>isFull(): </strong>Return true if no more elements can be pushed or added, otherwise return false.</li></ol><h3>Data Structures :</h3><p>Now, here comes the Data Structures. So what really it is?</p><p>Data Structure is a programming construct used to implement an <strong>ADT</strong>.</p><p>It is the physical implementation of ADT. All operations specified in ADT are implemented through functions in the physical implementation. A data structure that is implementing an ADT consists of a collection of variables for storing the data specified in the ADT and the algorithms for implementing the operations specified in ADT.</p><blockquote>ADT is the logical view of data and the operations to manipulate the data while Data Structure is the actual representation of data and the algorithms to manipulate the data.</blockquote><h3>What are the Advantages of Data Structures?</h3><p>Here are some advantages of using data structures.</p><ul><li><strong>Efficiency: </strong>Proper choice of data structures make programs efficient in terms of time and space. For Example, suppose we have some data and we need to organize it properly and perform the search operation. If we organize our data in an array, then we will have to search sequentially element by element. If the item to be searched is present at last then we will have to visit all the elements before reaching that element. So the use of array is not very efficient here. There is a better data structure which makes the search process efficient like an ordered array, Binary Search Tree or Hash Table. Different data Structure gives different efficiency.</li><li><strong>Reusability: </strong>Data Structures are reusable, i.e, once we have implemented a particular data structure we can use it in any other place or requirement. Implementation of data structure can be compiled into libraries which can be used by different clients.</li><li><strong>Abstraction: </strong>Data Structure provides the level of abstraction and hides the detail of how things are working behind the screen. For example, In Stack push() insert the element at top and pop() removes an element from the top. How this insertion and removing is working is hidden from the user.</li></ul><p>Now, in the next section, we will cover the types of data structure, it’s importance and some brief overview of different data structures.</p><p><a href="https://medium.com/data-structure/importance-and-types-of-data-structures-7f90c6259826">Importance and Types of Data Structures</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c19e09b953e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-structure/what-is-data-structure-and-why-its-so-important-c19e09b953e0">#1. What is Data Structure and why it’s so important?</a> was originally published in <a href="https://medium.com/data-structure">Data Structure</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>