Independent Preparation Bank for Pakistani Computing Graduates • 100% Free • No Signup
NSCTTest.
Simulator
Problem Solving & Analytical SkillsTopic #4 of 564 MCQs Available

Algorithms & Flow Control

Comprehensive question bank, step-by-step rationales, and dedicated timed quiz for Algorithms & Flow Control.

Launch Quiz Mode ↗

Algorithms & Flow Control Question Bank

Showing 64 questions of 64 with verified answers

6Multiple Choice

(Technique) In a debugger, what is the difference between "Step Over" and "Step Into"?

7Multiple Choice

(Scenario-Based) You have a bug in a file with 10,000 lines of code. You decide to comment out half the code to see if the bug persists, then continue halving the remaining code until you find the exact line. This strategy is known as:

8Multiple Choice

(Comparison) What is the difference between "Static Analysis" and "Dynamic Analysis" in error detection?

9Multiple Choice

(Code Error / Debugging) Identify the potential crash in this C-style code: int *ptr = NULL; if (condition) { ptr = &some_value; } print(*ptr);

10Multiple Choice

(Conceptual) When analyzing a "Stack Trace" after a crash, the function at the very *top** of the list usually represents:

11Multiple Choice

(Scenario-Based) A production server is slowing down over several days until it eventually crashes. After a restart, it works fine for another few days. This pattern strongly suggests which type of error?

12Multiple Choice

(Calculation/Logic) In terms of software engineering costs, a bug found during the *Testing Phase** is generally how much more expensive to fix than a bug found during the *Requirement Analysis Phase**?

13Multiple Choice

(Code Error / Logic) What is the logical flaw in this "Defensive Programming" snippet? if (index < 0 AND index > arr.length): print("Invalid Index")

14Multiple Choice

(Conceptual) What does the term "Dry Running" code mean?

15Multiple Choice

(Scenario-Based) You are debugging a distributed system where two processes are waiting for each other to release a resource, causing the whole system to hang forever. This is called:

16Multiple Choice

(Code Output / Logic) What will be the output of this attempt to swap two numbers? function swap(a, b): a = b b = a x = 5, y = 10 swap(x, y) print(x, y)

17Multiple Choice

(Technique) Why is "Logging" usually preferred over "Print Statements" for debugging professional production applications?

18Multiple Choice

(Conceptual) A bug that only appears when you turn on the compiler's "Optimization" flag is likely due to:

19Multiple Choice

(Scenario-Based) A developer uses a "Watchpoint" while debugging. What is the specific purpose of this tool?

20Multiple Choice

(Code Error / Debugging) Identify the bug in this search algorithm: for i from 0 to arr.length - 1: if arr[i] == target: return i return -1

21Multiple Choice

(Comparison) What is the difference between "Black-Box Debugging" and "White-Box Debugging"?

22Multiple Choice

(Conceptual) "Defensive Programming" is a technique aimed at:

23Multiple Choice

(Calculation/Logic) If a recursive function calls itself twice in every step (like Fibonacci) and has no base case, how fast will it crash with a "Stack Overflow"?

24Multiple Choice

(Scenario-Based) An e-commerce site has a bug where 1% of users are charged twice. The bug is high severity but low frequency. What is the correct priority for the engineering team?

25Multiple Choice

(Conceptual) What is "Unit Testing" and how does it relate to debugging?

1Multiple Choice

(Conceptual) What does Big-O notation strictly represent in algorithmic analysis?

2Multiple Choice

(Calculation) An algorithm processes an array of size N. It contains two separate (not nested) loops: the first loop runs N times, and the second loop runs N times. What is the Big- O complexity?

3Multiple Choice

(Code-Analysis) What is the time complexity of the following code snippet? for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { print(i, j); } }

4Multiple Choice

(Conceptual) If an algorithm's runtime is O(1), how does the execution time change if you increase the input size from 1,000 to 1,000,000?

5Multiple Choice

(Calculation) You have three algorithms for the same task. Algorithm A is O(N²), Algorithm B is O(N log N), and Algorithm C is O(2^N). For an input size of N = 100, which is the most efficient?

6Multiple Choice

(Scenario-Based) A developer is building a search feature for a list of 100,000 items. The list is not sorted. Which complexity will they face for a single search?

7Multiple Choice

(Calculation) Trace the time complexity of this loop: for (int i = 1; i < N; i = i * 2) { print(i); }

8Multiple Choice

(Scenario-Based) A social media platform wants to suggest "Mutual Friends." For every friend a user has (N), the system checks every friend that friend has (N). What is the time complexity of this specific operation?

9Multiple Choice

(Conceptual) What is "Space-Time Trade-off" in algorithmic optimization?

10Multiple Choice

(Code-Analysis) What is the time complexity of this nested loop? for (int i = 0; i < N; i++) { for (int j = 0; j < 500; j++) { print(i, j); } }

11Multiple Choice

(Conceptual) Which of the following describes "Space Complexity"?

12Multiple Choice

