A string is a palindrome if it reads the same forwards as backwards. The following strings are examples of palindromes: "Racecar" "madam" "12344321" Upper-case and lower-case characters need to be treated the same. For example, 'A' is equivalent to 'a'.
- (a)A function IsPalindrome() will take a string parameter. The function will return TRUE if the string is a palindrome and will return FALSE if the string is not a palindrome. Write pseudocode for IsPalindrome().[7]
- (b)Strings may consist of several words separated by spaces. For example, the string "never odd or even" becomes a palindrome if the spaces are removed. The program flowchart represents an algorithm to produce a string OutString by removing all spaces from a string InString. [Figure 7.1] Complete the table by writing the text that should replace each of the labels B, C, D, F and G. Note: the text may be written as a pseudocode statement. Label | Text ---|--- A | Set OutString to "" B | C | D | E | Set Index to Index + 1 F | G |[4]
This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.
Mark scheme
Marking points from the official mark scheme (May/June 2022). The mark or mark type is shown in brackets.
- [7] (a) FUNCTION IsPalindrome(InString : STRING) RETURNS BOOLEAN
- [7] (a) DECLARE IsPal : BOOLEAN
- [7] (a) DECLARE Index, Num : INTEGER
- [7] (a) DECLARE CharA, CharB : CHAR
- [7] (a) IsPal ← TRUE
- [7] (a) Index ← 1
- [7] (a) Num ← INT(LENGTH(InString) / 2)
- [7] (a) WHILE Index <= Num AND IsPal = TRUE
- [7] (a) CharA ← MID(InString, Index, 1)
- [7] (a) CharB ← MID(InString, LENGTH(InString) - Index + 1, 1)
- [7] (a) IF UCASE(CharA) <> UCASE(CharB) THEN
- [7] (a) IsPal ← FALSE // RETURN FALSE
- [7] (a) ENDIF
- [7] (a) Index ← Index + 1
- [7] (a) ENDWHILE
- [7] (a) RETURN IsPal // RETURN TRUE
- [7] (a) ENDFUNCTION
- [7] (a) Mark as follows: 1 Functions header including parameter, ending and return type
- [7] (a) Mark as follows: 2 Calculation of number of pairs to match (length or half length)
- [7] (a) Mark as follows: 3 Loop for half or whole string
- [7] (a) Mark as follows: 4 ...Extracting characters to compare // create reverse string
- [7] (a) Mark as follows: 5 Convert characters to same case
- [7] (a) Mark as follows: 6 Check for_mismatch of characters inside loop / test for mismatch after loop for reversed string
- [7] (a) Mark as follows: 7 Returning Boolean in both cases
- [4] (b) Mark for each of: B
- [4] (b) Mark for each of: D
- [4] (b) Mark for each of: C
- [4] (b) Mark for each of: ...F and G
- [4] (b) Note: The mark for F and G is dependent on a reasonable attempt at C
- [4] (b) Label: B, Text: Is Index > LENGTH(InString)?
- [4] (b) Label: C, Text: Is MID (InString, Index, 1) = " "?
- [4] (b) Label: D, Text: Set OutString to OutString & MID(InString, Index, 1)
- [4] (b) Label: F, Text: YES
- [4] (b) Label: G, Text: NO
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →