Computational thinking: searching, sorting, ADTs and recursion – A Level Computer Science (9618)
19 questions · page 1 of 2 · Clear filters
Question text
9
(a) A stack has been implemented using pseudocode to store a maximum of 100 string items
using the global variables in the following table:
Initialisation
Identifier
Data type
Description
value
Base
INTEGER
0
pointer for the bottom of the stack
Top
INTEGER
‑1
pointer for the top of the stack
StackArray
STRING
[0:99]
1D array to implement the stack
Max
INTEGER
100
maximum number of items in the stack
The value of Top is incremented each time a data item is added to the stack and decremented
every time a data item is removed.
(i)
Complete the pseudocode for the function to remove a data item from the stack.
FUNCTION Pop() …
DECLARE DataItem : STRING
""
DataItem
IF … THEN
…
DataItem
…
Top
ELSE
"You cannot remove data; the stack is empty"
DataItem
ENDIF
…
ENDFUNCTION
[5]
(ii)
Write the pseudocode to output the data item removed from the stack with an appropriate
message.
…
… [1]
ĬÛú¾Ġ´íÈõÏĪÅĊÝùµĀ×
,
,
(b) A stack is used to implement recursion.
State the three essential features of recursion.
1 …
…
2 …
…
3 …
…
[3]
Question text
12 (a) A stack has been implemented using pseudocode to store a maximum of 100 string items
using the global variables in the following table:
Initialisation
Identifier
Data type
Description
value
Base
INTEGER
0
pointer for the bottom of the stack
Top
INTEGER
-1
pointer for the top of the stack
StackArray
STRING
[0:99]
1D array to implement the stack
Max
INTEGER
100
maximum number of items in the stack
The value of Top is incremented each time a data item is added to the stack and decremented
each time a data item is removed. If the stack is full, an appropriate error message is output.
(i)
Complete the pseudocode for the procedure to add a data item onto the stack.
PROCEDURE Push( … )
IF Top < Max – 1 THEN
Top ← …
… ← NewData
ELSE
OUTPUT …
ENDIF
ENDPROCEDURE
[4]
(ii)
Write pseudocode to input a new data item and add it to the stack using Push().
…
…
…
… [2]
(b) Explain the reasons why a stack is used when a recursive algorithm is executed.
…
…
…
…
…
… [3]
ĬÑĊ®Ġ´íÈõÏĪÅĊàû·Ā×
,
,
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
ĬÍĊ®Ġ´íÈõÏĪÅĊÝú¶Ą×
Question text
10 A stack, StackArray, is to be implemented using pseudocode, to store a maximum of 100 string
items in an appropriate array. Declarations are required so that the stack has a beginning, an end
and a maximum size. An array is also required to store the data.
(a) Write pseudocode to declare the variables, constant and array required to implement the
stack.
…
…
…
…
…
… [3]
(b) Write pseudocode for a procedure to initialise the top and bottom pointers of the stack to
appropriate values.
…
…
…
…
…
… [3]
ĬÙú¾Ġ´íÈõÏĪÅĊàù¶Ā×
Question text
11
Describe when the use of recursion would be beneficial and give an example.
Description …
…
…
…
Example …
…
[3]
Question text
2
A program stores 20 unique random integers between 0 and 100 (inclusive) in a 1D array that is
local to the main program.
(a) Write program code to declare the array local to the main program and store 20 unique
random numbers between 0 and 100 (inclusive) in the array.
Save your program as Question2_N25.
Copy and paste the program code into part 2(a) in the evidence document.
[3]
(b) The procedure PrintArray() takes an integer array as a parameter. The procedure outputs
the array contents on a single line with a space between each integer.
Write the program code for PrintArray()
Save your program.
Copy and paste the program code into part 2(b) in the evidence document.
[3]
(c) The function BubbleSort():
•
takes an integer array as a parameter
•
sorts the data into ascending order using a bubble sort
•
returns the sorted array.
The function needs to work for an array of any length.
Do not use an inbuilt sorting method.
Write program code for BubbleSort()
Save your program.
Copy and paste the program code into part 2(c) in the evidence document.
[5]
(d) (i)
The main program:
•
outputs the contents of the array using PrintArray()
•
sorts the array using BubbleSort()
•
outputs "Sorted"
•
outputs the contents of the sorted array using PrintArray()
Write program code for the main program.
Save your program.
Copy and paste the program code into part 2(d)(i) in the evidence document.
[3]
(ii)
Test your program.
Take a screenshot of the output(s).
Save your program.
Copy and paste the screenshot(s) into part 2(d)(ii) in the evidence document.
[1]
(e) The recursive function RecursiveBinarySearch() takes four parameters:
•
an integer array
•
the lower bound of the array
•
the upper bound of the array
•
the value to find in the array.
The recursive function performs a binary search to find the index of the value in the array.
The function returns the index of the value if it is found. The function returns –1 if the value is
not found.
Write program code for RecursiveBinarySearch()
Save your program.
Copy and paste the program code into part 2(e) in the evidence document.
[6]
(f)
(i)
The main program:
•
prompts the user to enter an integer
•
takes the integer as input
•
calls RecursiveBinarySearch() with the sorted array, appropriate lower bound,
appropriate upper bound and the user’s input as parameters
•
outputs "Not found" if the input is not within the array
•
outputs "Found at position" and the index if the input is within the array.
Write program code to amend the main program.
Save your program.
Copy and paste the program code into part 2(f)(i) in the evidence document.
[3]
(ii)
Test your program three times with each of the inputs described:
Test 1: the smallest number in the array
Test 2: the largest number in the array
Test 3: a number not in the array
Take a screenshot of each output.
Save your program.
Copy and paste the screenshot(s) into part 2(f)(ii) in the evidence document.
[2]
Question text
3
A program stores integers in ascending order in an ordered binary tree. The tree is implemented
as a 2D array.
Each node is stored with three values:
•
a pointer to the left node
•
the data
•
a pointer to the right node.
All null values are stored as –1
The binary tree can store up to 50 nodes.
Nodes cannot be deleted from the binary tree.
(a) The binary tree is stored as a global array with the identifier TreeArray. The left pointer, the
data and the right pointer of each node are initialised to –1
The global variable RootPointer stores the index of the root node in the tree, initialised to
–1
The global variable FreeNode stores the index of the next free node in the array, initialised
to 0
Write program code to declare and initialise TreeArray, RootPointer and FreeNode
Save your program as Question3_N25.
Copy and paste the program code into part 3(a) in the evidence document.
[3]
(b) The procedure AddNode():
•
takes an integer to store in the binary tree as a parameter
•
stores the parameter in the next free node in the array
•
finds the position to store the data in the tree by following the appropriate pointers
•
updates the pointer of the new node’s parent node.
The procedure outputs "The tree is full" if the parameter cannot be stored because
the tree is full.
Write program code for AddNode()
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[7]
(c) The text file TreeData.txt stores 50 integers. Each integer is on a new line in the file.
The main program reads each integer from the file and stores each integer in the binary tree
in the order they are read.
Write program code for the main program.
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
[4]
(d) The procedure WriteAllToFile() stores the content of TreeArray in a new text file with
the filename Tree.txt. The file Tree.txt is not provided.
Each node in TreeArray is stored on one line with a comma separating each value.
For example, the current contents of TreeArray are:
Index
0
1
2
0
–1
20
1
1
–1
30
–1
…
49
-1
-1
-1
After writing TreeArray to the text file, Tree.txt will contain:
–1,20,1
–1,30,–1
…
-1,-1,-1
Write program code for WriteAllToFile()
Include exception handling when writing to the file.
Save your program.
Copy and paste the program code into part 3(d) in the evidence document.
[5]
Amend the main program to call WriteAllToFile()
(e) (i)
Save your program.
Copy and paste the program code into part 3(e)(i) in the evidence document.
[1]
(ii)
Test your program.
Take a screenshot that shows all of the content stored in the file Tree.txt
In this screenshot you need to make sure the filename is visible.
Save your program.
Copy and paste the screenshot(s) into part 3(e)(ii) in the evidence document.
[1]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Question text
11
The following diagram shows an ordered binary tree.
Red
Green
Yellow
Blue
Orange
Violet
Indigo
(a) A linked list of nodes is used to store the data. Each node consists of a left pointer, the data
and a right pointer.
–1 is used to represent a null pointer.
Complete this linked list to represent the given binary tree.
RootPtr
LeftPtr
Data
RightPtr
Red
Green
–1
Blue
–1
[4]
ĬÑĊ®Ġ´íÈõÏĪÅĊàú·Ā×
,
,
(b) A user-defined record structure is used to store the nodes of the linked list in part (a).
Complete the diagram, using your answer for part (a).
RootPtr
Index
LeftPtr
Data
RightPtr
0
Red
0
Green
1
Yellow
2
Blue
3
Orange
4
Indigo
5
Violet
FreePtr
6
7
[4]
(c) The linked list in part (a) is implemented using a 1D array of records. Each record contains a
left pointer, data and a right pointer.
The following pseudocode represents a function that searches for an element in the array of
records BinTree. It returns the index of the record if the element is found, or it returns a null
pointer if the element is not found.
Complete the pseudocode for the function.
FUNCTION SearchTree(Item : STRING) …
…
NowPtr
WHILE NowPtr <> -1
IF … THEN
NowPtr
BinTree[NowPtr].LeftPtr
ELSE
IF BinTree[NowPtr].Data < Item THEN
…
ELSE
RETURN NowPtr
ENDIF
ENDIF
ENDWHILE
RETURN NowPtr
ENDFUNCTION
[4]
ĬÓĊ®Ġ´íÈõÏĪÅĊàü·Ā×
,
,
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
ĬÍĊ®Ġ´íÈõÏĪÅĊÝû¶Ą×
Question text
11
This binary tree shows an ordered list of integers.
25
4
36
1
16
64
9
49
(a) A linked list of nodes is used to store the data. Each node consists of a left pointer, the data
and a right pointer.
−1 is used to represent a null pointer.
Complete this linked list to represent the given binary tree organisation.
RootPtr
LeftPtr
Data RightPtr
25
4
–1
1
–1
[4]
ĬÑĊ®Ġ´íÈõÏĪÅĊàù¸Ā×
,
,
(b) A 2D array is used to store the nodes of the linked list in part (a).
Complete the diagram using your answer for part (a).
RootPtr
Index
LeftPtr
Data
RightPtr
0
25
0
4
1
36
2
1
3
16
4
64
5
9
FreePtr
6
49
7
8
[4]
(c) The linked list in part (a) is implemented using a 1D array of records. Each record contains a
left pointer, data and a right pointer.
The following pseudocode represents a function that searches for an element in the array of
records LinkList. It returns the index of the record if the element is found, or it returns a
null pointer if the element is not found.
Complete the pseudocode for the function.
FUNCTION SearchList(Item : INTEGER) …
−1
NullPtr
RootPtr
…
WHILE NowPtr <> NullPtr
IF LinkList[NowPtr].Data < Item THEN
NowPtr
LinkList[NowPtr].RightPtr
ELSE
IF … THEN
NowPtr
…
ELSE
RETURN NowPtr
ENDIF
ENDIF
ENDWHILE
RETURN NullPtr
ENDFUNCTION
[4]
ĬÓĊ®Ġ´íÈõÏĪÅĊàû¸Ā×
,
,
Permission to reproduce items where third‑party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer‑related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
ĬÍĊ®Ġ´íÈõÏĪÅĊÝüµĄ×
Question text
11
The following diagram shows an ordered binary tree.
Red
Green
Yellow
Blue
Orange
Violet
Indigo
(a) A linked list of nodes is used to store the data. Each node consists of a left pointer, the data
and a right pointer.
–1 is used to represent a null pointer.
Complete this linked list to represent the given binary tree.
RootPtr
LeftPtr
Data
RightPtr
Red
Green
–1
Blue
–1
[4]
ĬÑĊ®Ġ´íÈõÏĪÅĊßû·Ā×
,
,
(b) A user-defined record structure is used to store the nodes of the linked list in part (a).
Complete the diagram, using your answer for part (a).
RootPtr
Index
LeftPtr
Data
RightPtr
0
Red
0
Green
1
Yellow
2
Blue
3
Orange
4
Indigo
5
Violet
FreePtr
6
7
[4]
(c) The linked list in part (a) is implemented using a 1D array of records. Each record contains a
left pointer, data and a right pointer.
The following pseudocode represents a function that searches for an element in the array of
records BinTree. It returns the index of the record if the element is found, or it returns a null
pointer if the element is not found.
Complete the pseudocode for the function.
FUNCTION SearchTree(Item : STRING) …
…
NowPtr
WHILE NowPtr <> -1
IF … THEN
NowPtr
BinTree[NowPtr].LeftPtr
ELSE
IF BinTree[NowPtr].Data < Item THEN
…
ELSE
RETURN NowPtr
ENDIF
ENDIF
ENDWHILE
RETURN NowPtr
ENDFUNCTION
[4]
ĬÓĊ®Ġ´íÈõÏĪÅĊßù·Ā×
,
,
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
ĬÍĊ®Ġ´íÈõÏĪÅĊÞú¶Ą×
Question text
10 A stack is to be set up using the information in the table.
Identifier
Data type
Description
BasePointer
INTEGER
points to the bottom of the stack
TopPointer
INTEGER
points to the top of the stack
Stack
REAL
1D array to implement the stack
A constant, with identifier Capacity, limits the size of the stack to 25 items.
(a) Write the pseudocode for the required declarations.
…
…
…
…
…
… [3]
(b) Complete the pseudocode function Pop() to pop an item from Stack.
// popping an item from the stack
FUNCTION Pop() …
DECLARE Item : REAL
0
Item
… BasePointer THEN
…
Item
…
TopPointer
ELSE
OUTPUT "The stack is empty – error"
ENDIF
…
ENDFUNCTION
[5]
(c) Compare and contrast the queue and stack Abstract Data Types (ADT).
…
…
…
…
…
… [2]
Question text
9
(a) A stack Abstract Data Type (ADT) is to be implemented using pseudocode, with procedures
to initialise it and to push new items onto the stack.
A 1D array Stack stores the contents of the stack.
(i)
Study the pseudocode in part (a)(ii) and complete the table of identifiers by writing the
missing data types and descriptions.
Identifier
Data type
Description
BasePointer
TopPointer
Stack
REAL
[2]
(ii)
Complete the pseudocode.
CONSTANT MaxSize = 40
DECLARE BasePointer : INTEGER
DECLARE TopPointer : INTEGER
DECLARE Stack : ARRAY[1:40] OF REAL
// initialisation of stack
PROCEDURE Initialise()
…
1
…
0
ENDPROCEDURE
// push an item onto the stack
PROCEDURE Push(NewItem : REAL)
… MaxSize THEN
…
…
Stack[TopPointer]
ENDIF
ENDPROCEDURE
[5]
(b) Justify the use of a linked list instead of an array to implement a stack.
…
…
…
… [2]
(c) Explain how a compiler makes use of a stack when translating recursive programming code.
…
…
…
…
…
…
…
… [4]
Question text
1
This iterative pseudocode algorithm for the function IterativeVowels() takes a string as a
parameter and counts the number of lower-case vowels in this string.
The vowels are the letters a, e, i, o and u.
FUNCTION IterativeVowels(Value : STRING) RETURNS INTEGER
DECLARE Total : INTEGER
DECLARE LengthString : INTEGER
DECLARE FirstCharacter : CHAR
← 0
Total
← LENGTH(Value)
LengthString
← 0 TO LengthString - 1
FOR X
FirstCharacter ← MID(Value, 0, 1)
IF FirstCharacter = 'a' OR FirstCharacter = 'e' OR
FirstCharacter = 'i' OR FirstCharacter = 'o' OR
FirstCharacter = 'u' THEN
← Total + 1
Total
ENDIF
← MID(Value, 1, LENGTH(Value)-1)
Value
NEXT X
RETURN Total
ENDFUNCTION
The pseudocode function MID(X, Y, Z) returns Z number of characters from string X, starting
at the character in position Y. The first character in a string is in position 0, for example:
MID("computer", 0, 3) returns "com"
The pseudocode function LENGTH(X) returns the number of characters in the string X, for
example:
LENGTH("computer") returns 8
(a) (i)
Write program code for the function IterativeVowels().
Save your program as Question1_N23.
Copy and paste the program code into part 1(a)(i) in the evidence document.
[5]
(ii)
Write program code to call the function IterativeVowels() with the parameter
"house" from the main program.
Output the return value.
Save your program.
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[2]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 1(a)(iii) in the evidence document.
[1]
(b) (i)
Rewrite the function IterativeVowels() as a recursive function with the identifier
RecursiveVowels().
Save your program.
Copy and paste the program code into part 1(b)(i) in the evidence document.
[6]
(ii)
Write program code to call the function RecursiveVowels() with the parameter
"imagine" from the main program.
Output the return value.
Save your program.
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[1]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 1(b)(iii) in the evidence document.
[1]
Question text
2
An integer is said to be divisible by another integer if the result of the division is also an integer.
For example:
10 is divisible by 1, 2, 5 and 10:
•
10 ÷ 1 = 10
•
10 ÷ 2 = 5
•
10 ÷ 5 = 2
•
10 ÷ 10 = 1
10 is not divisible by 4:
•
10 ÷ 4 = 2.5
1, 2, 5 and 10 are said to be the divisors of 10.
The iterative function IterativeCalculate() totals all the divisors of its integer parameter and
returns this total.
Example 1: if the parameter is 10, the total will be 18 (1 + 2 + 5 + 10) .
Example 2: if the parameter is 4, the total will be 7 (1 + 2 + 4) .
A pseudocode algorithm for IterativeCalculate() is shown.
FUNCTION IterativeCalculate(Number : INTEGER) RETURNS INTEGER
DECLARE Total : Integer
DECLARE ToFind : Integer
← Number
ToFind
Total ← 0
WHILE Number <> 0
IF ToFind MODULUS Number = 0 THEN
← Total + Number
Total
ENDIF
← Number - 1
Number
ENDWHILE
RETURN Total
ENDFUNCTION
The operator MODULUS calculates the remainder when one number is divided by another.
(a) (i)
Write program code for IterativeCalculate().
Save your program as Question2_N23.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[5]
(ii)
Write program code to call IterativeCalculate() with 10 as the parameter and
output the return value.
Save your program.
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[2]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 2(a)(iii) in the evidence document.
[1]
(b) IterativeCalculate() has been rewritten as the recursive function RecursiveValue().
A pseudocode algorithm for RecursiveValue() is given. The function is incomplete.
FUNCTION RecursiveValue(Number : INTEGER, ToFind : INTEGER)
RETURNS INTEGER
IF Number = … THEN
RETURN 0
ELSE
IF ToFind … Number = 0 THEN
RETURN … + RecursiveValue(Number - 1, ToFind)
ELSE
… RecursiveValue(Number - 1, … )
ENDIF
ENDIF
ENDFUNCTION
(i)
Write program code for RecursiveValue().
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[7]
(ii)
Write program code to call RecursiveValue() with 50 as the first parameter and 50
as the second parameter and output the return value.
Save your program.
Copy and paste the program code into part 2(b)(ii) in the evidence document.
[1]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 2(b)(iii) in the evidence document.
[1]
Question text
12 (a) The array Names[0:99] is in alphabetical order.
Complete this pseudocode binary search algorithm.
← 0
Lower
…
←
Mid
0
←
Exit
FALSE
OUTPUT "Enter the name to be found "
INPUT Target
REPEAT
… THEN
OUTPUT Target, " does not exist"
←
Exit
TRUE
ENDIF
←
Mid
Lower + (Upper – Lower + 1) DIV 2
IF Names[Mid] < Target THEN
←
…
Lower
ENDIF
IF Names[Mid] > Target THEN
…
ENDIF
… THEN
OUTPUT Target, " was found at location ", Mid
←
Exit
TRUE
ENDIF
…
[6]
(b) Big O notation is used to classify efficiency of algorithms.
The Big O notation for time complexity in a binary search is O(log n).
(i)
State the Big O notation for time complexity of a linear search.
… [1]
(ii)
Describe the meaning of O(log n) as it applies to a binary search algorithm.
…
…
…
… [2]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Question text
11
A simplified linked list is used to store the names of flowers in alphabetical order. It is implemented
using two 1D arrays:
•
Flower stores the names of the flowers.
•
NextPointer stores the pointer to the next flower name in the list.
HeadPointer indicates the index of the first flower name in the linked list.
HeadPointer
6
When the end of the linked list is reached, the next pointer has the value of 0.
The following table shows the initial content of the arrays.
Index
Flower
NextPointer
1
Rose
7
2
Marigold
1
3
Foxglove
10
4
Iris
9
5
Daisy
3
6
Dahlia
5
7
Saxifrage
0
8
Lupin
2
9
Lily
8
10
Hydrangea
4
(a) Several flower names have been deleted from the linked list. These are crossed out in the
following table.
Complete the table to show the new values of HeadPointer and NextPointer to keep the
remaining flower names in alphabetical order.
HeadPointer
Index
Flower
NextPointer
1
Rose
2
Marigold
3
Foxglove
4
Iris
5
Daisy
6
Dahlia
7
Saxifrage
8
Lupin
9
Lily
10
Hydrangea
[3]
(b) Complete the pseudocode algorithm so that it achieves the following when applied to the
arrays:
•
The flower name is input.
•
The linked list is searched, in order, for the flower name.
•
If the flower name is found, an appropriate message is output to indicate it has been
found.
•
If the flower name is not found, an appropriate message is output to indicate it has not
been found.
•
The algorithm terminates when the next pointer value is 0.
HeadPointer
Pointer
0
Found
OUTPUT "Enter a flower name "
… .
… .
IF Flower[Pointer] = FlowerName THEN
Pointer
Found
0
Pointer
ELSE
… .
ENDIF
ENDWHILE
… .
OUTPUT Flower[Found], " is found"
ELSE
… .
ENDIF
[5]
(c) Explain how you could improve the simplified linked list structure.
…
…
…
… [2]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge