[go: up one dir, main page]

0% found this document useful (0 votes)
1K views8 pages

Compsci Topic 7 Assessment Test

This document contains an assessment test on algorithm design and problem solving consisting of 7 multiple choice questions. The test assesses concepts such as defining algorithms, writing pseudocode, sorting algorithms, validation checks, and the product development lifecycle. Key tasks assessed include rewriting flowcharts as pseudocode, linear searches, bubble sorts, and completing trace tables to determine program output.

Uploaded by

bold banana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views8 pages

Compsci Topic 7 Assessment Test

This document contains an assessment test on algorithm design and problem solving consisting of 7 multiple choice questions. The test assesses concepts such as defining algorithms, writing pseudocode, sorting algorithms, validation checks, and the product development lifecycle. Key tasks assessed include rewriting flowcharts as pseudocode, linear searches, bubble sorts, and completing trace tables to determine program output.

Uploaded by

bold banana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Assessment test

Unit 8 Algorithm design and problem solving

Name:............................................................................. Class:................... Mark:................

1. (a) Define the meaning of the term algorithm.

A logical process for solving a problem. It is usually written in pseudo code or in flow charts.

(b) The function RANDOM_INT(number1, number2) will find a random integer number
between number1 and number2. For example, RANDOM_INT(1,3) would give a random
number from the numbers 1, 2 or 3.
The following program simulates throwing two dice. What is the output from the
following program if:

Start

die1 ←
RANDOM_INT(1,6)

die2 ←
RANDOM_INT(1,6)

score ←
die1 + die 2

No
die1 = die2?

Yes

score ← score * 2

OUTPUT
score

Stop

1
Assessment test
Unit 8 Algorithm design and problem solving

(i) die1 is 3, die2 is 4?


Output is 7

(ii) die1 is 5, die2 is 5?

Output is 20

(c) Rewrite the flowchart as a pseudo-code algorithm, making the following alterations:
A player’s score is added to their total score after each throw. If the user throws
a ‘double’, their score for that throw is doubled, and they throw the dice again.
Their turn ends if die1 and die2 have different values after a throw. Output the total
score at the end of a turn.
TotalScore = 0
On = True

Die1 = Random (1,6)


Die2 = Random (1,6)

Score = Die1 + Die2

If Die1=Die2 Then
Score = Score*2
Endif

TotalScore = TotalScore + Score

If Die1<>Die2
On = False
Endif

(d) State the output if the user ‘throws’ 3 times, getting 4 and 4, 3 and 3, 6 and 1
on the three throws.
35

2
Assessment test
Unit 8 Algorithm design and problem solving

2. The following list of numbers is to be searched:


103, 118, 122, 134, 138, 149, 156, 159, 163, 171, 180, 193
(a) List the numbers that will be examined if a linear search is carried out to find the
number 138.
103 118 122 134 138

(b) The list of numbers is stored in an array as follows:


DECLARE Numbers : ARRAY[1,12] OF INTEGER
Numbers  [103, 118, 122, 134, 138, 149, 156, 159, 163,
171, 180, 193]
Create an algorithm in pseudocode that will ask the user for a number to search
for and then perform a linear search on the array named Numbers.

Num = input (“enter a number”)


Found = false

While Found=false
If Numbers == num then
Found=true
Endif
Endwhile

3
Assessment test
Unit 8 Algorithm design and problem solving

3. A sort is carried out on the following list of numbers.

15 6 43 21 8 17 11 3

(a) How many passes through the list will be required to sort the numbers into
ascending sequence using the bubble sort algorithm?
7

(b) Show how the numbers change after each comparison is made during the first pass,
and the position of the numbers after the first pass is complete. The first row is
completed for you.

6 15 43 21 8 17 11 3

6 15 21 43 8 17 11 3

6 15 21 8 43 17 11 3

6 15 21 8 17 43 11 3

6 15 21 8 17 11 43 3

6 15 21 8 17 11 3 43

4
Assessment test
Unit 8 Algorithm design and problem solving

4. An algorithm is to be made with the following features:


The algorithm asks the user to input an integer between 0 and 23, representing the hours in
a 24-hour clock, and accepts the user’s input, which you can assume will be valid.
The algorithm outputs the equivalent time in 12-hour clock format. For example:
If the user inputs 0, the output will be Midnight
If the user inputs 2, the output will be 2am
If the user inputs 12, the output will be Midday
If the user inputs 23, the output will be 11pm
(a) Write the algorithm using pseudocode.

Clock = input “enter a number between 0 and 23”

If clock = 0 then
Output (“midnight”)
Endif

If clock =2 then
Output (“2 am”)
Endif

If clock = 12 then
Output (“midday”)
Endif

If clock = 23 then
Output (“11pm”)
Endif

(b) As part of the testing stage of the program development life cycle, a series of tests
will be carried out. One type of test data will be boundary data. Explain, with an
appropriate example for this algorithm, the meaning of boundary data.
It is the data at each end of the range. One example would be 0.

5
Assessment test
Unit 8 Algorithm design and problem solving

5. Below is an incomplete algorithm which is intended to check the username and password
entered by a user.
1 passwordOK  False
2 count  0
3 WHILE count < 3 AND NOT passwordOK

4 OUTPUT "Please enter password"


5 INPUT password
6 IF password = "AXcd35" THEN
7 passwordOK  True
8 ELSE
9 OUTPUT "password incorrect"
10 count  count + 1
11 ENDIF
12 ENDWHILE
13 IF passwordOK THEN
14 OUTPUT "Welcome back"
15 ELSE
16 OUTPUT "Contact administrator"
17 ENDIF

(a) Lines 3, 6, 10 and 13 are missing from the algorithm above. Using four of the lines
of code below, complete this algorithm.
count  count + 1
IF password = "AXcd35" THEN
IF password <> "AXcd35" THEN
WHILE count < 3 AND NOT passwordOK
WHILE count < 3 OR NOT passwordOK
IF passwordOK THEN
passwordOK  False

(b) When a user creates a password, it needs to be between 8 and 15 characters


long. State the type of validation check that needs to be carried out to check
the password.
Length check

6
Assessment test
Unit 8 Algorithm design and problem solving

(c) Explain one other validation that could be made of a new password.
Type check to make sure all data is numerical. If it is a string or special character , data will
be rejected

6. Complete the trace table below to determine the output from the following algorithm:
total ← 0
n ← 1
WHILE n < 6
IF n MOD 2 = 0
total ← total + n
ENDIF
n ← n + 1
ENDWHILE
OUTPUT total

total n n MOD 2 n<6 OUTPUT

0 1 1 Yes

2 2 0 Yes

2 3 1 Yes

6 4 0 Yes

6 5 3 Yes

12 6 0 No 12

7. The product development lifecycle has four stages: analysis, design, coding and testing.
One task that happens in the design stage is decomposition.
Give three other tasks that may happen in the design stage.
Abstraction

Pattern recognition

Algorithms

7
Assessment test
Unit 8 Algorithm design and problem solving

[Total 50 Marks]

You might also like