Question d’entretien chez Phunware

In which situation would you use linked list over an Array

Réponse à la question d'entretien

Utilisateur anonyme

28 sept. 2014

In a situation where no random access is needed and/or the number of items contained in the data structure frequently changes (add/delete). Now, being the case this question is asked in an interview, it is obvious (IMO) that what is intended is to know if the candidate knows & understands the conceptual/implementation difference between the two data structures: Arrays: items can be accessed by indexing, fixed memory allocated, if limit of array is reached, new memory needs to be allocated and all data copied to new structure. Linked Lists: cannot be indexed, you'd have to iterate through the list to find an item (direction of iteration depends whether is single or double linked list); adding / deleting items to the list is constant, no need to creating and copying whole data structure to allocate more elements in the list.