Search code examples
algorithmdata-structureslinked-listlookupskip-lists

Why not use an array of pointers to optimize linked list but use skip list?


Recently I was learning about the skip list, and I've learned that it is designed to speed up the lookup of linked list. But I am wondering why not use a data structure which adds an array of pointers of all nodes based on the structure of the linked list ? For a list of 2^n nodes, if each levels we have half of the number of pointers of the lower level we will add 2^n-1 ponters, it's almost the same number of adding a list of pointers of each nodes, and at the same time it's O(1) to access by index.

There must be some reasons not to implement my idea, can anyone tell me?


Solution

  • A skip list offers average performance of O(log(n)) to read, insert, update and delete the element at any index.

    Your array of pointers idea offers average performance of O(1), O(n), O(1) and O(n) for the same operations. Admittedly with a good constant on the O(n) operations, but still that is how it scales.

    Both data structures are used in practice. They are just used for different situations.