




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which of the following best defines an algorithm? A) A set of instructions for solving a specific problem with characteristics like finiteness and definiteness B) A data structure that organizes data for efficient access C) A programming language syntax for implementing solutions D) An unstructured process that may or may not solve a problem Answer: A Explanation: An algorithm is a finite, well-defined set of instructions designed to solve a particular problem, characterized by clarity, correctness, and efficiency. Question 2. Which characteristic differentiates an algorithm from a simple process? A) Its ability to be executed by a computer B) Its finiteness and definiteness C) Its use of data structures D) Its implementation in code Answer: B
Explanation: The key characteristic of an algorithm is that it must be finite and well-defined, ensuring it terminates after a finite number of steps with a solution. Question 3. How are algorithms related to data structures? A) Data structures are a subset of algorithms B) Algorithms organize data within data structures to solve problems efficiently C) Data structures and algorithms are unrelated concepts D) Data structures are only used after algorithms have been designed Answer: B Explanation: Algorithms often utilize data structures to organize and manipulate data efficiently, enabling effective problem-solving. Question 4. Which of the following best describes the time complexity of an algorithm? A) The amount of memory used during execution B) The number of steps an algorithm takes relative to input size C) The number of data structures employed
D) Little-o Answer: C Explanation: Theta (Θ) notation indicates a tight bound, meaning the algorithm's running time grows asymptotically at a specific rate from above and below. Question 7. When analyzing recursive algorithms, which method is commonly used to solve recurrence relations? A) Divide and conquer B) Master Theorem C) Dynamic programming D) Greedy approach Answer: B Explanation: The Master Theorem provides a systematic way to analyze recurrence relations for divide-and-conquer algorithms, determining their asymptotic complexity. Question 8. Which of the following is an example of amortized analysis? A) Calculating the average time per operation over a sequence of operations,
such as in dynamic array resizing B) Worst-case analysis of quicksort C) Analyzing the space complexity of recursive algorithms D) Comparing sorting algorithms based on best-case scenarios Answer: A Explanation: Amortized analysis averages the cost of operations over a sequence, accounting for occasional expensive steps like resizing in dynamic arrays. Question 9. Which programming construct is essential for implementing recursion? A) Looping statements like for or while B) Function calls that invoke themselves C) Pointer arithmetic D) Arrays and lists Answer: B Explanation: Recursion relies on functions that call themselves with modified parameters, enabling solutions to problems that can be broken down into smaller subproblems.
Explanation: Stacks can be implemented using arrays or linked lists, supporting LIFO operations like push and pop efficiently. Question 12. What is the primary characteristic of a queue? A) Last-In, First-Out (LIFO) B) First-In, First-Out (FIFO) C) Random access to elements D) Sorted order maintenance Answer: B Explanation: Queues operate on the FIFO principle, where elements are added at the rear and removed from the front. Question 13. Which operation in a queue removes the element at the front? A) Enqueue B) Dequeue C) Push D) Pop Answer: B
Explanation: Dequeue removes the element at the front of the queue, following FIFO order. Question 14. What distinguishes a circular queue from a linear queue? A) Circular queue can grow dynamically B) The rear wraps around to the front when space is available, making efficient use of space C) Circular queue allows insertion at both ends D) Circular queue does not have a rear pointer Answer: B Explanation: Circular queues wrap around, using space efficiently by connecting the end of the array back to the front, avoiding wasted space. Question 15. Which data structure is most suitable for implementing a depth-first search (DFS) traversal? A) Queue B) Stack or recursive call stack C) Priority queue D) Hash table
D) Level order Answer: B Explanation: Preorder traversal visits the root first, then recursively traverses the left and right subtrees. Question 18. In a binary search tree (BST), where is the smallest element located? A) In the root node B) In the leftmost leaf node C) In the rightmost leaf node D) Randomly distributed Answer: B Explanation: The smallest element in a BST is located at the leftmost leaf, as values decrease to the left. Question 19. Which property characterizes an AVL tree? A) Self-balancing with a balance factor of - 1, 0, or 1 for every node B) All leaves are at the same depth C) It is always perfectly balanced
D) It does not require rotations during insertion or deletion Answer: A Explanation: AVL trees maintain balance by ensuring the balance factor (height difference between left and right subtrees) is within - 1 to 1, requiring rotations when necessary. Question 20. What operation in a heap maintains the heap property after insertion? A) Heapify-up (sift-up) B) Heapify-down (sift-down) C) Bubble sort D) Quick sort Answer: A Explanation: After insertion, the heap property is restored using heapify-up, which compares the inserted element with its parent and swaps if necessary. Question 21. Which of the following is a property of a min-heap? A) The parent node is always smaller than its children B) The root node is always the maximum element
B) Linked list C) Tree D) Stack Answer: A Explanation: An adjacency matrix uses a 2D array to represent edge presence between vertices, providing constant-time access. Question 24. In a weighted, undirected graph, what is the purpose of a minimum spanning tree (MST)? A) To connect all vertices with the minimum total edge weight without cycles B) To find the shortest path between two vertices C) To detect cycles in the graph D) To partition the graph into disconnected components Answer: A Explanation: An MST connects all vertices with the minimum total edge weight, ensuring no cycles, often used in network design. Question 25. Which algorithm is commonly used to find a minimum spanning tree?
A) Dijkstra's algorithm B) Prim's algorithm C) Bellman-Ford algorithm D) Floyd-Warshall algorithm Answer: B Explanation: Prim's algorithm builds an MST by starting from an arbitrary node and greedily adding the smallest edge connecting the tree to a new vertex. Question 26. Which shortest path algorithm can handle graphs with negative edge weights but no negative cycles? A) Dijkstra's algorithm B) Bellman-Ford algorithm C) Floyd-Warshall algorithm D) Prim's algorithm Answer: B Explanation: Bellman-Ford algorithm can handle negative edge weights and detect negative cycles, making it suitable for such graphs.
Question 29. What is the average-case time complexity of Quick Sort? A) O(n^2) B) O(n log n) C) O(log n) D) O(n) Answer: B Explanation: On average, Quick Sort partitions the array well, leading to O(n log n) complexity, although worst-case is O(n^2). Question 30. Which sorting algorithm is stable and in-place? A) Merge sort B) Bubble sort C) Heap sort D) Radix sort Answer: B Explanation: Bubble sort is stable (maintains relative order of equal elements) and in-place, as it sorts by swapping adjacent elements without extra space.
Question 31. Counting Sort is most effective when data elements are: A) Uniformly distributed integers within a limited range B) Floating-point numbers C) Large, sparse datasets D) Strings of varying lengths Answer: A Explanation: Counting Sort works efficiently when data are integers within a known, limited range, as it counts occurrences. Question 32. Radix Sort primarily sorts based on: A) Digit positions, from least significant to most significant B) String lexicographical order C) Randomized pivot points D) Pairwise comparisons Answer: A Explanation: Radix Sort sorts numbers digit by digit, starting from the least significant digit, using stable sorting algorithms like counting sort.
Question 35. In a hash table, a good hash function should: A) Distribute keys uniformly across buckets B) Map all keys to the same index C) Be computationally expensive D) Avoid collisions at all costs Answer: A Explanation: A good hash function spreads keys uniformly, minimizing collisions and ensuring efficient lookups. Question 36. Which collision resolution technique involves probing for the next available slot? A) Chaining B) Open addressing C) Separate chaining D) Hashing with linked lists Answer: B Explanation: Open addressing resolves collisions by probing sequentially or via a function until an empty slot is found.
Question 37. Linear probing resolves collisions by: A) Searching linearly for the next free slot B) Chaining collided elements in a linked list C) Using double hashing D) Rehashing the entire table Answer: A Explanation: Linear probing searches sequentially in the table until an empty slot is found, resolving collisions in open addressing. Question 38. Which divide-and-conquer sorting algorithm is typically faster on average? A) Bubble sort B) Merge sort C) Selection sort D) Insertion sort Answer: B Explanation: Merge sort has a consistent average-case complexity of O(n log n) and is faster than simple sorts like bubble or insertion on large data.