











































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!












































1. What is the primary purpose of a data structure? A) To organize and store data efficiently B) To execute programs faster C) To design graphical user interfaces D) To manage network connections Answer: A Explanation: Data structures provide systematic ways to organize and store data so that operations can be performed efficiently. 2. Which of the following best defines an algorithm? A) A step-by-step procedure for solving a problem B) A tool for storing data C) A programming language D) A computer’s hardware component Answer: A Explanation: An algorithm is a well-defined sequence of steps designed to solve a particular problem. 3. What does Big O notation primarily measure? A) The hardware performance of a computer B) The efficiency of an algorithm in terms of time or space C) The accuracy of a program D) The complexity of user interfaces Answer: B Explanation: Big O notation is used to classify algorithms according to their running time or space requirements in the worst-case scenario. 4. Which case does Big O notation represent when analyzing an algorithm? A) Best case only B) Worst case only C) Average case only D) Worst case performance Answer: D Explanation: Big O notation typically describes the worst-case performance of an algorithm. 5. Why are data structures important in problem solving? A) They allow direct hardware control B) They help in designing efficient algorithms and managing data C) They eliminate the need for algorithms D) They are used only in databases Answer: B
Explanation: Data structures are crucial because they enable the efficient management and processing of data, directly impacting algorithm performance.
6. Which of the following is a characteristic of algorithms? A) They must be written in assembly language B) They always guarantee a solution C) They are independent of the programming language used D) They require complex hardware Answer: C Explanation: Algorithms are abstract problem-solving methods that can be implemented in any programming language. 7. How is time complexity generally expressed? A) In bytes B) In Big O notation C) In lines of code D) In processing speed (GHz) Answer: B Explanation: Time complexity is commonly expressed using Big O notation to describe how the running time increases with input size. 8. What is space complexity? A) A measure of the memory required by an algorithm B) The number of bugs in a program C) The speed at which data is processed D) The design of the user interface Answer: A Explanation: Space complexity refers to the amount of memory an algorithm needs to execute relative to the size of the input. 9. Which factor is not directly related to algorithm efficiency? A) Time complexity B) Space complexity C) Hardware cost D) Input size Answer: C Explanation: While hardware cost may affect performance in practice, algorithm efficiency is primarily about time and space complexity relative to input size. 10. What is the worst-case scenario in algorithm analysis? A) When the algorithm uses the maximum possible resources B) When the algorithm performs at its fastest C) When there is no input data D) When only a few operations are executed Answer: A
Explanation: Complexity analysis examines how the algorithm’s running time or space requirements scale as the input size increases.
16. Why is it necessary to know different algorithm complexities (best, average, worst)? A) To design multi-colored software B) To choose the most efficient algorithm for a given scenario C) To ensure the code compiles without errors D) To meet marketing requirements Answer: B Explanation: Knowing the different complexities helps developers choose the best algorithm based on typical, best-case, or worst-case scenarios. 17. What does “asymptotic analysis” refer to? A) Analysis performed after code deployment B) Analyzing the performance of algorithms as input size grows indefinitely C) A method of debugging code D) The study of computer hardware limits Answer: B Explanation: Asymptotic analysis describes the behavior of an algorithm when the input size approaches infinity, helping to understand long-term performance. 18. What is one common pitfall when ignoring space complexity? A) Producing faster code B) Overusing available memory leading to inefficient solutions C) Creating user-friendly applications D) Lowering development costs Answer: B Explanation: Failing to consider space complexity can lead to memory overuse, which might slow down or crash the application. (Topic 1: Introduction to Data Structures and Algorithms Complete) 19. Which of the following is the correct way to declare an array in C? A) int arr[]; B) array int[]; C) int[] arr; D) array arr[]; Answer: A Explanation: In C, you declare an array with a type followed by the array name and square brackets, often with size specified. 20. What is the initial index of an array in most programming languages like C/C++ and Java? A) 1 B) 0 C) - 1
D) Depends on the language Answer: B Explanation: Arrays in languages like C, C++, and Java are zero-indexed, meaning the first element is at index 0.
21. When inserting an element in an array, what is a major concern? A) Memory reallocation cost B) Array styling C) Compiler version D) Network speed Answer: A Explanation: Inserting into an array may require shifting elements or reallocating memory if the array is full. 22. Which algorithm is known for its simple swapping mechanism when sorting an array? A) Merge Sort B) Quick Sort C) Bubble Sort D) Heap Sort Answer: C Explanation: Bubble sort repeatedly swaps adjacent elements that are out of order. 23. What is the time complexity of a simple linear search on an unsorted array? A) O(1) B) O(log n) C) O(n) D) O(n²) Answer: C Explanation: In the worst case, a linear search may inspect every element in the array, making its complexity O(n). 24. What advantage does binary search have over linear search? A) It works on unsorted arrays B) It uses recursion exclusively C) It divides the search space in half each iteration D) It requires no additional memory Answer: C Explanation: Binary search repeatedly divides the search space in half, greatly reducing the number of comparisons needed. 25. What is required for binary search to work correctly? A) The array must be sorted B) The array must be unsorted C) The array must be multidimensional D) The array must have unique elements Answer: A
Answer: A Explanation: Arrays provide constant time access to elements via indexing.
31. Which operation is typically more complex in a fixed-size array? A) Traversal B) Random access C) Insertion in the middle D) Reading the first element Answer: C Explanation: Inserting an element in the middle of an array requires shifting subsequent elements, which is an O(n) operation. 32. What does “traversal” mean in the context of arrays? A) Sorting the array B) Accessing each element sequentially C) Searching for an element D) Deleting the array Answer: B Explanation: Traversal means visiting every element in the array one by one. 33. How does a multi-dimensional array differ from a single-dimensional array? A) It can store only numeric data B) It allows access via multiple indices C) It does not allow random access D) It is not supported by high-level languages Answer: B Explanation: Multi-dimensional arrays use more than one index to access their elements, such as rows and columns. 34. Which sorting algorithm repeatedly selects the smallest (or largest) element and places it in order? A) Quick Sort B) Selection Sort C) Merge Sort D) Bubble Sort Answer: B Explanation: Selection sort finds the smallest element in the unsorted part and swaps it with the first unsorted element. 35. In the context of strings, what does “concatenation” refer to? A) Reversing a string B) Combining two or more strings into one C) Extracting a substring D) Sorting the characters Answer: B Explanation: Concatenation is the process of linking two or more strings end-to-end.
36. Which of the following is true about the KMP algorithm? A) It uses a brute-force approach B) It preprocesses the pattern to build a “lps” array C) It is only used for numeric data D) It sorts the text before searching Answer: B Explanation: KMP builds an array (Longest Prefix Suffix – lps) to determine how far to shift the pattern upon a mismatch. (Topic 2: Arrays and Strings Complete) 37. What is the main characteristic of a singly linked list? A) Each node contains pointers to both the next and previous nodes B) Each node points only to the next node C) It is implemented using arrays D) It allows random access to nodes Answer: B Explanation: A singly linked list has nodes that contain a value and a pointer to the next node only. 38. How do you insert a node at the beginning of a singly linked list? A) By traversing to the end and adding the node B) By updating the new node’s next pointer to the current head and then reassigning the head C) By swapping values with the first node D) By deleting the head and replacing it Answer: B Explanation: To insert at the beginning, the new node’s next pointer is set to the current head, and then the head is updated to the new node. 39. What is the primary disadvantage of linked lists compared to arrays? A) Inefficient memory usage B) Lack of dynamic memory allocation C) They do not support sequential access D) No direct access to the middle elements Answer: D Explanation: Linked lists require traversal from the head to access a middle element, making random access inefficient. 40. Which operation is generally faster in linked lists than in arrays? A) Random access B) Insertion at the beginning C) Searching for an element D) Sorting Answer: B Explanation: Insertion at the beginning of a linked list is O(1) since it involves only pointer updates.
46. What is one common use of linked lists in computer applications? A) Direct memory addressing B) Implementing dynamic data structures such as stacks and queues C) Creating static arrays D) Managing operating system kernels Answer: B Explanation: Linked lists are often used to implement dynamic data structures like stacks, queues, and other flexible lists. 47. In which scenario is a circular linked list particularly useful? A) When you need fast random access B) When you require continuous looping through the list C) When sorting is required D) When working with binary trees Answer: B Explanation: Circular linked lists are useful in applications like round-robin scheduling where the list needs to be looped continuously. 48. What is the key step in reversing a singly linked list? A) Swapping the data of the nodes B) Changing the direction of the pointers C) Sorting the nodes in reverse order D) Allocating new memory for nodes Answer: B Explanation: Reversing a singly linked list is achieved by reassigning each node’s pointer so that it points to the previous node instead of the next one. 49. Which linked list variation allows traversal in both directions? A) Singly linked list B) Doubly linked list C) Circular singly linked list D) Static linked list Answer: B Explanation: A doubly linked list contains pointers to both the next and previous nodes, allowing bidirectional traversal. 50. How can you detect an intersection between two linked lists? A) Compare the head nodes only B) Traverse both lists and compare node addresses C) Sort both lists and then compare D) Use binary search on one list Answer: B Explanation: By traversing both lists and comparing node addresses, you can determine if they share any common nodes.
51. What does the term “node” refer to in linked lists? A) A single data element containing the value and a pointer B) The head of the list only C) The entire linked list structure D) A pointer without data Answer: A Explanation: A node is a basic unit in a linked list containing data and a pointer to the next (and possibly previous) node. 52. Which operation in a linked list is typically O(n) in time complexity? A) Inserting at the beginning B) Deleting the head C) Accessing the nth element D) Reversing the list Answer: C Explanation: Accessing the nth element in a linked list requires traversing from the head, which takes O(n) time. 53. What is the benefit of using linked lists over arrays in terms of memory? A) Linked lists use contiguous memory B) They allow dynamic memory allocation and can grow as needed C) They automatically sort the data D) They require less pointer overhead Answer: B Explanation: Linked lists use nodes allocated individually from memory, allowing flexible growth without the need for contiguous memory allocation. 54. Which of the following is an advanced operation often performed on linked lists? A) Constant time random access B) Finding the nth node from the end C) Direct indexing D) Automatic memory management Answer: B Explanation: Finding the nth node from the end of a linked list is a common advanced operation often solved using two pointers. (Topic 3: Linked Lists Complete) 55. What is the primary operation of a stack data structure? A) FIFO (First In First Out) processing B) LIFO (Last In First Out) processing C) Random access D) Sorting data Answer: B Explanation: A stack follows the Last In First Out principle, meaning the most recently added element is removed first.
Answer: A Explanation: Both push and pop operations on a stack can be performed in constant time.
62. What is a circular queue? A) A queue where the last position connects back to the first B) A stack that works in a circular fashion C) A queue that sorts its elements automatically D) A list that allows random access Answer: A Explanation: A circular queue connects the rear back to the front, making efficient use of storage. 63. Which data structure is often implemented using both arrays and linked lists? A) Binary Search Tree B) Queue C) Graph D) Hash Map Answer: B Explanation: Queues can be implemented using arrays (with circular logic) or linked lists, depending on the requirements. 64. What is the advantage of a double-ended queue (deque) over a regular queue? A) It supports insertion and deletion at both ends B) It automatically sorts data C) It supports random access D) It uses less memory Answer: A Explanation: A deque (double-ended queue) allows adding and removing elements from both the front and rear ends. 65. What is the result of a “peek” operation on a stack? A) It removes the top element B) It returns the top element without removing it C) It clears the stack D) It returns the bottom element Answer: B Explanation: The peek operation returns the top element while leaving the stack unchanged. 66. Which structure is typically used in the implementation of recursive algorithms? A) Queue B) Stack C) Array D) Graph Answer: B Explanation: Recursion uses the call stack to keep track of function calls.
67. In a queue implemented using a linked list, what is the complexity of enqueue and dequeue operations? A) O(1) B) O(n) C) O(log n) D) O(n²) Answer: A Explanation: When properly implemented, both enqueue and dequeue operations in a linked list- based queue run in constant time. 68. What is a primary real-world application of queues? A) Web browser history management B) CPU task scheduling using round-robin C) Managing recursive function calls D) Sorting large arrays Answer: B Explanation: Queues are used in CPU scheduling algorithms like round-robin to manage tasks in the order they arrive. (Topic 4: Stacks and Queues Complete) 69. What is a tree in data structures? A) A linear data structure B) A hierarchical data structure with a root and child nodes C) A structure used for sorting arrays only D) A type of graph with cycles Answer: B Explanation: A tree is a hierarchical data structure with a root node and child nodes connected in a parent-child relationship. 70. Which of the following is NOT a part of a typical tree terminology? A) Root B) Leaf C) Node D) Edge case Answer: D Explanation: The common tree terminology includes nodes, root, leaves, and edges, not “edge case.” 71. What is the order of traversal that visits the root node first, then the left subtree, and finally the right subtree? A) Inorder B) Preorder C) Postorder D) Level order
Explanation: A heap is a nearly complete binary tree that satisfies the heap property (max-heap or min-heap).
77. What is the main purpose of heap sort? A) To sort data using the heap data structure B) To search for elements quickly C) To balance binary trees D) To merge linked lists Answer: A Explanation: Heap sort builds a heap from the data and then repeatedly extracts the maximum or minimum element to sort the array. 78. What is a Trie (prefix tree) primarily used for? A) Storing numerical data B) Managing hierarchical file systems C) Efficiently storing and retrieving strings D) Sorting arrays Answer: C Explanation: A Trie is optimized for storing and searching string keys, making it useful in applications like autocomplete. 79. In a Trie, what does each node typically represent? A) A complete word B) A single character of a string C) A number D) A pointer to an array Answer: B Explanation: Each node in a Trie represents a character; paths from the root form strings. 80. What is the main benefit of using a Trie for dictionary implementations? A) It uses less memory than arrays B) It allows fast prefix-based searches C) It automatically sorts the words D) It prevents duplicate words Answer: B Explanation: Tries enable efficient searches for words with a given prefix, which is valuable in autocomplete systems. 81. Which tree structure supports efficient range queries, such as range sum or minimum? A) Binary Search Tree B) Segment Tree C) AVL Tree D) B-Tree Answer: B Explanation: Segment trees are designed to answer range queries quickly by storing aggregated information in nodes.
82. What is a key characteristic of a complete binary tree used in heaps? A) Every level, except possibly the last, is completely filled B) It allows random node deletion C) It is always perfectly balanced D) It supports multi-directional pointers Answer: A Explanation: In a complete binary tree, all levels are fully filled except possibly the last, which is filled from left to right. (Topic 5: Trees Complete) 83. In graph representations, which structure uses a 2D matrix to indicate edge existence between nodes? A) Adjacency List B) Adjacency Matrix C) Edge List D) Incidence Matrix Answer: B Explanation: An adjacency matrix uses a two-dimensional array where each cell indicates whether an edge exists between node pairs. 84. What is the main advantage of an adjacency list over an adjacency matrix? A) Easier to implement for dense graphs B) Requires less memory for sparse graphs C) Provides faster edge lookup D) Automatically sorts nodes Answer: B Explanation: Adjacency lists use less memory for sparse graphs because they store only the existing edges. 85. Which graph traversal algorithm uses a stack (explicitly or implicitly) and goes as deep as possible before backtracking? A) Breadth-First Search (BFS) B) Depth-First Search (DFS) C) Dijkstra’s Algorithm D) Prim’s Algorithm Answer: B Explanation: DFS uses a stack (or recursion) to explore as deep as possible before backtracking. 86. In a Breadth-First Search (BFS), what data structure is primarily used? A) Stack B) Queue C) Priority Queue D) Linked List Answer: B Explanation: BFS uses a queue to explore nodes level by level.
Explanation: Prim’s algorithm grows the spanning tree by selecting the minimum weight edge from the tree to a vertex not yet in the tree.
92. What does topological sorting of a directed acyclic graph (DAG) produce? A) A sorted list of nodes with cycles B) A linear ordering of vertices respecting the directed edges C) A minimum spanning tree D) A list of nodes sorted by degree Answer: B Explanation: Topological sorting produces a linear ordering of vertices such that for every directed edge u → v, u comes before v. 93. Which algorithm is used to identify strongly connected components in a graph? A) Dijkstra’s Algorithm B) Kosaraju’s Algorithm C) Prim’s Algorithm D) Quick Sort Answer: B Explanation: Kosaraju’s algorithm efficiently finds strongly connected components in directed graphs. 94. What is the primary use of cycle detection algorithms in graphs? A) To sort nodes B) To determine if a graph contains cycles C) To calculate node degrees D) To balance the graph Answer: B Explanation: Cycle detection is essential to determine whether a graph contains any cycles, which is important in many applications. 95. Which network flow algorithm computes the maximum flow in a flow network? A) Ford-Fulkerson Method B) Dijkstra’s Algorithm C) Bellman-Ford Algorithm D) Kruskal’s Algorithm Answer: A Explanation: The Ford-Fulkerson method is used to compute the maximum flow in a network by finding augmenting paths. 96. What is one key application of graph algorithms in real-world scenarios? A) Image processing only B) Social network analysis and routing C) Compiling source code D) Creating databases Answer: B
Explanation: Graph algorithms are widely used in social networks, routing, and many other real- world applications. (Topic 6: Graphs Complete)
97. What is the main idea behind the Union-Find (Disjoint Set Union) data structure? A) It sorts elements in a list B) It maintains a collection of disjoint sets and supports union and find operations C) It builds a binary search tree D) It compresses data Answer: B Explanation: Union-Find efficiently manages a collection of disjoint sets with quick union and find operations. 98. Which optimization techniques are commonly used in Union-Find data structures? A) Quick Sort and Merge Sort B) Path compression and union by rank C) Binary search and interpolation D) DFS and BFS Answer: B Explanation: Path compression and union by rank are two optimizations that speed up Union- Find operations. 99. What is a common application of the Union-Find data structure? A) Sorting large datasets B) Detecting cycles in graphs and implementing Kruskal’s algorithm C) Implementing stacks D) Managing recursion calls Answer: B Explanation: Union-Find is used in Kruskal’s algorithm to detect cycles and maintain connected components. 100. What does the “find” operation in Union-Find do? A) Merges two sets B) Determines which set a particular element belongs to C) Sorts the sets D) Deletes an element from the set Answer: B Explanation: The find operation returns the representative (or parent) of the set to which an element belongs. 101. Which of the following is a primary advantage of using a Binary Indexed Tree (Fenwick Tree)? A) It supports fast point updates and prefix sum queries B) It stores data in a binary tree format C) It requires no memory