Question 1
A computer program stores data in an array named words.
The data in the array needs to be searched for a value that the user inputs.
One example of a searching algorithm is a binary search.
Identify the precondition for a binary search.
[1]
A second example of a searching algorithm is a linear search.
Describe how a linear search works.
[4]
The array words is defined as a global variable and contains these values:
The pseudocode function useWords() here uses the global array words.
The number of words in the array words is passed as a parameter.
Identify two variables in the function useWords().
[2]
numberOfWords is a parameter passed by value.
Describe the difference between passing a parameter by value and by reference.
[2]
Rewrite the function useWords() to use a while loop instead of a for loop.
The function header and close have been written for you.
Write your answer using pseudocode or program code.
function useWords(numberOfWords: byVal)
endfunction
[4]
Give one benefit and one drawback of declaring the array as a global variable instead of a local variable.
[2]
Describe one feature of an Integrated Development Environment (IDE) that can be used to help write the program and one feature that can be used to help test the program.
[4]
Functions and procedures are reusable components.
Give two benefits of writing a program with reusable components.
[2]