A Data Structure is a specialized format for organizing, processing, retrieving, and storing data in computer memory so that operations can be performed efficiently. An algorithm cannot exist in isolation; it requires a structured mathematical or logical representation of data upon which its operational steps are executed.
The design and selection of an appropriate data structure involve analyzing: (1) the volume and relationship of data items, (2) the frequency of basic operations (searching, insertion, deletion, traversal), and (3) the physical resource constraints (CPU execution time and primary memory consumption).
Data structures are broadly categorized into two fundamental tiers:
- Primitive Data Structures: Basic, atomic data types directly supported by hardware and machine-level instruction sets. In C, these include
int,float,char,double, and raw memory memory addresses (pointers). They hold a single atomic value at any instant. - Non-Primitive Data Structures: Sophisticated structures derived from primitive data types to manage collections of homogeneous or heterogeneous data elements. These are further subdivided into:
| Classification Category | Key Structural Properties | Representative Examples | Traversal Mechanism |
|---|---|---|---|
| Linear Data Structures | Elements form a sequential sequence where every element (except first and last) has a unique predecessor and successor. | Arrays, Stacks, Queues, Linked Lists | Single sequential pass visits all elements linearly in $O(n)$ time. |
| Non-Linear Data Structures | Elements are arranged hierarchically or interconnected in a multi-path network. | Trees (Binary Trees, BST), Graphs | Non-linear traversal (Depth-First Search, Breadth-First Search, Inorder/Preorder). |
| Static Data Structures | Memory allocation is fixed at compile time; size cannot expand or shrink dynamically during runtime. | Fixed-size Arrays | Memory allocated in Stack or BSS/Data segment. |
| Dynamic Data Structures | Memory is allocated and deallocated at runtime from the Heap segment using pointers. | Linked Lists, Dynamic Stacks, Trees | Memory grows and shrinks on demand via malloc() and free(). |
Regardless of their structural classification, all data structures support a standard set of core operational primitives:
- Traversing: Accessing and processing each element of the data structure exactly once (e.g., printing all values or computing their sum).
- Insertion: Adding a new data element into a designated position within the data structure.
- Deletion: Removing an existing data element from the data structure.
- Searching: Locating the position or memory address of an element satisfying a given target key (Linear Search, Binary Search).
- Sorting: Arranging elements in a predetermined logical sequence (ascending or descending order) using algorithms such as Bubble, Selection, or Insertion sort.
- Merging: Combining two distinct, typically sorted data collections into a unified composite data structure.