Download Assessment Test - Can You Compute?

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Addition wikipedia , lookup

Factorization of polynomials over finite fields wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Assessment test
Unit 5 Algorithms
Assessment Test
1.
(a) What is an algorithm?
[2]
(b) The following program simulates throwing two dice. What is the output from the
following program if:
(i)
Die1 = 3, Die2 = 4
(ii)
Die1 = 5, Die2 =5
[2]
Start
Die1 = Random(1,6)
Die2 = Random(1,6)
Score =
Die1 + Die 2
No
Die1=Die2?
Yes
Score = Score*2
Output score
End
1
Assessment test
Unit 5 Algorithms
(c) Rewrite the flowchart as a pseudocode algorithm, making the following alterations:
If the user throws a “double”, they get another turn, and the score accumulates into a
total score. Their turn ends as soon as Die1 and Die2 have different values after a
“throw”. Print out the total score at the end of a turn.
[4]
(d) What is output if the user “throws” 3 times, getting 4 and 4, 3 and 3, 6 and 1 on the
three throws?
[1]
[9 marks]
2.
The following list of numbers is to be searched:
103, 118, 122, 134, 138, 149, 156, 159, 163, 171, 180, 193, 199
(a) List the numbers that will be examined if a linear search is carried out to find the
number 138.
[2]
(b) List the numbers that will be examined if a binary search is carried out to find the
number 138.
[2]
(c) Using a binary search, how many items will need to be examined to find the
number 199?
[1]
2
Assessment test
Unit 5 Algorithms
(d) Give one advantage of the linear search method and one advantage of the binary
search method.
[2]
[7 marks]
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 using the bubble
sort algorithm?
[1]
(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]
6
15
43
21
8
17
11
3
3
Assessment test
Unit 5 Algorithms
(c) Using an insertion sort, what sequence are the numbers in after 1, 2 and 3 items have
been moved?
[3]
15
6
43
21
8
17
11
3
[10 marks]
4.
Explain the principle of the merge sort, using the numbers below to illustrate the procedure.
Show each stage of the process.
46
27
[8 marks]
33
21
18
28
43
13
4
Assessment test
Unit 5 Algorithms
5.
Write a pseudocode algorithm which does the following:
Asks the user to input an integer between 0 and 23, representing the hours in a 24hour clock, and accepts the user’s input, which you can assume will be valid.
Outputs the equivalent time in 12 hour clock format. For example:
If the user inputs 0, the output will be 12am
If the user inputs 2, the output will be 2am
If the user inputs 12, the output will be 12pm
If the user inputs 23, the output will be 11pm
6.
[7 marks]
Below is an incomplete algorithm which is intended to check the username and password
entered by a user.
1 passwordOK = false
2 count = 1
3 password = input (Please enter password”)
4 …………………………………………………………………………………………
5
…………………………………………………………………………………………
6
passwordOK = True
7
else
8
print (“password incorrect”)
9
……………………………………………………………………………………
10
count = count + 1
11
endif
12 endwhile
13 ……………………………………………………………………………………
14
print (“Welcome back”)
15 else
16
print (“Contact administrator”)
5
Assessment test
Unit 5 Algorithms
Lines 4, 5, 9 and 13 are missing from the algorithm above. Using four of the lines
of code below, complete this algorithm.
[4 marks]
password = input (“Please re-enter password: ”)
if password == “AXcd35”
if password != “AXcd35”
while count < 3 OR passwordOK == False
while count < 3 OR passwordOK == False
if passwordOK == True
if passwordOK == False
7.
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
print(total)
[5 marks]
total
n
n mod 2
n<6
OUTPUT
[Total 50 Marks]
6