Linked List Interview Problem
Linked List Interview Problem
[Cueball is writing on a whiteboard with a blue pen with Ponytail looking over his shoulder. The text on the board is unreadable, but it is is written in blue above them. It is a piece of code and it reads:]
Ponytail: Hey.
[Caption beneath the panel:] Coding interview tip: Interviewers get really mad when you try to donate their linked lists to a technology museum.

This is another one of Randall's Tips , this time a Coding interview Tip.
In computer programming, a linked list is a type of data structure that stores data throughout memory accompanied with memory addresses of the next, and potentially previous data point, establishing a relative ordering for a collection of data. Several common software engineering interview questions involve manipulating or otherwise interacting with linked lists. Possibly because programmers in the current day rarely work with linked lists directly, Randall suggests that such structures belong in a "technology museum," and thinks it would be more beneficial to mankind to email the list to such a museum rather than perform any useful work with it.
A linked list is a way to store sequential data in computer memory. Each piece of data is stored with a pointer to the next piece. This makes it very easy to add new data in the middle, since only one existing pointer must change to point to the new data. The drawback of a naive implementation can be that finding data may require following the entire chain. Technical programming interviewers like to see if applicants are familiar with the structure and the computational complexity concept itself.
Linked lists are, historically, one of the two main data structures that represent sequential data, along with arrays. Unlike arrays, they have the theoretical advantage of O(1) insertions and deletions thanks to not needing to reallocate the entire structure, but have O(n) random access (see comparisons ). However, modern processors' cache structure favors data that are located next to each other, pre-fetching the adjacent items, and modern processors can perform bulk memory moves, making resize operations faster. Finally, using linked lists usually implies dynamic allocation of each list member as opposed to reserving memory for a bunch of items in a bulk and then using that memory once an item has to be added. Memory allocation tends to be slow on modern systems and adds overhead for managing the information, which byte is allocated for what item, which can be significant, particularly for smaller data items; many small allocations also tend to fragment memory, which can lead to it being wasted and unavailable to the app later, particularly in long-running processes such as web servers. These properties tend to make linked lists poorly suited for most system programming applications in which a programmer might write algorithms to manipulate data structures, instead of using existing libraries.
Modern programming languages usually provide abstractions (often named "array," "vector" or "list") which interact with the sequential data at the memory level, providing access to this data while using arrays, linked lists, hybrids of the aforementioned technologies, or other approaches, and the programmer doesn't necessarily need to care one way or another. Knowing the underlying concepts is still useful, however, when creating fast running code which scales well to large data, avoiding (e.g.) traversing the list over and over again, or performing particularly inefficient operations.
Cueball's code implements a routine whose name implies that it does a mundane task, specifically traversing a linked list, but in fact emails the contents of the list to a technology museum. This could reveal private data that might be stored in a linked list, such as bank account numbers, medical information, passwords, etc., and would thus be a terrible idea. This is why interviewers - presumably job interviewers - would "get really mad".
In the title text, a singly linked list contains pointers to traverse the list in only one direction; namely, from the head to the end. By contrast, each element in a doubly linked list contains pointers to both the "next" and "previous" elements, enabling traversal in either direction. Randall continues the implication that such lists are obsolete by implying that traversing such a list would be akin to time travel. Without the "previous element" pointers, Randall is concerned he would not be able to reverse the time travel, as he could not traverse the list in the reverse direction.
[Cueball is writing on a whiteboard with a blue pen with Ponytail looking over his shoulder. The text on the board is unreadable, but it is is written in blue above them. It is a piece of code and it reads:]
Ponytail: Hey.
[Caption beneath the panel:] Coding interview tip: Interviewers get really mad when you try to donate their linked lists to a technology museum.
