List Headline Image
Updated by Santosh Sahu on Aug 22, 2020
 REPORT
Santosh Sahu Santosh Sahu
Owner
10 items   2 followers   10 votes   0 views

Data Structures

In computer science, a data structure is a particular way to organize data so that it enables efficient access and modification. It is a collection of data values based on the relationships among them, and the functions and operations which can be applied on the data. Few of the commonly used data structures are stack, queue, and linked list etc.

Source: https://www.alphacodingskills.com/ds/ds-tutorial.php

A linked list is a linear data structure, in which the elements are stored in the form of a node. Each node contains two sub-elements. A data part that stores the value of the element and next part that stores the pointer to the next node as shown in the below image:

A circular singly linked list is a linear data structure, in which the elements are stored in the form of a node. Each node contains two sub-elements. A data part that stores the value of the element and the next part that stores the pointer to the next node as shown in the below image:

A doubly linked list is a linear data structure, in which the elements are stored in the form of a node. Each node contains three sub-elements. A data part that stores the value of the element, the previous part that stores the pointer to the previous node, and the next part that stores the pointer to the next node as shown in the below image:

A circular doubly linked list is a linear data structure, in which the elements are stored in the form of a node. Each node contains three sub-elements. A data part that stores the value of the element, the previous part that stores the pointer to the previous node, and the next part that stores the pointer to the next node as shown in the below image:

A stack is a linear dynamic data structure that follows Last-In/First-Out (LIFO) principle. In a stack, addition of a new element and deletion of an element occurs at the same end which implies that the element which is added last in the stack will be the first to be removed from the stack.

A linked list is a linear data structure, in which the elements are stored in the form of a node. Each node contains two sub-elements. A data part that stores the value of the element and next part that stores the pointer to the next node.

A queue is a linear dynamic data structure that follows First-In/First-Out (FIFO) principle. In a queue, addition of a new element and deletion of an element occurs at different end which implies that the element which is added first in the queue will be the first to be removed from the queue.

Traversing through a linked list is very easy. It requires creating a temp node pointing to the head of the list. If the temp node is not null, display its content and move to the next node using temp next. Repeat the process till the temp node becomes null. If the temp node is empty at the start, then the list contains no item.

In this method, a new node is inserted at the beginning of the linked list. For example - if the given List is 10->20->30 and a new element 100 is added at the start, the Linked List becomes 100->10->20->30.

Inserting a new node at the beginning of the Linked List is very easy. First, a new node with given element is created. It is then added before the head of the given Linked List that makes the newly added node to new head of the Linked List by changing the head pointer to point to the new node.

In this method, a new node is inserted at the end of the linked list. For example - if the given List is 10->20->30 and a new element 100 is added at the end, the Linked List becomes 10->20->30->100.

Inserting a new node at the end of the Linked List is very easy. First, a new node with given element is created. It is then added at the end of the list by linking the last node to the new node.