




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Covers graph algorithms (BFS, DFS, Dijkstra’s, Kruskal’s, Prim’s), dynamic programming, greedy methods, and backtracking. Includes NP-completeness, approximation algorithms, and practical problem-solving in computational complexity.
Typology: Exams
1 / 127
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which property best characterizes an algorithm? A) It must be expressed in a programming language B) It provides a step-by-step procedure to solve a specific problem C) It is always recursive in nature D) It can only be used for numerical problems Answer: B Explanation: An algorithm is a finite set of well-defined instructions that provides a step-by-step procedure to solve a specific problem, regardless of implementation language or problem type. Question 2. Which of the following is NOT a characteristic of a good algorithm? A) Correctness B) Efficiency C) Ambiguity D) Finite execution time Answer: C
Explanation: A good algorithm must be unambiguous, correct, efficient, and terminate in finite time; ambiguity contradicts the clarity requirement. Question 3. Which data structure is classified as a primitive data structure? A) Array B) Stack C) Integer variable D) Linked list Answer: C Explanation: Primitive data structures are basic data types like integers, floats, characters; complex structures like arrays and lists are non-primitive. Question 4. What distinguishes an abstract data type (ADT) from a concrete data structure? A) ADT is implementation-specific B) ADT defines operations and behavior independent of implementation C) Concrete data structures cannot be implemented in C or C++ D) ADTs contain data but no operations Answer: B
Answer: C Explanation: Dominant term is 3n^2, so the time complexity is O(n^2), representing quadratic growth. Question 7. Which is an example of a recursive recurrence relation? A) T(n) = T(n/2) + n B) T(n) = 2T(n-1) + 1 C) T(n) = n + 1 D) Both A and B Answer: D Explanation: Both A and B are recurrence relations defining T(n) in terms of smaller instances, suitable for recursive analysis. Question 8. What is the primary use of the master theorem? A) To solve linear equations B) To analyze the time complexity of divide-and-conquer algorithms C) To implement recursive functions D) To optimize memory usage in algorithms
Answer: B Explanation: The master theorem provides a direct way to determine the asymptotic bounds of recurrence relations typical in divide-and-conquer algorithms. Question 9. Which C/C++ construct allows dynamic memory allocation? A) malloc() and calloc() B) static variables C) automatic variables D) #define directive Answer: A Explanation: malloc() and calloc() are functions used for dynamic memory allocation on the heap; static and automatic variables are stack allocated. Question 10. Which statement correctly describes recursion? A) It is a process where a function calls itself directly or indirectly B) It always leads to iterative solutions C) It replaces the need for base cases D) It is only useful for mathematical calculations
D) Heap (not binary) Answer: B Explanation: Arrays are linear, contiguous memory structures. Trees and graphs are non-linear, heaps are specialized tree structures. Question 13. What is a key disadvantage of arrays compared to linked lists? A) Fixed size and contiguous memory requirement B) Dynamic resizing is easy C) Insertion and deletion at arbitrary positions are efficient D) They use pointers for navigation Answer: A Explanation: Arrays are fixed in size and require contiguous memory, making dynamic resizing and insertion/deletion at arbitrary positions less efficient. Question 14. In a singly linked list, which operation is most complicated? A) Traversal B) Insertion at the beginning C) Deletion of a node given only its pointer D) Reversing the list
Answer: C Explanation: Deletion of a node given only its pointer involves updating the previous node's pointer, which requires traversal to find the predecessor if only the node's pointer is available. Question 15. Which linked list type allows for efficient insertion and deletion from both ends? A) Singly linked list B) Doubly linked list C) Circular linked list D) Array Answer: B Explanation: Doubly linked lists have pointers to both previous and next nodes, enabling efficient insertion/deletion at both ends. Question 16. What is an advantage of circular linked lists over singly linked lists? A) They do not require pointers B) They allow for continuous traversal without null termination
B) Stack C) Hash table D) Graph Answer: B Explanation: Stacks naturally support undo/redo operations because of their LIFO property, allowing last action to be reversed easily. Question 19. In a queue, which operation removes the element at the front? A) enqueue() B) dequeue() C) pop() D) push() Answer: B Explanation: The dequeue() operation removes and returns the element at the front of a queue, adhering to FIFO principle. Question 20. Which queue implementation provides better space utilization in fixed-size arrays? A) Simple Queue with linear array
B) Circular Queue C) Deque D) Priority Queue Answer: B Explanation: Circular queues reuse space freed by dequeued elements, avoiding the problem of wasted space at the front in linear queues. Question 21. What is a key advantage of a deque (double-ended queue)? A) Insertion and deletion only at the front B) Insertion and deletion at both ends C) Cannot be implemented with arrays D) Only supports FIFO operations Answer: B Explanation: Deques support insertion and deletion operations at both ends, providing greater flexibility. Question 22. Which is an application of a priority queue? A) Implementing a stack B) Operating system process scheduling based on priority
D) All nodes are at the same depth Answer: C Explanation: BSTs maintain the property that left descendants are less than the node, and right descendants are greater, enabling efficient search. Question 25. Which operation in a BST can cause the tree to become unbalanced? A) Insertion of nodes in sorted order B) Deletion of leaf nodes C) Search for a node D) Traversal in inorder sequence Answer: A Explanation: Inserting nodes in sorted order can create skewed trees, degrading performance, which balanced trees aim to prevent. Question 26. What is the primary purpose of AVL trees? A) To implement priority queues B) To maintain a balanced binary search tree for efficient operations C) To store data in a heap structure
D) To perform graph traversal Answer: B Explanation: AVL trees are self-balancing BSTs that maintain a height difference (balance factor) to ensure efficient operations. Question 27. Which rotation is used to restore balance after an insertion that causes imbalance in an AVL tree? A) Left rotation B) Right rotation C) Single or double rotations (left-right or right-left) D) No rotation needed Answer: C Explanation: Depending on the imbalance pattern, AVL trees perform single or double rotations to restore balance after insertions or deletions. Question 28. Which self-adjusting binary search tree algorithm moves recently accessed elements closer to the root? A) AVL Tree B) Red-Black Tree
D) All of the above Answer: D Explanation: Insertions, deletions, and heapify operations in heaps are performed in O(log n) due to the height of the complete binary tree. Question 31. Which graph representation is more space-efficient for sparse graphs? A) Adjacency matrix B) Adjacency list C) Incidence matrix D) Adjacency table Answer: B Explanation: Adjacency lists are more space-efficient for sparse graphs, storing only existing edges, unlike adjacency matrices which allocate space for all possible edges. Question 32. Which graph traversal algorithm can detect cycles in a graph? A) Breadth-First Search (BFS) B) Depth-First Search (DFS)
C) Dijkstra's Algorithm D) Topological Sort Answer: B Explanation: DFS can detect cycles by checking back edges during traversal, indicating cycles in directed or undirected graphs. Question 33. What is the main purpose of topological sorting in a directed acyclic graph (DAG)? A) Find the shortest path B) Detect cycles C) Linearize nodes respecting dependency order D) Find the minimum spanning tree Answer: C Explanation: Topological sort arranges nodes linearly such that for every directed edge u→v, u appears before v, respecting dependencies. Question 34. Which algorithm is used to find the minimum spanning tree in a weighted graph? A) Dijkstra's algorithm
A) Queue B) Min-priority queue (heap) C) Stack D) Hash table Answer: B Explanation: Dijkstra's algorithm uses a min-priority queue (often implemented as a min-heap) to efficiently select the vertex with the smallest tentative distance. Question 37. In a hash table, which collision resolution technique involves probing sequentially for the next available slot? A) Separate chaining B) Linear probing C) Double hashing D) Quadratic probing Answer: B Explanation: Linear probing handles collisions by checking subsequent slots in a linear sequence until an empty slot is found.
Question 38. Which sorting algorithm is based on divide and conquer and guarantees stability? A) Bubble sort B) Merge sort C) Quick sort D) Heap sort Answer: B Explanation: Merge sort divides the array recursively and merges sorted subarrays, maintaining stability by preserving equal element order. Question 39. Which sorting algorithm generally performs the best on average for large datasets? A) Bubble sort B) Selection sort C) Quick sort D) Insertion sort Answer: C Explanation: Quicksort has an average-case time complexity of O(n log n) and performs well on large datasets, though its worst case is O(n^2).