Docsity

Skip List: Insertion and Deletion Algorithms, Lecture notes of Data Structures and Algorithms

Partial preview of the text

Download Skip List: Insertion and Deletion Algorithms and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

  • (^) The skip list is initialized with a header node of level 0, whose forward pointer is set to null.
  • (^) The top item shows the value associated with the skip list node. The head node is special so has the value "Hd".
  • (^) Starting from level 0 of the head, we look for the first node whose pointer points to the largest key that is less than or equal to key:10 that we want to insert, and save it into a temporary update array at index level.
  • (^) If no such key exists because the pointer is null, then update array will contain the last node at that level.
  • (^) We save this highlighted node into our updated array since it will point to our new key: 10 if their height matches.
  • (^) The update array actually contains a pointer to a node but we display the value of the node it is pointing to. To continue the process, we reduce level by one or stop if there are no more levels.
  • (^) All of the pointers are now updated.
  • (^) Insert value 30, assuming randomLevel returns 1.
  • (^) The random depth of the node to be inserted is 1, so we must adjust the depth of the header node before inserting.
  • (^) Starting from level 1 of the head, we look for the first node whose pointer points to the largest key that is less than or equal to key:30 that we want to insert, and save it into a temporary update array at index level.
  • (^) If no such key exists because the pointer is null, then update array will contain the last node at that level.
  • (^) We compare 30 to the next record 10. If it is less, we move forward, else we save this value.
  • (^) We save this highlighted node into our updated array since it will point to our new key: 30 if their height matches.
  • (^) The update array actually contains a pointer to a node but we display the value of the node it is pointing to.
  • (^) To continue the process, we reduce level by one or stop if there are no more levels.
  • (^) All of the pointers are now updated.
  • (^) Insert value 20, assuming randomLevel returns 2.
  • (^) Starting from level 2 of the head, we look for the first node whose pointer points to the largest key that is less than or equal to key:20 that we want to insert, and save it into a temporary update array at index level.
  • (^) If no such key exists because the pointer is null, then update array will contain the last node at that level.
  • (^) We save this highlighted node into our updated array since it will point to our new key: 20 if their height matches.
  • (^) The update array actually contains a pointer to a node but we display the value of the node it is pointing to.
  • (^) To continue the process, we reduce level by one or stop if there are no more levels.