Append: Big O Hazard
Suppose we want to make a list (0 1 ... n-1).
user=> (listofn 5) (0 1 2 3 4) (defn listofnb [n i answer] ; version 1 (if (< i n) (listofnb n (+ i 1) (append answer (list i)) ) answer)) (defn listofnb [n i answer] ; version 2 (if (< i n) (listofnb n (+ i 1) (cons i answer)) ; backwards (reverse answer))) ; fix backwards (defn listofn [n] (listofnb n 0 '() ) )
What is the Big O of each version?