SkipList---Some Thoughts

first thing you should know about why we have skiplist, even though we already have so many data structures.
add, delete, insert, search, query are very important attributes of a data structure. and all data strutures are not the same in one way or another.
like array, for array, the insert might take O(n) and search can take O(n), if we want to delete item in given index, we also need O(n).
what about linkedlist? well, insert still takes O(n), and query and search takes O(n) as well. and if we want to delete a specific value, we still needs O(n).
if the items are sorted, if we use linkedlist to search ,the time complexity will still be O(n), in other words, the linkedlist data structure didn’t get smarter.
but, can we have a better way to improve the search efficient for linkedlist?
yes, we do. and that’s skiplist shows up. and it used time-space trade off technique.
we randomly leveled up some nodes. to have a better search efficient, O(logn), but in worst case, the time will still be O(n).
but what about insert and delete? since we made search quicker, so it’s faster for us to find the right spot to insert and delete.

so, in summary, the skiplist is essentially linkedlist(well, not just one, but many), but a linkedlist with a binary search function when all items are sorted.
refer: https://mp.weixin.qq.com/s/AGPCfFg7bEiCsa5zNeCi4A

posted @ 2020-04-26 12:50  EvanMeetTheWorld  阅读(12)  评论(0)    收藏  举报