TK Study

Software Engineering › How to answer › pseudocode questions

How to answer pseudocode questions

Pseudocode questions ask you to write (or fix) an algorithm in NESA’s style. You are marked on structure and logic, not on perfect typing. Learn the five-step routine and the few rules the markers look for. From course notes From NESA material

What it looks like in the real exam

From NESA material 2025 HSC 2025 HSC exam, Q17 (3 marks): an algorithm that sums an array and gives a risk rating. 2025 sample 2025 NESA sample exam, Q14 (3 marks, subroutines and RETURN). 2025 familiarisation 2025 NESA familiarisation exam, Q8 (3 marks, fix a linear search) and 2025 NESA familiarisation exam, Q13. The online exam gives you a pseudocode editor (the familiarisation exam has it on Q8 so you can practise).

From NESA material Typical tasks: write an algorithm from a description, complete or fix given pseudocode, or read it and say what it does (see also trace tables).

The conventions (what markers expect)

IdeaWrite it like this
Start/endBEGIN Name … END Name (same name)
KeywordsCAPITALS, in pairs: IF … THEN … ELSE … ENDIF, WHILE … ENDWHILE, REPEAT … UNTIL, FOR … NEXT
Input / outputGet Mark, Display "Total is ", Total
AssignTotal = 0 (the NESA samples also use Set number = …)
SelectionIF Mark >= 50 THEN … (relational: = <> < > <= >=; logical: AND OR NOT)
Many branchesELSEIF chain, or CASEWHERE x evaluates to … / OTHERWISE / END CASE (NESA accepts both for the 2025 Q17 style)
LoopsWHILE tests before (may run 0 times); REPEAT…UNTIL tests after (runs at least once); FOR for a known count
SubroutineBEGIN Name (parameters) … RETURN value … END Name; the mainline calls it
LayoutIndent everything inside a structure, one statement per line

From NESA material “Keywords are in capitals; structural elements come in pairs; indent to show control structures” (course specifications). Reasoned Array notation is not fixed: 2025 Q17 uses Risks[index] starting at 0, and the familiarisation Q8 uses ItemArray(Index) starting at 1. Use the notation and start index the question uses.

Method (the course’s 5 steps, with detail)

  1. Read the question. Underline what it asks you to produce (display, return, store) and any limits. Course step 1
  2. Analyse the stimulus and list every requirement. Number them in the margin: each one is probably a mark. Note the input, the process, the output. Course step 2 From NESA material NESA feedback: use the stimulus to identify the structures needed.
  3. Plan the mainline. Decide the structures: a loop over an array? a selection with three outcomes? Decide whether any piece is a subroutine. Write the mainline first with calls only if you use subroutines. Course step 3
  4. Write the subroutines/body. Initialise variables before the loop (Total = 0). Put every structure’s closing word in as soon as you type the opening word. Course step 4
  5. Re-read and test with one example. Do a quick trace with a simple input and one boundary value (see the trace table method). Course step 5

Worked example 1: array sum and selection (2025 HSC Q17)

2025 HSC exam, Q17 · 3 marks

[Exact question wording is not published as a paper (online exam). Task as shown by the NESA marking guidelines/mapping grid: pseudocode RiskRating: the sample answer sums an array Risks of 10 values, then sets Rating to High if Total > 35, Low if Total < 20, otherwise Medium, and displays it]

Official marking criteria

  • 3 marks: Substantially correct pseudocode algorithm.
  • 2 marks: Addresses some aspects of the problem.
  • 1 mark: Some understanding of the problem or pseudocode.

NESA sample answer (NESA also accepts CASEWHERE or an IF/ELSEIF version)

BEGIN RiskRating
  Total = 0
  index = 0
  REPEAT
    Total = Total + Risks[index]
    index = index + 1
  UNTIL index = 10
  IF Total > 35 THEN
    Rating = "High"
  ELSE
    IF Total < 20 THEN
      Rating = "Low"
    ELSE
      Rating = "Medium"
    ENDIF
  ENDIF
  Display Rating
END RiskRating
(NESA also accepts a CASEWHERE version: CASEWHERE Total is  > 35: Rating = "High"  < 20: Rating = "Low"  OTHERWISE: Rating = "Medium"  END CASE; and an IF / ELSEIF / ELSE version.)

Notes

Marker feedback: use pseudocode control structures accurately; iterate an array and sum it; apply relational operators correctly; use the stimulus to choose the right structures.

