Re:Nth-to-Last Element in a Singly Linked List
by cperciva on Sunday January 31, 2010 @06:37PM
(#1091329)
That doesn't help significantly, since you only save the final O(k) dereferences. The situation (small k) where it's practical to allocate a ring buffer like this is exactly the situation where it isn't useful.
[ Parent
| on HN ]
Re:Nth-to-Last Element in a Singly Linked List
by extension on Sunday January 31, 2010 @08:02PM
(#1091474)
Actually, you're right, it's the larger values of k where this might make a difference. If the list items are scattered in memory, the cost of the buffer increases very slowly with k compared to the cost of hitting those extra k/2 items.