Exercise 1: Writing FindMin Pseudocode and Verifying It — Possible Solution ==================================================================== THE PSEUDOCODE ------------------------------ Following this chapter's own FindMax template exactly, only reversing the comparison direction: ALGORITHM FindMin(list) min_val <- list[0] FOR i <- 1 TO length(list) - 1 IF list[i] < min_val THEN min_val <- list[i] ENDIF ENDFOR RETURN min_val TRANSLATING TO WORKING CODE ------------------------------ def find_min(lst): min_val = lst[0] for i in range(1, len(lst)): if lst[i] < min_val: min_val = lst[i] return min_val VERIFYING AGAINST A TRUSTED REFERENCE ------------------------------ Run on [8, 3, 5, 1, 9, 2]: find_min(data) = 1 Python's own built-in min(data) = 1 Match: yes, exactly. WHY THIS CONFIRMS THE PSEUDOCODE IS CORRECT, NOT JUST PLAUSIBLE-LOOKING ------------------------------ Matching Python's own min() function - a separately implemented, independently trusted reference - is a genuine correctness check, the same discipline this chapter's own FindMax example used against Python's max(). Simply reading the pseudocode and judging that it "looks right" would not have caught a subtle logic error (for example, starting the loop at index 0 instead of 1, which would still often produce a correct-looking answer purely by comparing the first element to itself unnecessarily, without actually being provably correct pseudocode). WHY THIS WORKS AS AN ANSWER ------------------------------ The answer follows this chapter's own established notation precisely (only the comparison operator changes, exactly mirroring how the underlying algorithm itself only changes in that one respect), and verifies correctness against an independent trusted implementation rather than simply asserting the pseudocode is right by inspection.