Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complexity of ConcurrentSkipListSet to access the first and the last elements

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.

like image 333
user592748 Avatar asked Dec 06 '25 09:12

user592748


1 Answers

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: Find last

I hope this helps.

like image 168
Dimitar Avatar answered Dec 08 '25 21:12

Dimitar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!