(Scenario-Based) You are optimizing a web crawler. You decide to store a list of already-visited URLs in a Set to ensure you don't visit the same site twice. This increases memory usage but speeds up the check. This is an example of:

13Multiple Choice

(Calculation) If an O(2^N) algorithm takes 1 millisecond for N = 10, how long will it take for N = 30?

14Multiple Choice

(Conceptual) In Big-O notation, which term is dominant and kept for f(n) = 5n³ + 2n² + 100 log n + 500?

15Multiple Choice

(Scenario-Based) A developer chooses "Selection Sort" to sort a list of 1 million items. Why is this a poor efficiency decision?

16Multiple Choice

(Code-Analysis) What is the space complexity of an algorithm that creates a 2D matrix of size N x N to store results?

17Multiple Choice

(Calculation) How many times will the "action" be performed in this loop? for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { // action } }

18Multiple Choice

(Conceptual) What does "Big-Omega (Ω)" notation represent?

19Multiple Choice

(Scenario-Based) An algorithm is O(N!). This complexity is most commonly associated with which type of problem?

20Multiple Choice

(Code-Analysis) What is the space complexity of a recursive function that calls itself N times (e.g., recursive factorial)?

21Multiple Choice

(Conceptual) In a "Log-Linear" complexity algorithm (O(N log N)), what happens to the runtime if the input size N doubles?

22Multiple Choice

(Scenario-Based) Why is "Premature Optimization" considered a bad practice in problem solving?

1Multiple Choice

(Conceptual) Which of the following is the primary benefit of "Modularization" in a large programming project?

2Multiple Choice

(Code-Tracing) Trace the following pseudocode. What is the final value of result? x = 10 y = 5 function update(a, b): return (a * 2) - b result = update(y, x)

3Multiple Choice

(Debugging) A developer is writing a program to calculate the average of three numbers. Find the logical bug: num1 = 10 num2 = 20 num3 = 30 average = num1 + num2 + num3 / 3

4Multiple Choice

(Scenario-Based) You are writing a program for a library. You have copied the same 10 lines of "Late Fee Calculation" logic into five different parts of your code. Which programming principle are you violating?

5Multiple Choice

(Code-Tracing) What will be the output of this code snippet? total = 0 for i from 1 to 5: if (i % 2 == 0): total = total + i print(total)

6Multiple Choice

(Scenario-Based) A client wants a simple website with 3 pages. A junior developer suggests using a complex Microservices architecture with a Kubernetes cluster. This is a violation of which principle?

7Multiple Choice

(Conceptual) In programming, what is a "Side Effect"?

8Multiple Choice

(Code-Tracing) Consider this function: function check(val): if (val > 10): return "High" if (val > 5): return "Medium" return "Low" print(check(7))

9Multiple Choice

(Debugging) Why is using "Global Variables" generally considered a poor practice in large-scale problem solving?

10Multiple Choice

(Calculation) You are writing a program to distribute 100 tasks among 3 workers. You want to know how many tasks will be left over after each worker gets an equal share. Which operator should you use?

11Multiple Choice

(Scenario-Based) You are building a weather app. You find that you are writing the code to convert Celsius to Fahrenheit in the "Hourly View," the "Daily View," and the "Settings" page. What is the best problem-solving action?

12Multiple Choice

(Code-Tracing) What is the output? val = 1 for i from 1 to 3: val = val * i print(val)

13Multiple Choice

(Conceptual) What does "Refactoring" code mean?

14Multiple Choice

(Debugging) A developer is writing an infinite loop intentionally for a server but notices it is consuming 100% of the CPU. What is the best way to "solve" this performance problem without stopping the loop?

15Multiple Choice

(Scenario-Based) You need to write a program that calculates taxes based on the user's country. Instead of a giant if-else chain with 200 countries, you use a "Lookup Table" (Dictionary/Map) where the key is the country name and the value is the tax rate. This is an example of:

16Multiple Choice

(Code-Tracing) Trace the logic: x = [1, 2, 3] y = x y[0] = 99 print(x[0]) Assuming x and y are reference types (like in Python or JS):

17Multiple Choice

(Conceptual) What is the "Scope" of a variable?

18Multiple Choice

(Calculation) You are writing an algorithm to paginate search results. You have TotalItems = 55 and ItemsPerPage = 10. Which formula correctly calculates the total number of pages needed?

19Multiple Choice

(Scenario-Based) A function calculateDiscount(price) is supposed to return the final price. However, it also prints "Success!" to the console and saves the price to a history.txt file. These extra actions are called:

20Multiple Choice

(Debugging) Why is "Hard-coding" values like tax = 0.17 directly into your functions considered a bad practice?

21Multiple Choice

(Code-Tracing) Trace this recursion: function mystery(n): if (n == 1): return 1 return n + mystery(n - 1) print(mystery(3))

27Multiple Choice

Consider an algorithm with an outer loop running from i = 1 to n, and an inner loop running from j = 1 to i^2. What is the overall asymptotic time complexity?