Algorithms and Data Structures · Junior · Question 25 of 75

Which operation is O(1) in a linked list but O(n) at the start of an array?

Explanation

Adding to the front of a list means creating a node and pointing it at the old head. In an array every element has to shift one position to make room (unshift).

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 25

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz