Algorithms and Data Structures · Junior · Question 24 of 75
What is the cost of getting the k-th element of a linked list?
- 1O(log k)
- ✓Correct answer: O(k)
- 3O(1)
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).
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