📄 The question’s wording & key points
Exercise 1 (a): Perform the following search operations and show each step clearly.
Use Linear Search to find the number 27 in the array:
[10, 5, 18, 27, 32, 40, 3, 9]
1Start at i = 0 — linear search can only walk from the beginning
2Compare DataSet[i] == id — equal means return i (found)
3Nothing matched → return -1 (not found)
Why does it work on an unsorted array? Linear search never looks at the order, it just checks element after element — so an unsorted array is fine (binary search is not, it needs sorted data).
Cost: 1 comparison in the best case, n comparisons in the worst and average case (n = 8) → time O(n), extra space O(1).
The courseware example: looking for 27 → compare 10, 5, 18, 27 in turn; the 4th one is equal → return 3.