Algorithmic Thinking MCQs for NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

Algorithmic thinking is the skill of turning a task into a finite list of precise steps, then checking those steps by hand with dry runs and trace tables. It is one of the 16 official topics in Problem Solving and Analytical Skills, which carries 20% of the NSCT according to HEC's Areas of Competencies. Questions here usually give you a short piece of code or pseudocode and ask what it prints, how many times a loop runs, or which input breaks it.

This topic builds on Algorithms & Flow Control, which covers how to read pseudocode and flowcharts. Here the focus is on designing steps and checking them.

Step design

An algorithm is a finite sequence of well-defined steps that takes input and produces the required output. Knuth lists five properties:

Property Meaning Breaks when…
Finiteness Stops after a finite number of steps A loop condition can never become false
Definiteness Every step is precise and unambiguous A step says "add a few numbers"
Input Takes zero or more inputs –
Output Produces at least one output Nothing is returned or printed
Effectiveness Each step is basic enough to carry out exactly A step needs an unbounded search with no method

Good step design uses top-down design (stepwise refinement): write the task as 3–5 big steps, then refine each until it is simple enough to code. Variables play standard roles: a counter adds 1 per event, an accumulator builds a running total, a flag records a yes/no condition, and a sentinel is a special input value that marks the end of data.

Exam angle: ordering questions test dependencies. A step can only run once every value it uses has been computed, so "divide by N" must come after "add up all N values".

Dry runs

A dry run is executing an algorithm by hand with chosen test values, following each step exactly as written rather than as you think it should work. Choose inputs that test the boundaries, known as edge cases:

Exam angle: "which input exposes the bug?" questions are dry-run questions. Try each option on the code; the right answer is the one whose output differs from what the specification says.

Trace tables

A trace table records a dry run. It has one column per variable (and one for output if useful) and one row for each step or loop iteration. This code adds the even numbers in a list:

a = [3, 4, 7, 10]
total = 0
for x in a:
    if x % 2 == 0:
        total = total + x
print(total)
x x % 2 == 0? total
– – 0
3 False 0
4 True 4
7 False 4
10 True 14

It prints 14. Writing the table forces you to record values you would otherwise "remember" wrongly, especially in nested loops and when variables are updated together.

Exam angle: watch the last iteration. Most trace mistakes happen where the loop condition is checked one final time, for example range(1, 5) stops at 4, not 5.

Correctness and termination

A dry run shows that an algorithm works for the inputs you tried; it does not prove it works for all inputs. Testing shows the presence of bugs, not their absence (Dijkstra). For a proof, CLRS uses a loop invariant, a condition that holds before the loop and after every iteration, checked in three parts: initialisation, maintenance and termination. To show that a loop stops, find a quantity that moves towards a bound on every iteration, such as high − low in binary search.

Exam angle: a loop with while i != 10 and a step of 3 never stops, because i jumps from 9 to 12. Prefer < or > conditions.

Common traps

Worked examples

Understanding. An algorithm's last step is "go back to step 1", and no step ever ends the process. Which property does it break?

Answer: finiteness. Every step may be precise, but the procedure never terminates, so it is not an algorithm in Knuth's sense.

Application. What does this print?

x = 2
for i in range(3):
    x = x * x
print(x)

Answer: 256. The trace for x is 2 → 4 → 16 → 256. The loop squares x three times; it does not multiply by 2 or 3.

Analysis. This code should count marks strictly above 50. It prints 3. What is wrong?

count = 0
for m in [50, 70, 40, 90]:
    if m >= 50:
        count = count + 1
print(count)

Answer: the condition should be m > 50. With >=, the mark 50 is counted too. Only 70 and 90 are strictly above 50, so the correct output is 2. Testing with a value exactly on the boundary (50) is what exposes the bug.

Practise

The quiz below has 99 original questions, filterable by tier (understanding, application, analysis) and difficulty. Every code output in it was checked by running the code.

Practise: 99 questions

