1. What is Data Structure?
A Data Structure is a way of organizing and storing data so that it can be used efficiently.
Examples: Array, Linked List, Stack, Queue, Tree, Graph.
Advantages:
- Efficient use of memory
- Faster processing (searching, insertion, deletion)
- Handles large/complex data easily
- Code reusability and abstraction
Disadvantages:
- Some structures are complex to implement
- Wrong choice may reduce efficiency
- Needs extra memory (e.g., Linked List uses pointers)
2. What is Algorithm?
An Algorithm is a step-by-step procedure or set of rules to solve a problem.
Examples: Binary Search, Merge Sort.
Advantages:
- Provides a clear procedure
- Easy to analyze and debug
- Optimizes time and memory
Disadvantages:
- Designing efficient algorithms is difficult
- Some are too theoretical
- May not be suitable for all platforms
3. What is Array? What are its Functions?
An Array is a collection of elements of the same type stored in contiguous memory locations.
Functions:
- Traversal (visit each element)
- Insertion (add element)
- Deletion (remove element)
- Searching (linear/binary)
- Sorting (arrange elements)
4. What is Complexity (Time and Space)?
Complexity measures efficiency of an algorithm.
Time Complexity:
- Best Case (Ω): Minimum time
- Average Case (Θ): Expected/normal time
- Worst Case (O): Maximum time
Example: Linear Search in n elements → Best = O(1), Average = O(n), Worst = O(n)
Space Complexity:
- Memory used by algorithm
- Fixed part (constants, program size)
- Variable part (arrays, recursion stack)
5. What is Sorting?
Sorting is arranging elements in ascending or descending order.
It improves searching and efficiency.
Types of Sorting:
Bubble Sort
Process: Compare adjacent elements and swap if needed.
Passes: (n-1)
Time: Best O(n), Worst O(n²)
Program (C):
for(i=0;i for(j=0;j if(arr[j] > arr[j+1]){
swap(arr[j], arr[j+1]);
}
}
}
Selection Sort
Process: Find smallest element and place it at beginning.
Passes: (n-1)
Time: O(n²)
Insertion Sort
Process: Insert each element into sorted part.
Passes: (n-1)
Time: Best O(n), Worst O(n²)
Merge Sort
Process: Divide array, sort halves recursively, merge.
Passes: log■n levels
Time: O(n log n)
Quick Sort
Process: Pick pivot, partition, recursively sort sub-arrays.
Passes: ~log■n
Time: Best/Average O(n log n), Worst O(n²)