Linear Data Structures
Linear data structures store data elements sequentially, where elements are connected to one
another and traversal is possible in a single run. They are widely used due to their simplicity and
efficiency for certain operations.
## Types of Linear Data Structures
1. Arrays
Definition: A collection of elements, each identified by an index.
Operations:
- Access: O(1) time complexity.
- Insertion/Deletion: O(n) (shifting required).
Applications:
- Storing a collection of data of the same type.
- Implementing other data structures like heaps and queues.
2. Linked List
Definition: A series of connected nodes where each node contains data and a reference to the next
node.
Operations:
- Access: O(n) (sequential search).
- Insertion/Deletion: O(1) for head/tail, O(n) for other positions.
Applications:
- Dynamic memory allocation.
- Implementing stacks, queues, and graphs.
3. Stack
Definition: A linear structure following LIFO (Last In, First Out).
Operations:
- Push: Add element to the top.
- Pop: Remove element from the top.
Applications:
- Expression evaluation and conversion.
- Function call management.
4. Queue
Definition: A linear structure following FIFO (First In, First Out).
Operations:
- Enqueue: Add element to the rear.
- Dequeue: Remove element from the front.
Applications:
- Scheduling and buffering.
- Breadth-First Search (BFS).
5. Deque (Double-Ended Queue)
Definition: A queue where elements can be added or removed from both ends.
Applications:
- Implementing undo operations.
- Cache management.
---
Summary Table:
| Data Structure | Access Time | Insertion/Deletion Time | Key Property | Applications |
| -------------- | ----------- | ----------------------- | ------------- | ------------------------- |
| Array | O(1) | O(n) | Fixed size | Static storage |
| Linked List | O(n) | O(1) at head/tail | Dynamic size | Dynamic memory management |
| Stack | O(n) | O(1) | LIFO | Function calls, parsing |
| Queue | O(n) | O(1) | FIFO | Scheduling, BFS |
| Deque | O(n) | O(1) | Bidirectional | Advanced queue operations |