# What is a nonlinear data structure

## Difference between linear and non-linear data structure

The data structure can be defined as the interpretation of the logical relationship that exists between the individual data elements. The linear and non-linear data structure is the subclassification of the data structure that underlies the non-primitive data structure. The key difference between them is that the linear data structure arranges the data in an order and follows a specific order. While the non-linear data structure does not organize the data sequentially.

The linear data structure is a single-level data structure, while non-linear data structures are the multi-level data structure. The data structure first describes how the data is organized, accessed, assigned and processed.

### Comparison table

Basis for comparisonLinear data structureNonlinear data structure
basicThe data items are arranged in an ordered manner where the items are placed side by side.It arranges the data in a sorted order and there is a relationship between the data items.
Step through the dataThe data elements can be accessed all at once (single run).You cannot traverse data items at once.
Ease of enforcementEasiercomplex
Levels involvedSingle levelMultiple level
ExamplesArray, queue, batch, linked list, etc.Tree and graphic.
Memory usageIneffectiveEffective

### Definition of the linear data structure

The data structure is saved as a considered linear, when the data elements form a sequence of a linear list. The elements are connected next to each other and in a certain order. It takes up linear storage space, the data elements must be stored sequentially in the memory. When implementing the linear data structure, the required amount of memory is declared beforehand. It does not make good use of memory and leads to wasted memory. The data elements are visited one after the other, whereby only one element can be reached directly.

The examples included in the linear data structure are array, stack, queue, linked list, and so on Array is a group of a certain number of homogeneous elements or data elements. Stack and queue are also an ordered collection of elements like an array. However, there is a special condition where the stack follows the order LIFO (last in first out). In the queue, FIFO (first in first out) are used to insert and delete the elements. Lists can be defined as a set of data elements of variable number.

### Definition of the non-linear data structure

The nonlinear data structure does not arrange the data consecutively, but is arranged in sorted order. In so doing, the data items can be appended to more than one item that has the hierarchical relationship that includes the relationship between the child, parent, and grandparent. In the non-linear data structure, traversing data items and inserting or deleting are not performed sequentially.

The nonlinear data structure uses the memory efficiently and does not require a memory declaration in advance. There are two general examples of the nonlinear data structure - Tree structure and diagram . A tree data structure organizes and stores the data items in a hierarchical relationship.

### Main differences between linear and non-linear data structure

1. In the linear data structure, the data is organized in a linear order in which elements are linked one after the other. In the non-linear data structure, on the other hand, the data elements are not stored sequentially, but the elements are hierarchically related to one another.
2. Traversing data in the linear data structure is easy because it can traverse all of the data items at once. However, only one element can be reached directly at a time. In contrast, in the non-linear data structure, the nodes are not visited sequentially and cannot be traversed at once.
3. Data elements are placed side by side in the linear data structure, so that only two elements can be linked with two other elements, whereas this is not the case with the non-linear data structure, in which one data element can be connected with numerous other elements.
4. The linear data structures are easy to implement relative to the non-linear data structure.
5. A single element level is integrated into the linear data structure. Conversely, the non-linear data structure comprises several levels.
6. Examples of the linear data structure are array, queue, batch, linked list, etc. In contrast, tree and diagram are the examples of the non-linear data structure.
7. The memory is used efficiently in the non-linear data structure where the linear data structure tends to waste the memory.

### Conclusion

The linear data structures comprise a single level of data elements and represent the linear relationship. On the other hand, it is said that the non-linear data structure is a multi-level data structure that forms a hierarchical relationship between the data.