Past exam question: 2078 Poush (Back), Q1(a)
Open in the Padhaiko appQuestion
Define Data Structure. Write down the difference between linear and non-linear data structure.
Solution
Definition of Data Structure: A data structure is a logical and mathematical model for organizing, storing, and manipulating data in computer memory so that operations (insertion, deletion, traversal, searching) can be executed efficiently in both time and space.
Linear vs. Non-Linear Data Structures:
| Aspect | Linear Data Structure | Non-Linear Data Structure |
|---|---|---|
| Arrangement | Elements are arranged sequentially one after another | Elements form hierarchical or network relationships |
| Adjacency | Each element has at most one predecessor and one successor | One element can connect to multiple elements (one-to-many / many-to-many) |
| Traversal | Can be traversed completely in a single linear pass | Requires recursive or multi-path traversal (DFS, BFS, tree traversals) |
| Memory & Implementation | Generally simpler to implement (arrays or linked lists) | More complex pointer/matrix representations |
| Examples | Array, Stack, Queue, Linked List | Tree, Binary Search Tree, AVL Tree, Graph |
Answer:
A data structure organizes data in memory for efficient access and modification. Linear structures (arrays, stacks, queues, linked lists) store items in a single sequential order, whereas non-linear structures (trees, graphs) organize items hierarchically or in arbitrary networks with multi-level connections.