15 - Past Paper Simulation - Algorithms (I)

 1. Algorithms are very important in Computer Science.Define the term 'Algorithm' (1 mark)

 2. State, using the process used in the algorithm below, the username for Jonathan Peter (1 mark)
Start Process
INPUT firstname
INPUT secondname
name - LEFT(firstname,3)
OUTPUT username
END Process

Using the above algorithm, Ruth Marvin's
username would be RutMa

 3. Charles has written the following algorithm. Can you describe what it does. Mention both the input and the output. (2 marks)
INPUT num1
INPUT num2
IF num1 > num2 THEN
OUTPUT num1 + “is greater”
OUTPUT num2 + “is greater”

 4. Onkyakachi is busy programming a to-do app. He starts with this algorithm. If the user enters the number 7, what would the output be? (1 mark)
INPUT number
IF number == 0 THEN
OUTPUT “Monday”
ELSE-IF number == 1 THEN
OUTPUT “Tuesday”
ELSE-IF number == 2 THEN
OUTPUT “Wednesday”
ELSE-IF number == 3 THEN
OUTPUT “Thursday”
ELSE-IF number == 4 THEN
OUTPUT “Friday”
ELSE-IF number == 5 THEN
OUTPUT “Saturday”
ELSE-IF number == 6 THEN
OUTPUT “Sunday”

 5. Grace has created an online animal board game that uses a file to store the animals the program can select from. Sample data is shown below. The first two stages of the bubble sort have been done for you. Write the third (1 mark)
Cat  Bat  Fly  Vole  Newt  Lion

Original List: 
[Cat Bat Fly Vole Newt Lion]
Stage 1
[Bat Crime Fly Vole Newt Lion]
Stage 2
[Bat Crime Fly Newt Vole Lion]

 6. Given the following code, what would the output be if the user input was "rat"? (1 mark)
animals =["ant","horse","kuala","moose","owl","rat","turtle","whale","zebra"]
animal = input("Enter animal:")
for i in range(len(animals)):
  if animal==animals[i]:

 7. Blessing is deciding between a linear and binary search for the following list. Show the stages of a binary search to find the word "zebra" when applied to the data shown (4 marks)

 8. Explain why a binary search would not be suitable for the following list (1 mark)
random_numbers =[1,6,2,3,17,12,0,8]

 9. Describe the merge sort technique, naming one advantage and one disadvantage of this sorting method (4 marks)

 10. Complete the following trace table, using the algorithm on the left. What is the final output, given the inputs 8 and 2?