3 ms·
They're both O(N). Pseudocode for the other way: 1. copy head of list consed with nil 2. copy next item consed with previous 3. goto 2 while next i
by chc 16y ago
They're both O(N). Pseudocode for the other way:
1. copy head of list consed with nil
2. copy next item consed with previous
3. goto 2 while next item is not nil
That's N*(cost of a copy and a cons). Granted, it's not as fast in absolute terms, but the slowdown is a constant factor. You're certainly not doing N operations on each item.