Open this question page · some of the NESA wording or answer is an image or is unpublished, as noted

  1. Requirements (from the criteria): iterate the array, total it, compare with the thresholds, display a rating.
  2. Initialise: Total = 0 and index = 0 before the loop.
  3. Loop: REPEAT adds each element and moves index on; UNTIL index = 10 stops after 10 items (indexes 0 to 9).
  4. Selection: a nested IF (High above 35; Low below 20; otherwise Medium).
  5. Output: Display Rating after the structures close.

From NESA material 2025 marker feedback: use pseudocode control structures accurately; iterate an array and sum it; apply relational operators correctly.

Original practice Quick check: totals of 20 and 35 give “Medium”, because neither is below 20 nor above 35. This is why you test boundary values (I ran this to confirm).

Worked example 2: subroutines and RETURN (2025 sample Q14)

2025 NESA sample exam, Q14 · 3 marks

PseudoPizza sells custom-designed pizzas. The price of a small pizza is $10. Added costs: Medium size $2; Large size $4; each topping $1.50. An algorithm is needed to calculate the cost of pizzas ordered for a customer. The algorithm should calculate and display: the cost of each pizza; the total cost of the order. Write the algorithm using pseudocode. Include at least one subroutine in your answer. You may assume that all inputs are valid. (3 marks)

Official marking criteria

  • 3 marks: Substantially correct pseudocode that includes at least ONE subroutine.
  • 2 marks: Addresses some of the requirements.
  • 1 mark: Some understanding of the problem.

NESA sample answer

BEGIN main
     Get num_pizzas
     total_cost = 0
     FOR i = 1 TO num_pizzas
           Get pizza_size
           Get num_toppings
           cost_per_pizza = calculate_pizza_cost(pizza_size, num_toppings)
           DISPLAY cost_per_pizza
           total_cost = total_cost + cost_per_pizza
     NEXT i
     DISPLAY total_cost
END main

BEGIN calculate_pizza_cost(size, num_toppings)
     base_price = 10
     topping_price = 1.5
     IF size = "Medium" THEN
           base_price = base_price + 2
     ELSEIF size = "Large" THEN
           base_price = base_price + 4
     ENDIF
     pizza_cost = base_price + num_toppings * topping_price
     RETURN pizza_cost
END calculate_pizza_cost

Open this question page

From course notes A clean mainline that calls named subroutines is something the specifications ask for (see Mainline and subroutines (algorithms)).

Original practice A tiny original example of the structure (verified by tracing):

BEGIN Main
    FOR i = 1 TO 3
        Display Square (i)
    NEXT i
END Main

BEGIN Square (x)
    result = x * x
    RETURN result
END Square (x)

Output: 1, 4, 9. The mainline only calls; Square returns a value.

Worked example 3: fixing a linear search (2025 familiarisation Q8)

2025 NESA familiarisation exam, Q8 · 3 marks

[Question stem not available as text (it is on the interactive NESA familiarisation site). Task per the NESA mapping grid: modify a search algorithm so it achieves its intended purpose (find SearchItem in ItemArray and display its position, otherwise 'Not found')]

Official marking criteria

  • 3 marks: Correctly modifies the algorithm to achieve its intended purpose.
  • 2 marks: Corrects some mistakes.
  • 1 mark: Some understanding of the problem.

NESA sample answer

BEGIN Search (SearchItem)
    Set LastIndex to the number of elements in ItemArray
    Found = FALSE
    Index = 1
    WHILE Found = FALSE AND Index < LastIndex + 1
         IF ItemArray(Index) = SearchItem THEN
               Found = TRUE
         ENDIF
         Index = Index + 1
    ENDWHILE
    IF Found = TRUE THEN
         Display 'Position', Index - 1
    ELSE
         Display 'Not found'
    ENDIF
END Search

Notes

The original (buggy) algorithm is not available. Note the 'Index - 1' because Index is incremented after the item is found.

Open this question page · some of the NESA wording or answer is an image or is unpublished, as noted

From NESA material The sample note tells you why Index - 1 is displayed: Index is incremented after the item is found, so the position is one behind.

Original practice A complete search that follows this pattern (original reconstruction; the original buggy algorithm is not published):

BEGIN Search (SearchItem)
    Set LastIndex to the number of elements in ItemArray
    Found = FALSE
    Index = 1
    WHILE Found = FALSE AND Index < LastIndex + 1
        IF ItemArray(Index) = SearchItem THEN
            Found = TRUE
        ENDIF
        Index = Index + 1
    ENDWHILE
    IF Found = TRUE THEN
        Display 'Position', Index - 1
    ELSE
        Display 'Not found'
    ENDIF
