CS Q-Test 1
CS Q-Test 1
Write your answers in the spaces provided. Some questions must be answered with a cross in a
box . If you change your mind about an answer, put a line through the box and then mark your
new answer with a cross .
AA5 A B 16 A C 25 A D 32
(c) State the type of error that can be found in algorithms. [1]
…………………………………………………………………………………………
………………………………………………………………………………………….
(d) A binary search algorithm is used with this list to find the target value ‘b’.
abcdefghijk
Complete the table to show the three characters in the order that the algorithm would
compare them against the target value. [3]
(e) What is meant by ‘decomposition’? What are the benefits it provides for programmers? [4]
………………………………………………………………………………………………………
………………………………………………………………………………………………………
……………………………………………………………………………………………………....
………………………………………………………………………………………………………
(f) Algorithms can be designed using pseudocode or flowcharts. Then, they need to be translated
into code that a computing device can execute. The following Figure shows the pseudocode for
an algorithm.
0
-12
5
12
………………………………………………………………………………………………………
………………………………………………………………………………………………………
(g) Best case and worst case for search algorithms can be determined based on the number of
comparisons necessary to find the target item. Give the best case and worst case for a binary
search algorithm. [2]
Best case
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Worst case
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
2. (a) A car has many embedded systems. An embedded system processes binary numbers.
(i) The speed limit for some roads is 60 miles per hour. Convert the denary number 60 to 8-bit
binary. [2]
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
(ii) The car displays speed limits in denary. Convert the 8-bit binary number 0010 0011 to
denary. [2]
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
(b) A player earns a badge for every 100 questions they answer correctly, providing this includes
at least 10 hard questions or 30 medium questions. This can be expressed as (NQ >= 100) and
(HQ >= 10 or MQ >= 30). Complete the truth table. [10]
A A
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
(ii) IF day = ‘Saturday’ OR day = ‘Sunday’ THEN
SET alarm TO 11
ELSE
SET alarm TO 8
END IF
What does this algorithm do? [2]
………………………………………………………………………………………………………
………………………………………………………………………………………………………
3. (a) The following program uses a condition-controlled loop.
x = 15
y=0
while x > 0
y=y+1
x=x–y
endwhile
print(y)
Complete the trace table to test this program. [4]
x y Output
15 0
(b) Complete the truth table in the Figure for the Boolean statement P = NOT(A AND B) [4]
A B P
0 0
0 1
1 0
1 1
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
(d) A program uses a file to store a list of words that can be used in a game. A sample of this data
is shown in the following. Show the stages of a bubble sort when applied to data shown in the
following List. [4]
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
(e) Produce a written description of an algorithm for making a cup of coffee. It should start with
placing some coffee in container and end with ready for serve. For example, the algorithm could
start with ‘Prepare glasses, hot water, sugar and coffee’ and end with ‘stir’.
[4]
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
4. (a) Write a program with high level programming language which is studied in your lesson
that asks the user to enter a person’s age. The program should display a message indicating
whether the person is an infant, a child, a teenager, or an adult.
Following are the guidelines: [7]
• If the person is 1 year old or less, he or she is an infant.
• If the person is older than 1 year, but younger than 13 years, he or she is a child.
• If the person is at least 13 years old, but less than 20 years old, he or she is a teenager.
• If the person is at least 20 years old, he or she is an adult
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
(b) Draw flow chat diagram for above question (a). [7]
(c) There are three points to consider when deciding whether an algorithm is successful or not.
Explain Two points of these criteria. [4]
1……………………………………………………………………………………………………
………………………………………………………………………………………………………
2……………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Marking Scheme
1.e Decomposition is usually the first step in the problem-solving process. Once a problem has
been broken down and the sub-problems have been identified, algorithms can be developed to
solve each of them. Decomposition means that sub-problems can be worked on by different
teams at the same time. As smaller algorithms are developed for each sub-problem, it is easier to
spot and correct errors. When the algorithm is developed into a program, code can be used agai
1.g Best case: The item is the middle/median of the list (1). Worst case: The item is not in the list /
located at the point at which the final division could be made (1). Do not accept last/first item in the list.
2.d nested IF statement a nested IF statement consists of one or more IF statements placed inside each
other. A nested IF is used where there are more than two possible courses of action.
4.c ◼ Accuracy – it must lead to the expected outcome (e.g. create a route from Beijing to Shanghai).
◼ Efficiency – it must solve the problem in the shortest possible time, using as few computer
resources as possible.
4.d Algorithms and programs are closely related, but they are not the same. An algorithm is a detailed
design for a solution; a program is when that design is implemented.