🔹 1. What is Data Structure?
A data structure is a way of organizing and storing data efficiently so it can be used effectively.
🔹 2. Why do we need data structures?
They help in:
- Faster data access
- Efficient memory usage
- Better performance of algorithms
🔹 3. Types of data structures?
✔ Linear:
- Array
- Linked List
- Stack
- Queue
✔ Non-linear:
- Tree
- Graph
🔹 4. What is an array?
An array is a collection of elements stored in contiguous memory locations.
🔹 5. Advantages of array?
- Fast access using index
- Easy to use
🔹 6. Disadvantages of array?
- Fixed size
- Insertion/deletion is slow
🔹 7. What is a linked list?
A linked list is a collection of nodes where each node contains data and a pointer to the next node.
🔹 8. Types of linked list?
- Singly linked list
- Doubly linked list
- Circular linked list
🔹 9. Difference between array and linked list?
| Array | Linked List |
|---|---|
| Fixed size | Dynamic size |
| Fast access | Slow access |
🔹 10. What is a stack?
A stack is a LIFO (Last In First Out) data structure.
🔹 11. Stack operations?
- push()
- pop()
- peek()
🔹 12. What is a queue?
A queue is a FIFO (First In First Out) data structure.
🔹 13. Queue operations?
- enqueue()
- dequeue()
🔹 14. Types of queue?
- Simple queue
- Circular queue
- Priority queue
🔹 15. What is recursion?
A function that calls itself.
🔹 16. What is tree?
A hierarchical data structure with nodes.
🔹 17. What is binary tree?
A tree where each node has max two children.
🔹 18. Types of tree?
- Binary tree
- Binary search tree (BST)
- AVL tree
🔹 19. What is BST?
A tree where left < root < right.
🔹 20. What is graph?
A collection of nodes (vertices) connected by edges.
🔹 21. Types of graph?
- Directed
- Undirected
- Weighted
- Unweighted
🔹 22. What is BFS?
Breadth First Search explores level by level.
🔹 23. What is DFS?
Depth First Search explores depth first.
🔹 24. BFS vs DFS?
| BFS | DFS |
|---|---|
| Queue | Stack |
| Level order | Depth order |
🔹 25. What is hashing?
Technique to map data to a fixed-size table.
🔹 26. What is hash table?
Stores data in key-value format.
🔹 27. What is collision?
When two keys map to same index.
🔹 28. Collision handling methods?
- Chaining
- Open addressing
🔹 29. What is sorting?
Arranging data in order.
🔹 30. Types of sorting?
- Bubble sort
- Selection sort
- Insertion sort
- Merge sort
- Quick sort
🔹 31. What is bubble sort?
Repeated swapping of adjacent elements.
🔹 32. What is selection sort?
Finds minimum and places it at correct position.
🔹 33. What is insertion sort?
Builds sorted array one element at a time.
🔹 34. What is merge sort?
Divide and conquer sorting algorithm.
🔹 35. What is quick sort?
Uses pivot element for partitioning.
🔹 36. Time complexity?
Measures algorithm performance.
🔹 37. Big O notation?
Represents worst-case complexity.
🔹 38. O(1), O(n), O(log n)?
- O(1): constant time
- O(n): linear time
- O(log n): logarithmic time
🔹 39. What is space complexity?
Memory used by algorithm.
🔹 40. What is linear search?
Search one by one.
🔹 41. What is binary search?
Search in sorted array by dividing.
🔹 42. Binary search condition?
Array must be sorted.
🔹 43. What is greedy algorithm?
Chooses best option at each step.
🔹 44. What is dynamic programming?
Break problem into smaller subproblems.
🔹 45. What is backtracking?
Trying all possible solutions.
🔹 46. Stack real-life example?
Undo operation in software.
🔹 47. Queue real-life example?
Printer queue.
🔹 48. Tree real-life example?
File system structure.
🔹 49. Graph real-life example?
Google Maps routes.
🔹 50. Why data structures important?
They make programs:
- Faster
- Efficient
- Scalable