Interactive quiz loading. The first 10 questions are shown below.

  1. Which statement best defines an algorithm?

    1. Any program written in a high-level language
    2. A diagram that shows the hardware of a computer
    3. A finite sequence of precise steps that solves a problem and stops
    4. A list of every possible input to a program
    Show answer

    Answer: C. A finite sequence of precise steps that solves a problem and stops

    An algorithm is a finite, well-defined sequence of steps that turns input into the required output and terminates. It exists independently of any language: the same algorithm can be written as pseudocode, a flowchart or code.

  2. Which property of an algorithm requires it to stop after a finite number of steps?

    1. Finiteness
    2. Definiteness
    3. Effectiveness
    4. Generality
    Show answer

    Answer: A. Finiteness

    Knuth lists finiteness, definiteness, input, output and effectiveness as properties of an algorithm. Finiteness means it always terminates after a finite number of steps; a procedure that can loop forever is not an algorithm in this sense.

  3. The step 'add a few of the numbers' violates which property of an algorithm?

    1. Finiteness
    2. Output
    3. Input
    4. Definiteness
    Show answer

    Answer: D. Definiteness

    Definiteness means every step is precisely and unambiguously specified. 'A few' could mean two or ten, so two people following the step could do different things.

  4. What is a dry run?

    1. Running a program without any input
    2. Working through an algorithm by hand with sample values, recording what each step does
    3. Compiling a program without executing it
    4. Deleting unused variables from code
    Show answer

    Answer: B. Working through an algorithm by hand with sample values, recording what each step does

    A dry run is a manual execution on paper (or in your head) using chosen test values. You follow each step exactly as written, which exposes logic errors before or without running the program.

  5. In a trace table, what do the columns and rows usually represent?

    1. Columns are lines of code; rows are programmers
    2. Columns are variables (and output); each row records their values after a step or iteration
    3. Columns are inputs; rows are compile errors
    4. Columns are loops; rows are functions
    Show answer

    Answer: B. Columns are variables (and output); each row records their values after a step or iteration

    A trace table has one column per variable (plus conditions or output if useful). Each new row shows the values after a step or loop iteration, so you can see exactly how the state changes.

  6. When swapping the values of two variables, why is a temporary variable normally used?

    1. To make the program run faster
    2. To keep one original value before it is overwritten
    3. Because two variables cannot be compared directly
    4. To free memory used by the first variable
    Show answer

    Answer: B. To keep one original value before it is overwritten

    Writing a = b destroys a's old value. Storing it first (temp = a; a = b; b = temp) keeps it so it can be copied into b. Without the temporary variable, both end up holding b's value.

  7. In the step total = total + x inside a loop, what role does total play?

    1. Accumulator
    2. Counter
    3. Flag
    4. Sentinel
    Show answer

    Answer: A. Accumulator

    An accumulator builds up a running result, such as a sum, by adding each new value. A counter increases by a fixed amount (usually 1) to count events, a flag records a yes/no condition, and a sentinel marks the end of input.

  8. Top-down design (stepwise refinement) means:

    1. Starting with the whole task and repeatedly breaking each step into smaller, more detailed steps
    2. Writing the most detailed code first and grouping it later
    3. Testing the program from the last line upwards
    4. Designing only the user interface first
    Show answer

    Answer: A. Starting with the whole task and repeatedly breaking each step into smaller, more detailed steps

    Stepwise refinement, described by Niklaus Wirth, starts with a high-level outline and refines each step until it is simple enough to code directly. It keeps each sub-problem small and manageable.

  9. What is a loop invariant?

    1. A variable whose value never changes inside the loop
    2. The condition that makes the loop stop
    3. A condition that is true before the loop starts and stays true after every iteration
    4. The number of times the loop body executes
    Show answer

    Answer: C. A condition that is true before the loop starts and stays true after every iteration

    As used in CLRS, a loop invariant is a property that holds before the first iteration and is preserved by every iteration. Combined with the exit condition, it proves the loop produces the right result. Variables can and usually do change while the invariant stays true.

  10. Which set of test inputs best checks the edge cases of a 'find the largest element' algorithm?

    1. Three lists of five random positive numbers
    2. An empty list, a one-element list and a list of all-negative numbers
    3. One very long list of positive numbers
    4. Lists that are already sorted in ascending order only
    Show answer

    Answer: B. An empty list, a one-element list and a list of all-negative numbers

    Edge cases sit at the boundaries of valid input: no elements, exactly one element, and values that break hidden assumptions (such as negatives when the code starts from 0). Random typical inputs rarely expose these bugs.

FAQs

Is algorithmic thinking part of the NSCT syllabus?

Yes. HEC lists Algorithmic Thinking as one of the 16 topics under Problem Solving and Analytical Skills in its Areas of Competencies. Expect short code or pseudocode traces, loop counts and step-ordering questions rather than long programs.

How do I trace code faster under time pressure?

Write a mini trace table in the margin with one column per changing variable. Update only the values that change in each step, and mark the moment the loop condition becomes false. With practice you will spot patterns, such as a loop that halves its variable running about log₂n times.

Which language do trace questions use?

The questions on this site use Python and plain pseudocode, because they read clearly for students from any programming background. The tracing method is the same in C++ or Java: follow each assignment in order, and remember that integer division and loop bounds can differ slightly between languages.

What is the difference between a dry run and debugging?

A dry run is a planned walk-through of the logic with chosen inputs, often done before the code runs at all. Debugging starts from a known wrong result and searches for its cause. Dry runs are one of the main tools you use while debugging, which is covered in Debugging & Error Analysis.

Next step

Move on to Critical Thinking & Decision Making MCQs, go back to the Problem Solving hub, or time yourself with an NSCT mock test.