News for hackers. Stuff that matters.
Re:Nth-to-Last Element in a Singly Linked List by DenisM on Sunday January 31, 2010 @02:11PM (#1090891)
It's not equally inefficient. The former will trash the CPU cache on large lists, whereas the latter will not if the k is small.
Re:Nth-to-Last Element in a Singly Linked List by cperciva on Sunday January 31, 2010 @02:32PM (#1090934)
True. But the author hadn't gotten to the point of counting operations yet, so I don't think he was trying to make a subtle point about memory hierarchies and non-constant access times. :-)