AQA A-Level Computer Science AS Paper 1, June 2025: Question 3

10 marks · Medium difficulty · Programming

Implement a palindrome-checking algorithm given in pseudo-code into program code, test it with provided test data, and state one reason why the algorithm is inefficient.

Practise this question

Question

Question 03 presents Figure 5 showing pseudo-code for a palindrome-checking program using nested iteration. A WHILE loop checks that string S is not equal to 'x', prompts for user input, computes Max as the length of S minus 1, and initializes Matched to True. A FOR loop from index 0 to Max compares Letter1 at S[i] and Letter2 at S[Max - i], setting Matched to False if they differ. Afterwards, it outputs 'Palindrome' if Matched is True, else 'Not a palindrome'. Students are tasked in 03.1 (8 marks) to implement this algorithm in code, in 03.2 (1 mark) to provide a screenshot testing the strings 'madam', 'maam', 'adam', 'aam', and 'x', and in 03.3 (1 mark) to state one reason why the algorithm is not efficient.
Question text

03 Figure 5 shows an algorithm represented using pseudo-code.

Figure 5

S ← ""

WHILE S ≠ "x"

OUTPUT "Enter a word or phrase: "

INPUT S

Max ← LENGTH(S) – 1

Matched ← True

FOR i ← 0 TO Max

Letter1 ← S[i]

Letter2 ← S[Max - i]

IF Letter1 ≠ Letter2 THEN

Matched ← False

ENDIF

ENDFOR

IF Matched = True THEN

OUTPUT "Palindrome"

ELSE

OUTPUT "Not a palindrome"

ENDIF

ENDWHILE

The strings are zero index based. For example, the character with index 0 in the5

string "ABCD" is "A".

What you need to do:

Task 1

Write a program to implement the algorithm in Figure 5.

Task 2

Test that your program works:

• run your program

• enter madam

• enter maam

• enter adam

• enter aam

• enter x

Evidence that you need to provide

Include the following evidence in your Electronic Answer Document.

03.1 Your PROGRAM SOURCE CODE for Task 1.

[8 marks]

03.2 SCREEN CAPTURE(S) showing the test described in Task 2.

[1 mark]

03.3 State one reason why the algorithm in Figure 5 is not efficient.

[1 mark]

Mark scheme

Show the mark scheme Mark scheme for Question 03 showing marking points for 03.1 across 8 criteria (variable declarations, while loop, input prompt, max calculation, for loop range, character comparison if statement, setting matched to false, and final palindrome output check), alongside sample solutions in VB.Net and C#. Subpart 03.2 requires a screen capture matching the test data with outputs. Subpart 03.3 awards 1 mark for stating that unnecessary comparisons are made (e.g. comparing characters twice or continuing the loop after Matched becomes false).

03 1 8 marks for AO3 (programming) 8

Mark as follows:

1. Correct variable declarations for S, Max, Matched, i, Letter1, Letter2;

I. case

Note to examiners:

If a language allows variables to be used without explicit declaration, (eg Python), then

this mark should be awarded if the correct variables exist in the program code and the

first value they are assigned is of the correct data type.

2. Correct WHILE loop syntax allowed by the programming language and correct

condition;

3. Correct prompt "Enter a word or phrase: " and S assigned value entered

by user;

I. case

4. Correct calculation of Max;

5. FOR loop iterates correct number of times;

6. Correct IF THEN statement syntax allowed by the programming language and

correct condition within FOR loop; R. if inappropriate values for Letter1 or

Letter2

7. Correct assignment to Matched in THEN part;

8. Correct IF THEN ELSE statement syntax allowed by the programming language

and correct condition after FOR loop and correct output; I. case, spelling, spacing

Max 7 if code does not function correctly

03 2 Mark is for AO3 (evaluate) 1

**** SCREEN CAPTURE ****

Must match code from 03.1.

Code for 03.1 must be sensible.

Screen capture showing:

Enter a word or phrase: madam

Palindrome

Enter a word or phrase: maam

Palindrome

Enter a word or phrase: adam

Not a palindrome

Enter a word or phrase: aam

Not a palindrome – – –

Enter a word or phrase: x

Palindrome

03 3 Mark is for AO3 (evaluate) 1

Algorithm makes unnecessary comparisons // by example: eg first and last letters

compared twice;

The loop continues to iterate after it has been identified that a word is not a palindrome;

The loop continues to iterate after Matched has been set to False;

– – – 7

Max 1

VB.Net

0043 11 SubMark is for AO1 (knowledge)Main() 81

Dim S As String = ""

A namedDimLetter1,/callableLetter2(out of line) block of code (that may be executed by writing the nameAsChar

in a program statement);DimMaxAsInteger

Dim Matched As Boolean ' MP1

While S <> "x" ' MP2

04 2 3 marks for AO1 (understanding)Console.Write("Enteraword or phrase: ") 3

S = Console.ReadLine() ' MP3

Easier to reMax=S.Length-use code; - 1 ' MP4

EasierMatchedto understand;=True

For i = 0 To Max ' MP5

Easier to debug/Letter1=update/S(i)maintain/test;

Easier to develop a solution // supports structured approach;Letter2=S(Max-i)

Less code // faster to develop a solution;IfLetter1<>Letter2Then ' MP6

Facilitates multiple programmers working on a program simultaneously;Matched=False'MP7

Reduces/eliminates sideEndIf-effects;

Next

A. enables use ofIfMatched=localTruevariables, which only use memory when subroutine is executingThen

Console.WriteLine("Palindrome")

Else

Max 3Console.WriteLine("Not a palindrome"–) ' MP8 – –

End If

End While

