Data Structures Viva Questions with Answers
1. What is a Data Structure?
A Data Structure is a way of organizing, storing, and managing data in a computer so that it can be
accessed and modified efficiently.
2. What are the types of Data Structures?
1. Primitive Data Structures - int, float, char, etc.
2. Non-Primitive Data Structures:
- Linear - Array, Linked List, Stack, Queue
- Non-Linear - Tree, Graph
- Hash-based - Hash Table
3. Difference between Linear and Non-Linear Data Structures.
Linear DS: Arranged in sequence (e.g., Array, Queue)
Non-Linear DS: Hierarchical structure (e.g., Tree, Graph)
4. Define Array.
An array is a collection of similar data elements stored in contiguous memory locations.
Example: int arr[5] = {1, 2, 3, 4, 5};
Use case: Efficient random access of elements.
5. What is a Linked List?
A Linked List is a linear data structure where each element (node) contains data and a pointer to the
next node.
Types: Singly, Doubly, Circular
Use case: Dynamic memory allocation.
6. Difference between Array and Linked List.
Array: Fixed size, random access
Linked List: Dynamic size, sequential access
7. Define Stack.
A stack is a linear data structure that follows LIFO (Last In, First Out) principle.
Operations: push, pop, peek
Use case: Function call stack
8. Define Queue.
A queue is a linear data structure that follows FIFO (First In, First Out) principle.
Operations: enqueue, dequeue
Use case: Task scheduling
9. Difference between Stack and Queue.
Stack: LIFO, one end used
Queue: FIFO, two ends used
10. What is a Tree?
A tree is a non-linear hierarchical data structure consisting of nodes.
Use case: File systems, databases
11. Define Binary Tree and Binary Search Tree.
Binary Tree: Each node has at most two children.
BST: Left child < parent < right child
12. What is a Graph?
A graph is a non-linear data structure consisting of nodes connected by edges.
Use case: Social networks, navigation
13. What is a Hash Table?
Stores data in key-value pairs using a hash function.
Use case: Fast lookup like dictionaries.
14. Where are insertion and deletion operations used?
Insertion: push (Stack), enqueue (Queue), add (Linked List)
Deletion: pop (Stack), dequeue (Queue), remove (Linked List)
15. What is the difference between enqueue and dequeue?
Enqueue: Insert at rear
Dequeue: Remove from front
16. Time complexity of common operations:
Array: Insertion O(n), Deletion O(n), Search O(n)
Linked List: Insertion O(1), Deletion O(1), Search O(n)
Stack/Queue: Most operations O(1)
17. What is a Circular Queue?
Queue where last position is connected back to the first.
Use case: Streaming buffer
18. Advantages of Linked List over Array?
Dynamic size, easier insert/delete, no memory wastage
19. What is a Double-Ended Queue (Deque)?
A data structure where insert/delete can happen at both ends.
Use case: Palindrome check, sliding window
20. What is a Priority Queue?
Queue where elements are dequeued based on priority.
Use case: CPU scheduling
21. What is recursion and how is it related to stack?
Recursion is function calling itself; stack stores the function calls.
22. What is a Heap?
Special tree-based structure. Max Heap: Parent > Children. Min Heap: Parent < Children
Use case: Priority Queue
23. Difference between Tree and Graph.
Tree: Hierarchical, no cycles, has root
Graph: General network, can have cycles, no root
24. What is Depth-First Search (DFS)?
Graph traversal using stack (explicit or recursion).
25. What is Breadth-First Search (BFS)?
Graph traversal using queue.
26. Applications of Stack.
Expression evaluation, syntax parsing, undo operations, backtracking.
27. Applications of Queue.
Job scheduling, data streams, BFS traversal.
28. Singly vs Doubly Linked List.
Singly: One direction, less memory
Doubly: Two directions, more memory
29. What is a Sparse Matrix?
Matrix with mostly zero elements. Use case: Space-efficient storage
30. What is a Hash Collision?
Two keys hashing to same index. Resolved by chaining or open addressing.
31. What is a Trie?
Prefix tree used to store strings. Use case: Autocomplete, dictionary.
32. Types of Linked Lists.
Singly, Doubly, Circular, Circular Doubly Linked List