Write program code to declare the function Unknown().
Save your program as question 1.
Copy and paste the program code into part 1(a) in the evidence document.
Take a screenshot to show the output from part (b)(i).
Copy and paste the screenshot into part 1(b)(ii) in the evidence document.
Rewrite the function Unknown() as an iterative function, IterativeUnknown().
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
Take one or more screenshots to show the output of both functions for each set of parameters.
Copy and paste the screenshot(s) into part 1(d)(ii) in the evidence document.
Write program code to declare the function Unknown().
Save your program as question 1.
Copy and paste the program code into part 1(a) in the evidence document.
Take a screenshot to show the output from part (b)(i).
Copy and paste the screenshot into part 1(b)(ii) in the evidence document.
Rewrite the function Unknown() as an iterative function, IterativeUnknown().
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
Take one or more screenshots to show the output of both functions for each set of parameters.
Copy and paste the screenshot(s) into part 1(d)(ii) in the evidence document.
The following recursive pseudocode function searches the binary tree for a given value. If the value is found, the function must return the index of the value. If the value is not found, the function must return –1.
The function is incomplete. There are four incomplete statements.
FUNCTION SearchValue(Root : INTEGER,
ValueToFind : INTEGER) RETURNS INTEGER
IF Root = –1 THEN
RETURN –1
ELSE
IF ArrayNodes[Root, 1] = ValueToFind THEN
RETURN .......................................
ELSE
IF ArrayNodes[Root, 1] = –1 THEN
RETURN –1
ENDIF
ENDIF
ENDIF
IF ArrayNodes[Root, 1] ....................................... ValueToFind THEN
RETURN SearchValue(ArrayNodes[............, 0], ValueToFind)
ENDIF
IF ArrayNodes[Root, ............] < ValueToFind THEN
RETURN SearchValue(ArrayNodes[Root, 2], ValueToFind)
ENDIF
ENDFUNCTION
Write program code for the function SearchValue().
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
A post order traversal performs the following operation:
- visit the left node
- visit the right node
- output the root.
For example, in the following tree, the output would be: 3 9 25 60 50
An outline of the PostOrder() procedure is:
- If left node is not empty, make a recursive call with the left node as the root.
- If right node is not empty, make a recursive call with the right node as the root.
- Output the current root node.
The procedure PostOrder() takes the root node as a parameter.
Write program code for the procedure PostOrder().
Save your program.
Copy and paste the program code into part 3(d) in the evidence document.
Test your program.
Take a screenshot to show the output.
Copy and paste the screenshot into part 3(e)(ii) in the evidence document.
The following recursive pseudocode function searches the binary tree for a given value. If the value is found, the function must return the index of the value. If the value is not found, the function must return –1.
The function is incomplete. There are four incomplete statements.
FUNCTION SearchValue(Root : INTEGER,
ValueToFind : INTEGER) RETURNS INTEGER
IF Root = –1 THEN
RETURN –1
ELSE
IF ArrayNodes[Root, 1] = ValueToFind THEN
RETURN .......................................
ELSE
IF ArrayNodes[Root, 1] = –1 THEN
RETURN –1
ENDIF
ENDIF
ENDIF
IF ArrayNodes[Root, 1] ....................................... ValueToFind THEN
RETURN SearchValue(ArrayNodes[............, 0], ValueToFind)
ENDIF
IF ArrayNodes[Root, ............] < ValueToFind THEN
RETURN SearchValue(ArrayNodes[Root, 2], ValueToFind)
ENDIF
ENDFUNCTION
Write program code for the function SearchValue().
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
A post order traversal performs the following operation:
- visit the left node
- visit the right node
- output the root.
For example, in the following tree, the output would be: 3 9 25 60 50
An outline of the PostOrder() procedure is:
- If left node is not empty, make a recursive call with the left node as the root.
- If right node is not empty, make a recursive call with the right node as the root.
- Output the current root node.
The procedure PostOrder() takes the root node as a parameter.
Write program code for the procedure PostOrder().
Save your program.
Copy and paste the program code into part 3(d) in the evidence document.
Test your program.
Take a screenshot to show the output.
Copy and paste the screenshot into part 3(e)(ii) in the evidence document.
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.
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.
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.
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.
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.
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.
Write program code for RecursiveValue().
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
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.
The following recursive pseudocode function sorts the array into ascending order using an insertion sort and returns the sorted array.
DECLARE LastItem : INTEGER
DECLARE CheckItem : INTEGER
DECLARE LoopAgain : BOOLEAN
FUNCTION RecursiveInsertion(IntegerArray : ARRAY[] OF INTEGER,
NumberElements : INTEGER) RETURNS ARRAY[] OF INTEGER
IF NumberElements <= 1 THEN
RETURN IntegerArray
ELSE
CALL RecursiveInsertion(IntegerArray, NumberElements - 1)
LastItem ← IntegerArray[NumberElements - 1]
CheckItem ← NumberElements - 2
ENDIF
LoopAgain ← TRUE
IF CheckItem < 0 THEN
LoopAgain ← FALSE
ELSE
IF IntegerArray[CheckItem] < LastItem THEN
LoopAgain ← FALSE
ENDIF
ENDIF
WHILE LoopAgain
IntegerArray[CheckItem + 1] ← IntegerArray[CheckItem]
CheckItem ← CheckItem - 1
IF CheckItem < 0 THEN
LoopAgain ← FALSE
ELSE
IF IntegerArray[CheckItem] < LastItem THEN
LoopAgain ← FALSE
ENDIF
ENDIF
ENDWHILE
IntegerArray[CheckItem + 1] ← LastItem
RETURN IntegerArray
ENDFUNCTION
Write the program code for the pseudocode function RecursiveInsertion().
Save your program.
Copy and paste the program code into part 3(b)(i) in the evidence document.
Write program code for the recursive function BinarySearch().
Save your program.
Copy and paste the program code into part 3(d)(i) in the evidence document.
Write program code for the recursive function BinarySearch().
Save your program.
Copy and paste the program code into part 2(c)(i) in the evidence document.
In the main program, test the function BinarySearch() twice, outputting the returned value each time.
One test should be for a number that is in the first line of the array.
One test should be for a number that is not in the first line of the array.
Take a screenshot to show the output.
Copy and paste the screenshot into part 2(c)(ii) in the evidence document.
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.
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.
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.