Loading...

Non-Linear Data Structure

What is Non-Linear Data Structure

Data structures where data elements are not arranged sequentially or linearly are called non-linear data structures. Unlike linear structures, such as arrays and linked lists, where elements follow a specific order, non-linear structures allow more complex relationships between elements. In a non-linear data structure, single level is not involved. Therefore, we can't traverse all the elements in single run only. For example: Trees, and Graphs.

In Trees, data elements are organized hierarchically, with a single root element and branches leading to child nodes.

Graphs, on the other hand, consist of nodes connected by edges, allowing for more intricate relationship between elements.

Difference Between Linear and Non-Linear Data Structures

1. Organization and Relationship

Linear Data Structures:

  • Elements are stored in a sequential manner.
  • Each element has a predecessor and a successor, forming a linear order.
  • Examples are arrays, linked lists, queues and stacks.

Non-Linear Data Structures:

  • Elements are not arranged in a linear order.
  • Relationship between elements can be more complex, forming hierarchies or interconnected networks.
  • Examples include trees and graphs.

2. Access Patterns

Linear Data Structures:

  • Accessing elements involves traversing the structure sequentially.
  • Operations like search, insertion, and deletion may have a time complexity proportional to the size of the structure.

Non-Linear Data Structures:

  • Access patterns depend on the specific structure.
  • Tress may provide faster access based on hierarchy, while graphs may require more sophisticated algorithms for efficient traversal.