## Introduction

Jump table is a data structure for storing a sorted list of elements with the help of a linked table hierarchy connected to a subsequence of elements. Jump table allows to handle item lookups in an efficient way. A jump table is a probabilistic data structure, which means that it skips several elements of the entire list, hence the name. We can think of a jump table as an extended version of a linked table. Similar to the way a linked table allows insertion, deletion and searching of elements, a jump table allows searching for elements, deleting elements from the list and inserting elements. It will contain a basic list with a set of elements that will maintain a linked hierarchy of subsequent elements.

## Syntax

There is no specific syntax for jumping tables, but it has an algorithm. Before examining the algorithm, we need to examine the types of basic jump table operations.

1. insertion operations: in jump tables, used to add a new node to a specific position in a specific situation
2. search operation: in jump table, used to search for a specific node
3. Delete operation: in a jump table, used to delete a node in a specific case

Let’s see how the jump table works in an algorithmic way.

## Insertion algorithm

Step 1: Determine the node level, since each element in the list is represented by a node, and randomly select the level of the node during insertion into the list

Step 2: Determine the level of the node according to the following steps

Step 3: Find the maximum level that is the upper limit of the level count in the jump table, which is determined by L(N)=logp/2N. This ensures that the random level will be greater than the maximum level

Step 4: Insert the next node starting from the highest level and compare the current node

Step 5: If the next node keypoint' is smaller than theinserted keypoint, then you can continue using the same level

Step 6: If next node key is greater than inserted key, then we need to store a pointer to the current node I and move down one level to continue the search.

## Search algorithm

Step 1: Because searching for an element is very similar to searching for a point to insert an element in the jump table.

Step 2: If the next node key is smaller than the search key, then we can move forward on the same level

Step 3: If the next node key is greater than the inserted key, then we need to store a pointer to the current node I and move down one level to continue the search.

Step 4: At the lowest level, if the next element of the rightmost element has a key equal to the searched key, then we have found the key, otherwise this is a failure.

## Deletion algorithm

Step 1: To delete any element, say k, first we need to locate the element in the jump table using the search algorithm.

Step 2: Once we have found the element using the search algorithm, the pointer rearrangement will remove the element from the list, just as we did in the single linked list.

Step 3: We need to rearrange the element next to the I not element k starting from the lowest level of the skip list.

Step 4: After removing the element, there may be a situation where there are no levels of the element, so we need to remove these levels by reducing the skip list levels.

