Past questions › sdd2022-q28
2022 6 marks Extended response The Software Engineering Project (Year 12) Desk check and debugging an algorithm
NESA 2022 HSC Software Design and Development (OLD syllabus) - Section II Question 28, with NESA Marking Guidelines
An algorithm was designed to remove repeating consecutive characters in a phrase, replacing them with a single character. The algorithm: • allows input of a phrase • removes repeated characters • displays the shortened phrase. For example, if the input is ‘aaaabbbaa’ the output will be ‘aba’. Note: The function right (m, n) gets the last n characters of m. There are errors in the algorithm. 1 BEGIN Shorten 2 | input phrase 3 | phrase = phrase + “X” | ‘Adds an X to the end of phrase 4 | Len = number of characters in phrase 5 | NewPhrase = “ ” 6 | REPEAT 7 | done = FALSE 8 | NewPhrase = NewPhrase + 1st character of phrase 9 | REPEAT 10 | IF 1st character of phrase does not equal 2nd character of phrase THEN 11 | done = TRUE 12 | ENDIF 13 | Len = Len - 1 14 | phrase = right (phrase, Len) 15 | UNTIL done = TRUE 16 | UNTIL Len < 1 17 | output phrase 18 | phrase = NewPhrase 19 END Shorten (a) | Perform a desk check of the algorithm using dddg as input. | 3 (b) | Identify and correct any logic errors in the algorithm. You may refer to line | 3 numbers in your response.
Marking criteria
[Question 28 (a)] Criteria | Marks • Completes a substantially correct desk check | 3 • Completes a partially correct desk check | 2 • Shows some understanding of desk checking this algorithm | 1 Criteria | Marks • Correctly identifies two errors and changes the code | 3 • Identifies two errors or corrects one error | 2 • Show some understanding of the algorithm | 1
Sample answer
Sample answer: phrase | Len | NewPhrase | done | output dddg dddgX | 5 | "" | F d ddgX | 3 dgX | T gX | F dg T X | F dgX Error message? At this point the algorithm is trying to compare X with a character that doesn’t exist.
[Question 28 (b)] Sample answer: Line 16 becomes UNTIL Len < = 1. Swap lines 17 and 18.