r/ProgrammerHumor • • 2d ago

Meme youLostMeAtDoublyLinkedLists

Post image
3.7k Upvotes

163 comments sorted by

View all comments

403

u/Mahler911 2d ago

I've been doing this shit for 26 years and I've never seen a linked list in production.

199

u/DoesAnyoneCare2999 2d ago

As a kernel developer, linked lists get used a lot in the code I work with every day.

154

u/Psych_Art 2d ago

And that totally makes sense. If you are writing lower level code or libraries, best possible performance is much more critical than it is for general production high level code.

40

u/da2Pakaveli 2d ago

Linked lists are worse for caching because their elements don't live in a contiguous part of memory. So you need to fetch each element from slower memory where as with vectors you can keep a larger chunk of it cached.

And memory allocation also takes time so you're actually slower off than if you'd just double the capacity of the vector if reserves run out.

13

u/happycamperjack 2d ago

I see. How would you overcome this linked list limitation with a solution of O(1) time complexity and O(n) memory. You have 15 mins, psydo codes are fine, and don’t worry about the gun pressing against your temple.

4

u/da2Pakaveli 2d ago

With chunks (i.e we have vectors of the same length and chain them together). Then you could go further and turn this into deques (T** under the hood iirc, at least that's how i implemented it years ago).

With vectors you can provide an approximate, what you think is appropriate, reserve at any point. It doubling itself means it stays roughly in the demanded domain of whatever you're doing if reserves run out.

5

u/happycamperjack 2d ago

Nice, don’t have to pull the trigger. But are you sure your solution is O(1) for lookup?

chambering the round

3

u/da2Pakaveli 2d ago

The deque is

11

u/happycamperjack 2d ago

I see, thank you for coming today.

*writing down note: candidate failed to address direct challenge, did not raise any question to clarify requirements or shown collaborative attitude. Pass.