Download Dab

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
no text concepts found
Transcript
Assessment test
Unit 6 Algorithms
Name: ........................................................................... Class:.................. Mark:................
1.
(a) What is an algorithm?
[2]
(b) The following program simulates throwing two dice. What is the output from the
following program if:
[2]
(i)
die1 is 3, die2 is 4
(ii) die1 is 5, die2 is 5
1
Assessment test
Unit 6 Algorithms
(c) Rewrite the flowchart as a pseudocode 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.
[4]
(d) State the output if the user “throws” 3 times, getting 4 and 4, 3 and 3, 6 and 1 on the
three throws.
[1]
2
Assessment test
Unit 6 Algorithms
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]
(d) Give one advantage of the linear search method and one advantage of the binary
search method.
[2]
3
Assessment test
Unit 6 Algorithms
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?
[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
(c) Using an insertion sort, show the sequence the numbers are in after 1, 2 and
3 items have been examined and moved if necessary.
15
6
43
21
8
17
11
[3]
3
4
Assessment test
Unit 6 Algorithms
4.
Describe how merge sort works using the numbers below to illustrate the procedure.
Show each stage of the process.
46
27
[8]
33
21
18
28
43
13
5
Assessment test
Unit 6 Algorithms
5.
Write a pseudocode algorithm which does the following:
[7]
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 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
6
Assessment test
Unit 6 Algorithms
6.
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
……………………………………………………………………………………
4
password = input("Please enter password")
5
…………………………………………………………………………………………
6
7
passwordOK = True
else
8
print("password incorrect")
9
……………………………………………………………………………………
10
[4]
endif
11 endwhile
12 ……………………………………………………………………………………
13
print("Welcome back")
14 else
15
print("Contact administrator")
Lines 3, 5, 9 and 12 are missing from the algorithm above. Using four of the lines
of code below, complete this algorithm.
count = count + 1
if password == "AXcd35"
if password != "AXcd35"
while count < 3 AND NOT passwordOK
while count < 3 OR NOT passwordOK
if passwordOK
passwordOK == False
7
Assessment test
Unit 6 Algorithms
7.
Complete the trace table below to determine the output from the following algorithm:
[5]
total = 0
n = 1
while n < 6
if n mod 2 == 0
total = total + n
endif
n = n + 1
endwhile
print(total)
total
n
n mod 2
n<6
OUTPUT
[Total 50 Marks]
8
Related documents
Assessment Test - Can You Compute?
Assessment Test - Can You Compute?
Assessment Test Answers
Assessment Test Answers