9 Linear and Non-Linear Data Structure
9 Linear and Non-Linear Data Structure
, a data structure is designed in such a way that it can work with various algorithms. A data
structure is classified into two categories:
o Linear data structure
o Non-linear data structure
is a structure in which the elements are stored sequentially, and the elements are connected to the
previous and the next element. As the elements are stored sequentially, so they can be traversed
or accessed in a single run. The implementation of linear data structures is easier as the elements
are sequentially organized in memory. The data elements in an array are traversed one after
another and can access only one element at a time.
The types of linear data structures are Array, Queue, Stack, Linked List.
o Array: An array consists of data elements of a same data type. For example, if we
want to store the roll numbers of 10 students, so instead of creating 10 integer
type variables, we will create an array having size 10. Therefore, we can say that
an array saves a lot of memory and reduces the length of the code.
o Stack: It is linear data structure that uses the LIFO (Last In-First Out) rule in which
the data added last will be removed first. The addition of data element in a stack
is known as a push operation, and the deletion of data element form the list is
known as pop operation.
o Queue: It is a data structure that uses the FIFO rule (First In-First Out). In this rule,
the element which is added first will be removed first. There are two terms used
in the queue front end and rear The insertion operation performed at the back
end is known ad enqueue, and the deletion operation performed at the front end
is known as dequeue.
o Linked list: It is a collection of nodes that are made up of two parts, i.e., data
element and reference to the next node in the sequence.
What is a Non-linear data structure?
A non-linear data structure is also another type of data structure in which the data
elements are not arranged in a contiguous manner. As the arrangement is
nonsequential, so the data elements cannot be traversed or accessed in a single run. In
the case of linear data structure, element is connected to two elements (previous and
the next element), whereas, in the non-linear data structure, an element can be
connected to more than two elements.
o Tree
It is a non-linear data structure that consists of various linked nodes. It has a hierarchical
tree structure that forms a parent-child relationship. The diagrammatic representation of
a tree data structure is shown below:
For example, the posts of employees are arranged in a tree data structure like
managers, officers, clerk. In the above figure, A represents a manager, B and C represent
the officers, and other nodes represent the clerks.
o Graph
A graph is a non-linear data structure that has a finite number of vertices and edges,
and these edges are used to connect the vertices. The vertices are used to store the data
elements, while the edges represent the relationship between the vertices. A graph is
used in various real-world problems like telephone networks, circuit networks, social
networks like LinkedIn, Facebook. In the case of facebook, a single user can be
considered as a node, and the connection of a user with others is known as edges.
Basic In this structure, the elements are arranged sequentially or In this structure, the elements are arranged
linearly and attached to one another. hierarchically or non-linear manner.
Types Arrays, linked list, stack, queue are the types of a linear Trees and graphs are the types of a non-linear data
data structure. structure.
implementation Due to the linear organization, they are easy to Due to the non-linear organization, they are difficult to
implement. implement.
Traversal As linear data structure is a single level, so it requires a The data items in a non-linear data structure cannot be
single run to traverse each data item. accessed in a single run. It requires multiple runs to be
traversed.
Arrangement Each data item is attached to the previous and next items. Each item is attached to many other items.
Levels This data structure does not contain any hierarchy, and all In this, the data elements are arranged in multiple
the data elements are organized in a single level. levels.
Memory In this, the memory utilization is not efficient. In this, memory is utilized in a very efficient manner.
utilization
Time The time complexity of linear data structure increases with The time complexity of non-linear data structure often
complexity the increase in the input size. remains same with the increase in the input size.
Applications Linear data structures are mainly used for developing the Non-linear data structures are used in image
software. processing and Artificial Intelligence.