




























































































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!





























































































This assessment covers the core topics required for the Foundation Certification, including Data Structures (Arrays, Strings, Stacks, Queues, Sets, Maps), Algorithms (Sorting, Searching, Recursion, Greedy), Computational Mathematics (GCD, Primality, Modular Arithmetic), and Complexity Analysis.
ALGORITHMS (Questions 1–20)
Q1. What is the primary purpose of a data structure? A) To execute programs faster B) To organize and store data efficiently C) To design graphical user interfaces D) To manage network connections Answer: B) To organize and store data efficiently Explanation: Data structures provide systematic ways to organize and store data so that operations like insertion, deletion, and searching can be performed efficiently.
Q2. 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) A step-by-step procedure for solving a problem
Q4. Which case does Big O notation typically represent? A) Best case only B) Worst case only C) Average case only D) All cases Answer: B) Worst case only Explanation: Big O notation generally describes the worst-case performance of an algorithm, focusing on how the time grows with the input size.
Q5. 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) A measure of the memory required by an algorithm
Explanation: Space complexity refers to the amount of memory an algorithm needs to execute relative to the size of the input.
Q6. 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) They help in designing efficient algorithms and managing data Explanation: Data structures are crucial because they enable the efficient management and processing of data, which directly impacts algorithm performance.
Answer: B) Analyzing the performance of algorithms as input size grows indefinitely Explanation: Asymptotic analysis helps us understand the long-term performance of an algorithm as the input size approaches infinity.
Q9. 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) In Big O notation Explanation: Time complexity is commonly expressed using Big O notation to describe how the running time increases with input size.
Q10. Which factor is NOT directly related to algorithm efficiency? A) Time complexity B) Space complexity C) Hardware cost D) Input size Answer: C) Hardware cost Explanation: While hardware may affect actual execution speed, algorithm efficiency is primarily about time and space complexity relative to input size.
Q11. Which complexity is often ignored, leading to potential memory overuse? A) Time complexity B) Space complexity C) Code complexity D) Line complexity
Q13. What is a common pitfall when analyzing only the worst-case scenario? A) Over-optimizing for rare cases B) Misunderstanding the average performance C) Ignoring hardware limitations D) Writing longer code Answer: B) Misunderstanding the average performance Explanation: Focusing solely on worst-case can make you choose an algorithm that is suboptimal for the typical data distribution.
Q14. Which of the following represents a linear time complexity? A) O(1) B) O(log n) C) O(n) D) O(n²)
Answer: C) O(n) Explanation: O(n) means the algorithm's running time grows linearly with the input size. Searching an unsorted array is O(n).
Q15. A function has a space complexity of O(1). This means: A) It uses no memory B) It uses constant memory regardless of input size C) It uses memory proportional to the input size D) It uses memory exponentially Answer: B) It uses constant memory regardless of input size Explanation: O(1) space complexity means the algorithm uses a fixed amount of memory, independent of the input.
Q16. Which of the following is a valid reason for using recursion?
Answer: B) Base case Explanation: The base case stops the recursion. Without it, the function would call itself indefinitely, leading to a stack overflow.
Q18. Which of the following statements about recursion is TRUE? A) Every recursive function can also be written iteratively B) Recursion always uses less memory than iteration C) Recursion cannot be used with arrays D) Recursion only works with integers Answer: A) Every recursive function can also be written iteratively Explanation: Recursion is a programming technique; any recursive solution can be implemented iteratively using loops and a stack.
Q19. The "call stack" in recursion is used to:
A) Store the function's output B) Keep track of active function calls C) Store global variables D) Display errors Answer: B) Keep track of active function calls Explanation: Each recursive call pushes a new frame onto the call stack. When the base case is reached, the stack unwinds.
Q20. What is the maximum depth of recursion that can be safely implemented? A) Unlimited B) Dependent on the stack size and the problem constraints C) Always 1000 D) Always 100 Answer: B) Dependent on the stack size and the problem constraints
Q22. 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) Memory reallocation cost Explanation: Inserting into an array may require shifting existing elements. If the array is full, reallocation (dynamic array) is needed.
Q23. 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) O(n) Explanation: In the worst case, a linear search may inspect every element in the array, making its complexity O(n).
Q24. 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) It divides the search space in half each iteration Explanation: Binary search repeatedly halves the search space, greatly reducing the number of comparisons.
Q25. What is required for binary search to work correctly?
Explanation: Bubble sort repeatedly swaps adjacent elements that are out of order.
Q27. 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) Selection Sort Explanation: Selection sort finds the smallest element in the unsorted part and swaps it with the first unsorted element.
Q28. 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) Combining two or more strings into one Explanation: Concatenation is the process of linking two or more strings end-to-end.
Q29. Which is true about the KMP algorithm? A) It uses a brute-force approach B) It preprocesses the pattern to build an “lps” array C) It is only used for numeric data D) It sorts the text before searching Answer: B) It preprocesses the pattern to build an “lps” array