Solution

ID: past-exam-of-the-mathematics-course-of-the-university-of-cambridge/2006/ia/paper-5/1/a/solution

Use the usual unit-cost model for Standard ML list constructors and fixed-size arithmetic. The input size in the list examples is the number of list elements, rather than the size of the integer entries. Inspecting only the first constructor has constant time complexity:
sml
fun firstOrZero [] = 0
  | firstOrZero (x :: _) = x;
No tail is traversed. The running time is .

New to topics? Read the docs here!