From what I understand, ConcurrentSkipListSet has an average complexity of O(log n) for insertion, search and removal of elements and a worst case of O(n). How about accessing the first and the last element? Is it any lower than log? I see that it retains a pointer to the head. Hence, I am guessing O(1) for the first element.
Yes, you are right about the head. => O(1)
However, when accessing the last one, you don't know which one it is, since after all it's a linked-list. Now because it is a skip-list you get O(log n) instead of processing all elements in linear time. Here you can look for a nil next pointer, but since you don't know which one to check it is still in O(log n).
There is a difference to note between real-measured time and asymptotic approximations!
Here is a possible depiction of it:

I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With