What is Linear Data Structure?

A linear data structure is one in which data items are ordered sequentially or linearly, with each member attached to its previous and next neighboring elements. All the elements in the linear data structure can be traversed in a single run. Arrays, Linked List, Stack and Queue are the different types of linear data structures available.

Takeaways

The time complexity of linear data structure increases with the increase in the input size.

Introduction to Linear Data Structure

A linear data structure is one in which data items are ordered sequentially or linearly, with each member attached to its previous and next neighboring elements.

Since the data elements are stored in a linear fashion, the structure allows single-level data storage. As a result, traversal of the data is accomplished in a single run. Memory is not efficiently utilized in a linear data structure.

Characteristics of Linear Data Structure

The linear data structure has the following characteristics:

List of data structure in a linear type of data structure

different types of the linear data structures are:

Array

The array is the linear data structure that is a collection of similar data items stored at contiguous memory locations. The elements of the array are stored in one memory block for the entire array.

Array Data Structure

Now let's understand the properties of array that are as follows:

Linked List

Linked List Data Structure

A linked list is the linear data structure made up of nodes, each of which has a data field and a connection to the next node in the list. The first node is pointed to by the head pointer, and the last element points to NULL marking the end of the linked list as shown in below figure.

NOTE: The head pointer points to null when the list is empty

These are the following types of Linked List:

  1. Singly Linked List: It consists of a series of a structure called nodes and each node contain data part and pointer to the next node in the linked list therefore it allows traversal in a single direction. Singly Linked List in Data Structure
  2. Doubly Linked List: In this type of linked list , a node contains a pointer to the previous as well as the next node in the sequence i.e. in a doubly-linked list , a node consists of three parts: data, a pointer to the next node in the sequence, and a pointer to the previous node. The advantage of this type of linked list is that we can traverse in both directions. Doubly Linked List in Data Structure
  3. Circular Linked List: Each node in a singly-circularly-linked list contains one link, just like in a regular singly-linked list, except the last node's next link points back to the first node. Thus circular linked list do not have ends i.e. every node points to its next node in the sequence but the last node points to the first node in the list. Circular Linked List in Data Structure

Properties of Linked List:

Now let's understand the important properties of linked list :

Stack

A stack is a simple data structure used for storing data. A pile of plates in a cafeteria is a good example of a stack. The piles are added to the stack as they are cleared and they are placed on the top. When a plate is needed, it is taken from the stack's top. The first plate on the stack is the last one to be used.

stack data structure

A stack is an ordered list in which insertion and deletion are performed at one end, which is referred to as the top. The first element to be eliminated is the last one that was entered. As a result, it's known as the Last in First Out (LIFO) . When an element is inserted in a stack, the concept is called push and when the element is removed from the stack, the concept is called pop. Trying to pop out an empty stack is called underflow and trying to push an element in a full stack is called overflow.

There are the following operations that can be performed on the stack(For simplicity, assume the data is an integer type):

Queue

Queue data structure

A queue is another linear data structure that is used for storing data. In the queue, the order in which data arrives is important. In general, a queue is a line of people or things to be served in sequential order starting at the beginning of the line or sequence. A queue is an ordered list in which insertions are done at one end i.e. rear end and deletions are done at the other end i.e. front end. The first element to be added is also the first to be removed. As a result, it's known as "First in, First out" (FIFO) .

The two changes that can be made to a queue are given special names, similar to Stacks. The concept of EnQueue is used when an element is added to a queue, and DeQueue is used when an element is deleted from the queue. Underflow refers to dequeuing an element from an empty queue, while overflow refers to enqueuing an element from a filled queue.

There are the following operations that can be performed on the queue(For simplicity, assume the data is an integer type):

Difference between Linear and Non-linear Data Structures

Linear Data Structure: A linear data structure is one in which data items are ordered sequentially and each data member attached to its previous and next neighbouring elements.

Non Linear Data Structure: A Non-linear data structure is one in which data items are not ordered sequentially and each member can connect to other member through multiple paths.

Now let's understand the difference between both of them in detail.

Linear Data StructureNon Linear Data Structure
Data elements in linear data structure are ordered in sequential order, with each element connected to the previous and next element.Data elements are connected hierarchically in a non-linear data structure.
They can be traversed completely in a single run.They needed multiple runs to traverse them completely.
In this type of data structure, only a single level is involved.In this type of data structure, multiple levels are involved.
In a linear data structure, memory is not utilized in an efficient way.In a non-linear data structure, memory is utilized in an efficient way.
Examples: Arrays, Stack, Queue, Linked List.Examples: Trees, Graphs, etc.

Looking to excel in coding interviews? Our Java DSA course is your key to success. Enroll today and pave the way for a successful career.

Conclusion