Six original Cambridge-style questions on linear search and bubble sort, with trace tables and pseudocode mark points.
Describe how a linear search finds a value in a 1D array.
Using the linear search in this lesson, Names holds Pia, Leo, Sam, Ada, Tia, Jon, Kai, Uma. State the final value of Index, the output and the number of comparisons when SearchName is (a) Jon (b) Zac.
Jon found at position 6; 6 comparisons. ✓Zac not found. ✓The improved bubble sort in this lesson is used on an array of 4 elements holding 7, 3, 9, 1 (with Top ← 4). Show the contents of the array after each pass and state how many passes are made.
IDs : ARRAY[1:100] OF STRING is a global array. Write pseudocode for a function FindID(SearchID : STRING) RETURNS INTEGER that uses a linear search and returns the index of SearchID, or −1 if it is not found.
ENDFUNCTION; local Index initialised to 1 and a flag (or a result variable) initialised. ✓IDs[Index] = SearchID; if equal set the flag / store the index. ✓RETURN Index if found, else RETURN -1. ✓Names : ARRAY[1:50] OF STRING holds 50 names. Write pseudocode for an efficient bubble sort that puts the names into alphabetical order and stops as soon as the names are sorted.
Top ← 50 (or a pass-length variable). ✓REPEAT ... UNTIL Swapped = FALSE OR Top = 1 (or a WHILE equivalent). ✓Swapped ← FALSE at the start of each pass. ✓FOR j ← 1 TO Top - 1 comparing Names[j] > Names[j + 1]. ✓Swapped ← TRUE. ✓Top ← Top - 1 after each pass. ✓An array of 10 integers is already in ascending order. Compare the number of comparisons made by (a) a simple bubble sort with two FOR loops from 1 to 9 and (b) the improved bubble sort. Explain the difference.
Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.