Microsquishy has decided to re-implement their Exmell Spreadsheet using DrSwindle. You have been hired by Gill Bates to demonstrate to the US Government that Microsquishy programmers are incompetent and so the Government should cut them a break in their current anti-trust suit. Your analysis for the court will help show that the functions would be coded much better if only the Microsquishy programmers had attended Cornell. Here is their code:
; Extracts the nth element of a list x ; (first element is at position 0.) ; Assume the list is non-empty. (define (nth-elt x n) (if (= n 0) (head x) (nth-elt (tail x) (- n 1)))) ; Calculates the length of a list. (define (length x) (if (empty? x) 0 (+ 1 (length (tail x))))) ; Reverses a list x. (define (reverse x) (let ((len (length x))) ; rev-x contains elements [n-1,n-2,...,3,2,1,0] (define (iter n rev-x) (if (= n len) rev-x (iter (+ n 1) (cons (nth-elt x n) rev-x)))) (iter 0 empty)))
The users of Exmell report that it takes a really long time to reverse a list. So, you decide to show the court that the asymptotic performance of reverse is actually quite bad. To simplify your analysis, you break the report to the Government into pieces.