Algorithms and Data Structures · Junior · Question 24 of 75

What is the cost of getting the k-th element of a linked list?

Explanation

There is no index: you have to start at the head and follow next k times. That's the main trade-off compared with arrays, where arr[k] is O(1).

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 24

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