04 3 2 marks for AO1 (understanding)Console.ReadLine() 2

C# End Sub

Avoids the use of global variables // makes subroutines self-contained/encapsulated;

03 1 stringMakes it easier to use the subroutines=""; with different values/expressions/variables; 8

intMakes it easier to reuse the subroutine in a different program;max=0;

boolMakes it easier to test the subroutine independently of the rest of the program;matched=true;

stringMakes it clearer which values from outside the subroutine are being used inside theletter1="";

stringsubroutine (as they are explicitly listed);letter2="";//MP1

while (s != "x") // MP2

{

Max 2Console.Write("Enter a word or phrase: ");

s = Console.ReadLine(); // MP3

max = s.Length - 1; // MP4

matched = true;

for (int i = 0; i <= max; i++) // MP5

05 Mark is for AO1 (understanding){ 1

letter1 = s[i].ToString();

(The detail of) how the data are (actually) represented is hidden;letter2=s[max-i].ToString();

New kinds of data objects/structures can be constructed from previously defined typesif(letter1!=letter2)//MP6

(of data objects);{

By example (eg stack/queue/tree implemented as an array);matched=false;//MP7

}

}

Max 1if(matched == true)

{

Console.WriteLine("Palindrome");

}

else

{

Console.WriteLine("Not a Palindrome"); // MP8

}

}

How to answer it

Palindrome Algorithm Implementation & Evaluation

AQA AS Computer Science • Paper 1 • Question 03

What this question tests

Translating pseudocode into high-level programming language code (Python, VB.Net, C#), maintaining correct syntax for conditional loops ( WHILE ), counted loops ( FOR ), zero-indexed string slicing, boolean tracking, capturing test run evidence, and critically evaluating algorithm time-efficiency (redundant comparisons).

Question 03.1

Implementing the Palindrome Algorithm in Program Code [8 Marks]

✅ Model Implementations

Python 3: s = "" while s != "x" : s = input ( "Enter a word or phrase: " ) max_val = len (s) - 1 matched = True for i in range (0, max_val + 1): letter1 = s[i] letter2 = s[max_val - i] if letter1 != letter2: matched = False if matched == True : print ( "Palindrome" ) else : print ( "Not a palindrome" ) C# / VB.Net Key Syntax:

Remember to declare variables explicitly (e.g. string s , int max , bool matched , char letter1, letter2 ) before using them.

💡 Mark Scheme Breakdown (8 Marks)

  • MP1: Correct variable declarations for S , Max , Matched , i , Letter1 , Letter2 (awarded in Python if correctly typed upon first assignment).
  • MP2: Correct WHILE loop syntax and condition ( S != "x" ).
  • MP3: Correct user prompt string & reading input into S .
  • MP4: Correct calculation: Max ← LENGTH(S) - 1 .
  • MP5: FOR loop iterates the exact correct number of times ( 0 to Max ).
  • MP6: Correct IF statement comparing characters at index i and Max - i .
  • MP7: Correct boolean assignment Matched ← False inside the loop branch.
  • MP8: Final IF...ELSE correctly branches output to "Palindrome" vs "Not a palindrome" .

🧠 Exam Technique: Exact Translation

  • Python Range Trap: In Python, range(start, stop) is exclusive of the upper limit! Writing range(0, max_val) stops at max_val - 1 . You must write range(0, max_val + 1) or range(len(s)) .
  • Don't "optimise" early: Implement the algorithm exactly as written in Figure 5, even if you notice it is inefficient. Marks are tied directly to pseudocode fidelity.
  • Functional penalty: The mark scheme limits you to a maximum of 7 marks if your code does not run correctly. Always dry-run test cases!

❌ Common Errors

  • String Index Out of Range: Using LENGTH(S) instead of LENGTH(S) - 1 causes index errors because strings are 0-indexed.
  • Resetting the Flag: Adding an ELSE: Matched = True inside the loop. Once Matched becomes False , it must stay False !
  • Misspelling prompts or outputs: Case, punctuation, and spaces count. Copy "Enter a word or phrase: " and "Not a palindrome" exactly.

Question 03.2

Screen Capture Test Evidence [1 Mark]

✅ Expected Terminal Output

Enter a word or phrase: madam Palindrome Enter a word or phrase: maam Palindrome Enter a word or phrase: adam Not a palindrome Enter a word or phrase: aam Not a palindrome Enter a word or phrase: x Palindrome
Examiner Note: Note that entering x executes the loop body first, prints Palindrome (since a single character is identical forwards and backwards), and then terminates on the next WHILE check.

🧠 Top Exam Habit

  • Follow the exact input sequence given in the bullet points in Task 2.
  • Make sure the code in 03.1 matches the code that generated the screenshot. Inconsistent outputs lose the mark.
  • Capture the full terminal window clearly showing prompts, inputs, and outputs.

Question 03.3

Algorithm Efficiency Evaluation [1 Mark]

✅ Acceptable Answers (Give ANY one)

  • The algorithm makes unnecessary / redundant comparisons (e.g. comparing the first and last letters twice).
  • The loop continues iterating even after it has already been identified that the word is not a palindrome.
  • The loop continues iterating after Matched has been set to False .
  • The loop should only run up to Max // 2 (half the length of the string).

❌ Insufficient Answers

  • "It takes too long" / "It has too many loops" — Too vague; specify what redundant work the loop is doing.
  • "It uses a while loop" — The while loop is necessary to process multiple inputs until termination.

Topics

4.1 Fundamentals of programming · 4.4 Theory of computation · 4.1.1 Programming · 4.4.1 Abstraction and automation

Question and mark scheme from the AQA A-Level Computer Science examination, AS Paper 1, June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.