Docsity

AQA A level computer science Exercise Algorithms, Exercises of Computer science

Toggle sidebar
bg1
Worksheet 1 Searching and sorting
Task 1
Use the 10 name cards for the activities in Task 1.
1. With the 10 name cards in a sequenced row, face down, search for the name Emily
Leave the cards you have examined face up.
Which card did you turn up first?
Which card did you turn up second?
Which card did you turn up third?
2. Turn the cards face down again.
Now search for the name Sophie
Which cards did you turn up? Write them in order.
What is the maximum number of cards you will need to find any given name?
What is the maximum number of items you will have to examine if the list contains
8 items?
16 items?
32 items?
37 items?
64 items?
2n items?
What is the time complexity of the binary search algorithm? Explain your answer.
3. The bubble sort algorithm is given below. Write the pseudocode statements for “swap the
names”.
FOR i = 1 to n
FOR j = 1 to(n - i)
IF numbers [j] > numbers[j + 1]
Temp = number [J]
numbers [J] = numbers[J+1]
numbers[J+1] = temp
ENDIF
ENDFOR
ENDFOR
1
pf3
pf4

Partial preview of the text

Download AQA A level computer science Exercise Algorithms and more Exercises Computer science in PDF only on Docsity!

Worksheet 1 Searching and sorting

Task 1

Use the 10 name cards for the activities in Task 1.

  1. With the 10 name cards in a sequenced row, face down, search for the name Emily Leave the cards you have examined face up. Which card did you turn up first? Which card did you turn up second? Which card did you turn up third?
  2. Turn the cards face down again. Now search for the name Sophie Which cards did you turn up? Write them in order. What is the maximum number of cards you will need to find any given name? What is the maximum number of items you will have to examine if the list contains  8 items?  16 items?  32 items?  37 items?  64 items?  2 n^ items? What is the time complexity of the binary search algorithm? Explain your answer.
  3. The bubble sort algorithm is given below. Write the pseudocode statements for “swap the names”. FOR i = 1 to n FOR j = 1 to(n - i) IF numbers [j] > numbers[j + 1] Temp = number [J] numbers [J] = numbers[J+1] numbers[J+1] = temp ENDIF ENDFOR ENDFOR

Task 2

A b c d e f g h i j k L m n o p q r s t u v w y x Use 8 name cards for the merge activity in Task 2.  Lay the cards out in a row, face up, in the following unsorted order: Jessica Ava Olivia Sophia^ Poppy Isla Lily Amelia  Read a card from each pair and write the lower value name to the merged list of 2 items  Then write the other value to the merged list  Do this for each pair  Fill in the names below. The first two pairs have been done for you. Ava Jessica^ Olivia^ Sophia Isla Poppy Amelia Lily  You are now merging Ava, Jessica, Olivia, Sophia.  Pick up the fist card from each list, Ava and Olivia.  Compare, and move Ava to the new merged list  Pick up another card (Jessica) form the same sublist as Ava  Compare Jessica with Olivia  Move Jessica to new merged list  Olivia and Sophie are in the correct sequence so write them to the merged list.  Merge the second sublist in the same way. Fill in the boxes below  Finally merge the two remaining lists in the same way.  Fill in the boxes below Binary search Amelia Ava Isha Jessica Lily Olivia poppy sophie Ava Jessica^ Olivia^ Sophia^ Amelia Isha^ Lily Poppy