Pergunta de entrevista da empresa Take-Two

Differentiate an array vs a linked list. How are they structured in memory? Which is faster based on access times? How do you add and remove elements from each one?

Resposta da entrevista

Sigiloso

1 de nov. de 2021

An array is a sequence stored in memory as a single "chunk" of data. It's contents can be easily accessed via indices and is the faster of the two. To add or remove data from an array you must restructure it with something like splice(). Linked lists are more of an abstract data structure that reference addresses in memory. Each node in a linked list is an object stored somewhere in the heap. The Head of the linked list is usually always accessible and must be used to traverse through the list and access other nodes. To add or remove data from a linked list you must access a neighboring node and change it's references to account for the new data. The new data must also point to the next node in the list if there is one.