11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

518 Chap. 16 P<strong>at</strong>terns of <strong>Algorithm</strong>shead0525 30 31 42 58 62 69head(a)525 30 31 42 58 626901head(b)52530 31 42 58 6269012(c)Figure 16.2 Illustr<strong>at</strong>ion of the Skip List concept. (a) A simple linked list.(b) Augmenting the linked list with additional pointers <strong>at</strong> every other node. Tofind the node with key value 62, we visit the nodes with values 25, 31, 58, <strong>and</strong> 69,then we move from the node with key value 58 to the one with value 62. (c) Theideal Skip List, guaranteeing O(log n) search time. To find the node with keyvalue 62, we visit nodes in the order 31, 69, 58, then 69 again, <strong>and</strong> finally, 62./** Skiplist Search */public E find(Key searchKey) {SkipNode x = head;// Dummy header nodefor (int i=level; i>=0; i--) // For each level...while ((x.forward[i] != null) && // go forward(searchKey.compareTo(x.forward[i].key()) > 0))x = x.forward[i];// Go one last stepx = x.forward[0]; // Move to actual record, if it existsif ((x != null) && (searchKey.compareTo(x.key()) == 0))return x.element();// Got itelse return null;// Its not there}Figure 16.3 Implement<strong>at</strong>ion for the Skip List find function.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!