Example: Skip Table in Java

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306   public class SkipListJava, V> implements Iterable { private int listsize; private double pb; protected static final Random randomGen = new Random(); protected static final double DEFAULT_PB = 0.5; private NodeKeyValue head; public SkipListJava() { this(DEFAULT_PB); } public SkipListJava(double pb) { this.head = new NodeKeyValue(null, null, 0); this.pb = pb; this.listsize = 0; } public V get(K key) { checkKeyValid(key); NodeKeyValue listnode = findNode(key); if (listnode.getKey().compareTo(key) == 0) return listnode.getValue(); else return null; } public void add(K key, V value) { checkKeyValid(key); NodeKeyValue listnode = findNode(key); if (listnode.getKey() != null && listnode.getKey().compareTo(key) == 0) { listnode.setValue(value); return; } NodeKeyValue newlistNode = new NodeKeyValue(key, value, listnode.getLevel()); horizontalInsertList(listnode, newlistNode); int curLevel = listnode.getLevel(); int headlistLevel = head.getLevel(); while (isBuildLevel()) { if (curLevel >= headlistLevel) { NodeKeyValue newHeadEle = new NodeKeyValue(null, null, headlistLevel + 1); verticalLink(newHeadEle, head); head = newHeadEle; headlistLevel = head.getLevel(); } while (listnode.getUp() == null) { listnode = listnode.getPrevious(); } listnode = listnode.getUp(); NodeKeyValue tmp = new NodeKeyValue(key, value, listnode.getLevel()); horizontalInsertList(listnode, tmp); verticalLink(tmp, newlistNode); newlistNode = tmp; curLevel++; } listsize++; } public void remove(K key) { checkKeyValid(key); NodeKeyValue listnode = findNode(key); if (listnode == null || listnode.getKey().compareTo(key) != 0) throw new NoSuchElementException("Key does not exist!"); while (listnode.getDownList() != null) listnode = listnode.getDownList(); NodeKeyValue previous = null; NodeKeyValue next = null; for (; listnode != null; listnode = listnode.getUp()) { previous = listnode.getPrevious(); next = listnode.getNext(); if (previous != null) previous.setNext(next); if (next != null) next.setPreviousVal(previous); } while (head.getNext() == null && head.getDownList() != null) { head = head.getDownList(); head.setUp(null); } listsize--; } public boolean contains(K key) { return get(key) != null; } public int listsize() { return listsize; } public boolean empty() { return listsize == 0; } protected NodeKeyValue findNode(K key) { NodeKeyValue listnode = head; NodeKeyValue next = null; NodeKeyValue down = null; K nodeKey = null; while (true) { next = listnode.getNext(); while (next != null && lessThanEqual(next.getKey(), key)) { listnode = next; next = listnode.getNext(); } nodeKey = listnode.getKey(); if (nodeKey != null && nodeKey.compareTo(key) == 0) break; down = listnode.getDownList(); if (down != null) { listnode = down; } else { break; } } return listnode; } protected void checkKeyValid(K key) { if (key == null) throw new IllegalArgumentException("Key must be not null!"); } protected boolean lessThanEqual(K a, K b) { return a.compareTo(b) <= 0; } protected boolean isBuildLevel() { return randomGen.nextDouble() < pb; } protected void horizontalInsertList(NodeKeyValue a, NodeKeyValue b) { b.setPreviousVal(a); b.setNext(a.getNext()); if (a.getNext() != null) a.getNext().setPreviousVal(b); a.setNext(b); } protected void verticalLink(NodeKeyValue a, NodeKeyValue b) { a.setDown(b); b.setUp(a); } @Override public String toString() { StringBuilder stringbuild = new StringBuilder(); NodeKeyValue listnode = head; while (listnode.getDownList() != null) listnode = listnode.getDownList(); while (listnode.getPrevious() != null) listnode = listnode.getPrevious(); if (listnode.getNext() != null) listnode = listnode.getNext(); while (listnode != null) { stringbuild.append(listnode.toString()).append("\n"); listnode = listnode.getNext(); } return stringbuild.toString(); } @Override public Iterator iterator() { return new SkipListIterator(head); } protected static class SkipListIterator, V> implements Iterator { private NodeKeyValue listnode; public SkipListIterator(NodeKeyValue listnode) { while (listnode.getDownList() != null) listnode = listnode.getDownList(); while (listnode.getPrevious() != null) listnode = listnode.getPrevious(); if (listnode.getNext() != null) listnode = listnode.getNext(); this.listnode = listnode; } @Override public boolean hasNext() { return this.listnode != null; } @Override public K next() { K result = listnode.getKey(); listnode = listnode.getNext(); return result; } @Override public void remove() { throw new UnsupportedOperationException(); } } protected static class NodeKeyValue, V> { private K key; private V value; private int skiplevel; private NodeKeyValue up, down, next, previous; public NodeKeyValue(K key, V value, int skiplevel) { this.key = key; this.value = value; this.skiplevel = skiplevel; } @Override public String toString() { StringBuilder stringbuild = new StringBuilder(); stringbuild.append("Node[") .append("key:"); if (this.key == null) stringbuild.append("None"); else stringbuild.append(this.key.toString()); stringbuild.append(", value:"); if (this.value == null) stringbuild.append("None"); else stringbuild.append(this.value.toString()); stringbuild.append("]"); return stringbuild.toString(); } public K getKey() { return key; } public void setKey(K key) { this.key = key; } public V getValue() { return value; } public void setValue(V value) { this.value = value; } public int getLevel() { return skiplevel; } public void setLevel(int skiplevel) { this.skiplevel = skiplevel; } public NodeKeyValue getUp() { return up; } public void setUp(NodeKeyValue up) { this.up = up; } public NodeKeyValue getDownList() { return down; } public void setDown(NodeKeyValue down) { this.down = down; } public NodeKeyValue getNext() { return next; } public void setNext(NodeKeyValue next) { this.next = next; } public NodeKeyValue getPrevious() { return previous; } public void setPreviousVal(NodeKeyValue previous) { this.previous = previous; } } public static void main(String[] args) { SkipListJava skip = new SkipListJava<>(); for (int i = 20; i < 35; i++) { skip.add(i, String.valueOf(i)); } System.out.println(skip); assert skip.listsize() == 10; int count = 0; for (Integer i : skip) assert i.equals(count++); skip.remove(23); System.out.println(skip); skip.remove(25); skip.remove(33); skip.remove(30); System.out.println(skip); skip.remove(28); skip.add(25, "25"); System.out.println(skip); assert skip.listsize() == 0; assert skip.empty(); } } 

### Summary

The concept of jump table is the same in any programming language and it is one of the main algorithms in data structures.