




























































































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
Introduces fundamental data structures such as arrays, stacks, queues, linked lists, and trees. Covers algorithmic techniques including recursion, iteration, searching, and sorting (bubble, selection, insertion, merge, quick sort). Emphasis on algorithm analysis (Big-O, time/space complexity).
Typology: Exams
1 / 126
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which property of a good algorithm ensures that it terminates after a finite number of steps? A) Definiteness B) Finiteness C) Input/output D) Generality Answer: B Explanation: Finiteness guarantees that an algorithm terminates after a finite number of steps, which is essential for an algorithm to be considered correct and practical. Question 2. Which data structure abstracts the behavior of "list" with dynamic memory allocation? A) Array B) Linked list C) Stack D) Graph Answer: B
Explanation: A linked list abstracts a list with dynamic memory allocation, allowing efficient insertion and deletion operations without the need for contiguous memory. Question 3. Which asymptotic notation describes the worst-case performance of an algorithm? A) Big-O (O) B) Omega (Ω) C) Theta (Θ) D) Little-o (o) Answer: A Explanation: Big-O notation describes the upper bound on the worst-case performance, providing an upper limit on the time or space complexity. Question 4. If a recursive algorithm has the recurrence relation T(n) = 2T(n/2)
Answer: B Explanation: Sparse matrices are characterized by most elements being zero, which motivates specialized storage techniques for efficiency. Question 7. Which linked list variation allows traversal in both directions? A) Singly linked list B) Doubly linked list C) Circular linked list D) Array list Answer: B Explanation: Doubly linked lists have pointers to both the previous and next nodes, enabling traversal in both directions. Question 8. Which operation is typically more efficient in a singly linked list than an array? A) Random access B) Insertion at beginning C) Binary search D) Indexing
Answer: B Explanation: Inserting at the beginning of a singly linked list is efficient because it involves only changing pointers, whereas arrays require shifting elements. Question 9. Which data structure follows the Last-In, First-Out (LIFO) principle? A) Stack B) Queue C) Priority queue D) Graph Answer: A Explanation: Stacks operate on the LIFO principle, where the last element inserted is the first to be removed. Question 10. Which operation on a stack does the "Peek" or "Top" function perform? A) Remove the top element B) Insert a new element at the top
B) Graph C) Array D) Queue Answer: A Explanation: Trees naturally model hierarchical relationships, with parent- child connections. Question 13. In a binary tree, the "height" of a node is defined as: A) The number of edges on the longest path from the node to a leaf B) The number of children of the node C) The number of ancestors of the node D) The number of sibling nodes Answer: A Explanation: The height of a node in a binary tree is the length of the longest path from that node down to a leaf. Question 14. Which traversal method visits nodes in the order: root, left subtree, right subtree? A) In-order
B) Pre-order C) Post-order D) Level-order Answer: B Explanation: Pre-order traversal visits the root first, then recursively traverses the left and right subtrees. Question 15. Which property is characteristic of a Binary Search Tree (BST)? A) Nodes are in complete binary tree shape B) Left child contains smaller values, right child contains larger values C) All leaves are at the same level D) Nodes only have two children Answer: B Explanation: A BST maintains the property that for each node, values in the left subtree are smaller, and in the right subtree are larger. Question 16. What is the primary advantage of balanced search trees like AVL trees? A) Simplified implementation
A) Heapify process B) Bubble sort C) Quick sort D) Merge sort Answer: A Explanation: The heapify process converts an unordered array into a heap efficiently, typically in O(n) time. Question 19. Which graph representation uses a 2D matrix to indicate the presence or absence of edges? A) Adjacency matrix B) Adjacency list C) Incidence matrix D) Edge list Answer: A Explanation: An adjacency matrix uses a 2D array where each cell indicates whether an edge exists between vertices.
Question 20. Which algorithm is suitable for finding the shortest path in an unweighted graph? A) Dijkstra's algorithm B) Bellman-Ford algorithm C) Breadth-First Search (BFS) D) Floyd-Warshall algorithm Answer: C Explanation: BFS finds the shortest path in unweighted graphs efficiently by exploring neighbors level by level. Question 21. Which algorithm is most appropriate for finding a Minimum Spanning Tree in a weighted graph? A) Kruskal's algorithm B) Bellman-Ford algorithm C) Depth-First Search D) Dijkstra's algorithm Answer: A Explanation: Kruskal's algorithm constructs an MST by adding edges in order of increasing weight, avoiding cycles.
Question 24. Which hashing collision resolution technique involves probing sequentially for an empty slot? A) Separate chaining B) Linear probing C) Double hashing D) Quadratic probing Answer: B Explanation: Linear probing resolves collisions by checking subsequent slots sequentially until an empty slot is found. Question 25. Which sorting algorithm is most efficient (O(n log n)) on average and uses divide-and-conquer? A) Bubble sort B) Merge sort C) Selection sort D) Insertion sort Answer: B Explanation: Merge sort uses divide-and-conquer and achieves O(n log n) average and worst-case time complexity.
Question 26. Which sorting algorithm is stable and in-place, often preferred for small datasets? A) Merge sort B) Quick sort C) Bubble sort D) Heap sort Answer: C Explanation: Bubble sort is stable and in-place but inefficient for large datasets; it is simple and suitable for small data. Question 27. Which non-comparison sorting technique is suitable for sorting integers within a limited range? A) Counting sort B) Radix sort C) Merge sort D) Quick sort Answer: A Explanation: Counting sort is efficient for integers with limited range, counting occurrences for sorting.
Question 30. Which problem is a classic example of backtracking? A) N-Queens problem B) Shortest path problem C) Minimum spanning tree D) Sorting array Answer: A Explanation: The N-Queens problem involves placing queens on a chessboard without conflicts, typically solved via backtracking. Question 31. Which complexity class contains decision problems that can be solved in polynomial time? A) P B) NP C) NP-complete D) NP-hard Answer: A Explanation: P includes decision problems that can be solved efficiently (in polynomial time).
Question 32. Which statement best describes NP-complete problems? A) They are the easiest problems in NP B) They are problems that can be verified quickly but not necessarily solved quickly C) They are problems that are solvable in polynomial time D) They are problems with no known solution Answer: B Explanation: NP-complete problems are verifiable in polynomial time but no known polynomial-time solutions exist for all instances. Question 33. Which data structure is most suitable for implementing a priority queue? A) Array B) Heap C) Linked list D) Graph Answer: B Explanation: A heap provides efficient insertion and deletion of the highest (or lowest) priority element, making it ideal for priority queues.
Question 36. Which property must a graph have to be a Directed Acyclic Graph (DAG)? A) Contains cycles B) No directed cycles C) Undirected D) Fully connected Answer: B Explanation: A DAG must have no directed cycles, which allows for topological sorting. Question 37. Which traversal order is used in topological sorting of a DAG? A) BFS (Level order) B) DFS (Post-order) C) In-order D) Breadth-first search only Answer: B Explanation: Topological sort uses DFS post-order traversal to linearize nodes respecting dependencies.
Question 38. Which algorithm is used to check for cycles in a directed graph? A) Dijkstra's algorithm B) DFS-based cycle detection C) Kruskal's algorithm D) Bellman-Ford algorithm Answer: B Explanation: DFS-based cycle detection identifies back edges indicating cycles in directed graphs. Question 39. In the context of algorithm analysis, the "best-case" performance refers to: A) The maximum amount of time an algorithm takes B) The minimum amount of time an algorithm takes for some input C) The average performance over all inputs D) The performance when input size is zero Answer: B Explanation: Best-case performance is the minimum time or space an algorithm requires for particular input.