Pergunta de entrevista da empresa Meta

What are the pros and cons of a linked list vs. an array?

Resposta da entrevista

Sigiloso

22 de jan. de 2010

Linked List: pros: you can add elements to the list anywhere and it will be constant time, cuz you're just repointing nodes. cons: when searching for a value, you have to walk down every element in the list to find the one you want. Optimal use: when you have data that you think you'll change often Array: pros:grabbing values is constant time, so its fast cons: when adding values you have to recreate the the array, making it cost more if you're using data that needs to be changed often. Optimal use: when you are creating a list of values that you will never need to edit and need access to fast

1