{"id":1862,"date":"2019-01-06T12:00:00","date_gmt":"2019-01-06T11:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/skip-lists-and-how-they-work\/"},"modified":"2026-07-05T03:21:01","modified_gmt":"2026-07-05T01:21:01","slug":"skip-lists-and-how-they-work","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/skip-lists-and-how-they-work\/","title":{"rendered":"Skip Lists and How They Work"},"content":{"rendered":"<p>A skip list is an efficient data structure\u00a0 that arranges the elements in a list in such a way that the search and update takes O(nlogn) time on average. n is the number of items in the list.<\/p>\n<p>We would cover the following<\/p>\n<ol>\n<li><a href=\"#t1\">How Skip Lists Work<\/a><\/li>\n<li><a href=\"#t2\">Example of Skip List<\/a><\/li>\n<li><a href=\"#t3\">Skip List Traversal<\/a><\/li>\n<li><a href=\"#t4\">Skip List Implementation<\/a><\/li>\n<li><a href=\"#t5\">Other Data Structures Tutorials<\/a><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-394 aligncenter\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Introduction-to-Skip-Lists-300x161.jpg\" alt=\"\" width=\"300\" height=\"161\" \/><\/p>\n<h5><strong id=\"t1\">1. How Skip Lists Work<\/strong><\/h5>\n<p>First of all, we define a skip list S for a map M consists of a series of lists {S<sub>0<\/sub>, S<sub>1<\/sub>,\u00a0 S<sub>2<\/sub>, . . . , S<sub>h<\/sub>)<\/p>\n<p>Each list S<sub>i<\/sub> in the set maintains a subset of the elements of M which is sorted in increasing order of the keys. Additionally, each list S<sub>i<\/sub> also stores two special keys, denoted as -\u221e and +\u221e where\u00a0-\u221e is smaller than all possible keys that can be inserted in m and +\u221e is greater than all possible keys that can be inserted in M. Additionally, the sublists satisfy the following conditions:<\/p>\n<ul>\n<li>List S<sub>0<\/sub> contains every possible item that can be stored in the map M (plus\u00a0 -\u221e and +\u221e).<\/li>\n<li>For i = 1, . . . h-1, S<sub>i<\/sub> contains a randomly generated subset of the entries of Si-1<\/li>\n<li>Lists S<sub>h<\/sub> contains only\u00a0 -\u221e and +\u221e,<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t2\">2. Skip List Example<\/strong><\/h5>\n<p>An example of a skip list is given in Figure 1.0. In this skip lists 10 items are stored in addition to\u00a0-\u221e and +\u221e.\u00a0 S<sub>0<\/sub> is at the bottom of the lists with all the possible elements\u00a0 and as we move to the top of the list from S<sub>0<\/sub> to S<sub>h<\/sub>, we could see that the number of items gradually reduces such that S<sub>i+ 1<\/sub> &lt; S<sub>i<\/sub> and also S<sub>i+1<\/sub>\u00a0\u2282 S<sub>i<\/sub> (S<sub>i+1<\/sub> is a subset of S<sub>i<\/sub>)<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_393\" aria-describedby=\"caption-attachment-393\" style=\"width: 735px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-393 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Skip-Lists-1024x377.jpg\" alt=\"Skip list implementation\" width=\"735\" height=\"271\" \/><figcaption id=\"caption-attachment-393\" class=\"wp-caption-text\">Figure 1.0: An example of a skip lists that stores 10 entries and maintains 6 sublists: S<sub>0<\/sub> to S<sub>5<\/sub> and a height of 6<\/figcaption><\/figure>\n<p>The insertion into a skip list is such that entries into sublist S<sub>i+1<\/sub> is randomly chosen from the entries of Si with a probability of 1\/2.\u00a0\u00a0This means that the number entries of S<sub>1<\/sub> is expected to be n\/2. Similarly, the number of entries of S<sub>2<\/sub> is expected to be n\/4 and so on.<\/p>\n<p>Generally, you can expect the number of entries in Si to be 1\/2<sup>i<\/sup>.\u00a0 This would then mean that the expected height of the skip list would be log n.<\/p>\n<p>We can therefore visualize skip lists as a 2-dimensional set of positions arranged horizontally in levels and vertically in towers. Each level is a sublist S<sub>i<\/sub> and each tower is a position for storing similar entries across the lists from bottom to top as can be seen in Figure 1.0. Maybe you can take some time to understand how it works<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t3\">3. Skip Lists Traversal<\/strong><\/h5>\n<p>We can\u00a0 all the positions in skip list by using the following set of operations:<\/p>\n<ul>\n<li>next(p): returns the position following p on the same level<\/li>\n<li>prev(p): returns the position preceding\u00a0 p on the same level<\/li>\n<li>below(p): returns the position directly below p in the same tower<\/li>\n<li>above(p): returns the position directly above p in the same tower<\/li>\n<\/ul>\n<p>If however any of the operations mentioned above are carried out and the position does not exist, then the operation returns a null as a result<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t4\">4. Skip List Implementation<\/strong><\/h5>\n<p>You can implement a skip list using a linked structure that allows the four operations outlined above to each take constant time, O(1) given a skip list position p. Such linked list is a collection of doubly-linked list which of length h and\u00a0 are aligned at the towers. The towers are themselves also doubly-linked list.<\/p>\n<p>It is noteworthy that , in Java programming language, there is an implementation of the skip list data structure which is\u00a0 available in the ConcurrentSkipListMap class which provides method for get(), put() and remove, operations which are guaranteed to be performed at O(log n) times.<\/p>\n<p>Finally, The main advantage of the skip list is randomization, which makes them very simple and efficient.<\/p>\n<p>In the next lesson, we would then\u00a0 examine lookup and insertion into linked list.<\/p>\n<p>&nbsp;<\/p>\n<h5><strong id=\"t5\">Check these Data Structure and Algorithms Tutorials<\/strong><\/h5>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/skip-lists-and-how-they-work\/\">Skip Lists and How They Work<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/perfect-hashing\/\">Perfect Hashing \u2013 How it Works<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/hashing\/\">Linear Probing, Quadratic Probing and Double Hashing<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/hashing-with-open-addressing\/\">Hashing With Open Addressing<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/universal-hashing\/\">Universal Hashing<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/search-time-under-simple-uniform-hashing\/\">Search Time Under Simple Uniform Hashing<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/hash-tables-hashing-with-chaining\/\">Hash Tables \u2013 Hashing With Chaining<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/introduction-to-hash-tables-and-direct-addressing\/\">Introduction to Hash Tables and Direct Addressing<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/recurrences-in-divide-and-conquer-algorithm\/\">Recurrences in Divide and Conquer Algorithm<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/how-bloom-filters-work\/\">How Bloom Filters Work<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/cuckoo-hashing\/\">How Cuckoo Hashing Works<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/kindsonthegenius.com\/tempsite\/introduction-to-avl-trees-with-examples\/\">Introduction to AVL Trees (With Examples)<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A skip list is an efficient data structure\u00a0 that arranges the elements in a list in such a way that the search and update takes &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[35],"tags":[],"class_list":["post-1862","post","type-post","status-publish","format-standard","hentry","category-algorithms"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=1862"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1862\/revisions"}],"predecessor-version":[{"id":2031,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1862\/revisions\/2031"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}