The algorithmic core of the entire practical syllabus — search, sort, and string manipulation algorithms you must be able to code from memory, not just describe.
Array searching algorithms:
| Algorithm | How it works | Requirement |
|---|---|---|
| Sequential (linear) search | Checks each element one by one from the start until found or the array ends | Works on any array, sorted or not |
| Binary search | Repeatedly checks the middle element and eliminates half the remaining array each time based on whether the target is higher or lower | Requires the array to already be SORTED |
Array sorting algorithms:
| Algorithm | How it works |
|---|---|
| Selection sort | Repeatedly finds the smallest (or largest) remaining unsorted element and swaps it into its correct position |
| Improved selection sort | Same idea, but avoids unnecessary swaps when the element is already in the correct position |
| Bubble sort | Repeatedly compares adjacent elements and swaps them if out of order, 'bubbling' the largest values to the end each pass |
| Bubble sort with a flag | Adds a Boolean flag that tracks whether any swap occurred in a pass — if no swaps happened, the array is already sorted and the algorithm can stop early (an execution efficiency improvement) |
Example
// Bubble sort with a flag boolean swapped; do { swapped = false; for (int i = 0; i < arr.length - 1; i++) { if (arr[i] > arr[i + 1]) { int temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; swapped = true; } } } while (swapped);
Other essential array operations: inserting an element (shifting later elements to make room), deleting an element (shifting later elements to close the gap), and removing duplicates — for both simple data types and arrays of objects (comparing relevant object fields instead of the whole object).
String manipulation algorithms:
Example
// Converting "Fred John Smith" to "FJ Smith" String[] parts = fullName.split(" "); String initials = ""; for (int i = 0; i < parts.length - 1; i++) { initials += parts[i].charAt(0); } String result = initials + " " + parts[parts.length - 1];
A key exam skill: identifying patterns in duplicated code to recognise where a reusable method with parameters would be more efficient than repeating similar logic multiple times (linking back to 11.4.1 and 11.4.6).
💡 Exam Tip
Binary search is the single most common 'explain why this fails' trap: it ONLY works correctly on a sorted array — if asked to debug a broken binary search, always check whether the array was sorted first.