Introduction to Data Structures
A data structure is a particular way of organizing and storing data in a computer so that it can be
accessed and modified efficiently.
Efficient programs depend not only on algorithms but also on proper representation of data.
Example: array for indexed data, linked list for dynamic data.
1 Data item: single unit of value
2 Group items: records, files
3 Data structure = organized collection of data
Classification of Data Structures
Data structures are classified based on organization and memory allocation.
1 Primitive: int, float, char
2 Non-primitive: linear and non-linear
3 Linear: array, linked list, stack, queue
4 Non-linear: tree, graph
Operations on Data Structures
Common operations performed on data structures:
1 Insertion
2 Deletion
3 Traversal
4 Searching
5 Sorting
6 Merging
Abstract Data Type (ADT)
ADT defines data and permitted operations independent of implementation.
Example: Stack ADT only defines push/pop but not array or linked list implementation.
Selecting a Data Structure
Choice depends on application requirements.
1 Time efficiency
2 Memory efficiency
3 Type of operations
4 Frequency of operations
5 Data size
Linear List & Linked Lists
Linear list stores elements sequentially.
Linked list stores elements dynamically using nodes containing data and pointer.
Singly Linked List
Each node contains data and next pointer.
Last node next pointer = NULL
1 Efficient insertion/deletion
2 No random access
Circular Linked List
Last node points to first node instead of NULL.
Useful in round-robin scheduling
Doubly Linked List
Each node has previous and next pointer.
Allows bidirectional traversal
1 Faster deletion
2 More memory required
Stack
Stack follows LIFO (Last In First Out).
1 Push: insert element
2 Pop: remove element
3 Peek: view top element
Stack Algorithm
PUSH Algorithm: check overflow → increment top → insert element
POP Algorithm: check underflow → return element → decrement top
Stack ADT
Operations: create, push, pop, peek, isEmpty, isFull
Stack Applications
Used in recursion, expression evaluation, parenthesis matching, undo operations
Queue
Queue follows FIFO (First In First Out).
1 Enqueue: insert at rear
2 Dequeue: delete from front
Queue Algorithm
ENQUEUE: check overflow → insert at rear
DEQUEUE: check underflow → delete from front
Queue ADT
Operations: createQueue, enqueue, dequeue, front, isEmpty
Queue Applications
CPU scheduling
Printer spooling
Breadth First Search
Buffer management