END Search

Linear search pattern: Found flag, check each item until found or end. See Linear search pattern.

More patterns you should be able to write

Original practice All of these were traced by hand and run in Python to check the outputs.

Validation loop (REPEAT…UNTIL)

BEGIN GetMark
    REPEAT
        Display "Enter a mark from 0 to 100"
        Get Mark
        IF Mark < 0 OR Mark > 100 THEN
            Display "Invalid mark, try again"
        ENDIF
    UNTIL Mark >= 0 AND Mark <= 100
    Display "Mark accepted: ", Mark
END GetMark

Largest in an array (1 to 10)

BEGIN LargestScore
    Largest = Scores[1]
    FOR i = 2 TO 10
        IF Scores[i] > Largest THEN
            Largest = Scores[i]
        ENDIF
    NEXT i
    Display Largest
END LargestScore

Sum of the even numbers 1 to 20 (answer 110)

BEGIN EvenSum
    Total = 0
    FOR n = 1 TO 20
        IF n MOD 2 = 0 THEN
            Total = Total + n
        ENDIF
    NEXT n
    Display Total
END EvenSum

Choosing between three grades (IF/ELSEIF)

BEGIN Grade
    Get Mark
    IF Mark >= 80 THEN
        Grade = "H"
    ELSEIF Mark >= 50 THEN
        Grade = "P"
    ELSE
        Grade = "N"
    ENDIF
    Display Grade
END Grade

Common mistakes

  • From NESA material NESA 2025 Q17 feedback: use control structures accurately; apply relational operators correctly (> vs >=). Better responses used the stimulus to pick the structures.
  • General advice Forgetting to initialise Total = 0 or to add index = index + 1 inside a WHILE/REPEAT (infinite loop).
  • General advice Off-by-one: FOR i = 1 TO 10 over a 0-based array, or the other way. Check the first and last index.
  • General advice Missing the closing word (ENDIF, ENDWHILE, NEXT, END name).
  • General advice Writing Python (print(), :, ==) in a pseudocode question. Use Display, THEN, =.
  • General advice Using AND where OR is needed in a validation (Mark < 0 AND Mark > 100 can never be true).

Time per mark

Derived 1.75 minutes per mark on average gives about 5 minutes for a 3-mark pseudocode question. General advice Plan: 1 minute read and underline, 3 minutes write, 1 minute check.

Practice (4 items, with answers)

Item 1 · 2025 HSC Q17 style (original)

An array Marks[1..5] holds five marks. Write pseudocode that displays “Pass” if the average is 50 or more, otherwise “Fail”.

Show the answer
BEGIN Average
    Total = 0
    FOR i = 1 TO 5
        Total = Total + Marks[i]
    NEXT i
    Average = Total / 5
    IF Average >= 50 THEN
        Display "Pass"
    ELSE
        Display "Fail"
    ENDIF
END Average

Check: marks 40, 50, 60, 70, 80 → average 60 → Pass. Marks 10, 20, 30, 40, 50 → 30 → Fail. Markers look for: initialise, loop over all five, accumulate, divide, relational operator >=. Original practice

Item 2 · original: count the passes

Write pseudocode to count how many of the 10 values in Marks[1..10] are 50 or more and display the count.

Show the answer
BEGIN CountPasses
    Count = 0
    FOR i = 1 TO 10
        IF Marks[i] >= 50 THEN
            Count = Count + 1
        ENDIF
    NEXT i
    Display Count
END CountPasses

Original practice

Item 3 · original: read and say the output

What does this display?

BEGIN Mystery
    x = 3
    y = 0
    WHILE x > 0
        y = y + x * 2
        x = x - 1
    ENDWHILE
    Display y
END Mystery
Show the answer

12. Trace: x=3, y=0 → pass 1: y=6, x=2 → pass 2: y=10, x=1 → pass 3: y=12, x=0 → loop ends. Original practice (Checked by running it.)

Item 4 · original: write a function

Write a subroutine IsEven (n) that returns TRUE if n is even, otherwise FALSE, and a mainline that displays the result for 7.

Show the answer
BEGIN Main
    Display IsEven (7)
END Main

BEGIN IsEven (n)
    IF n MOD 2 = 0 THEN
        result = TRUE
    ELSE
        result = FALSE
    ENDIF
    RETURN result
END IsEven

Displays FALSE. Original practice

More: all past questions (filter to pseudocode), flashcards.

← How to answer matching and table-completion questionsHow to answer Python questions →