1. Define data structure. Classify and explain.
A data structure is a way of organizing and storing data so that it can be accessed and modified
efficiently. Classification:
- Linear: Arrays, Linked Lists, Stacks, Queues
- Non-Linear: Trees, Graphs
- Static: Size fixed (e.g., Array)
- Dynamic: Size changes (e.g., Linked List)
2. Compare arrays and linked lists.
Arrays:
- Fixed size
- Random access
- Insertion/deletion is costly
Linked Lists:
- Dynamic size
- Sequential access
- Efficient insertion/deletion
3. Explain stack operations with algorithms.
Stack: LIFO structure.
Operations:
- Push: Add element
- Pop: Remove top element
- Peek: View top
Algorithm for Push:
1. Check if stack is full