Data Str & Algorithm HW Solutions 76

Data Str & Algorithm HW Solutions 76 - n nodes is 2...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
12 Lists and Arrays Revisited 12.1 Here is the f nal Skip List. head 2 5 20 25 26 30 31 +------> +--> +--> +--> +--> +--> +--> / +-----------> +-------> +--> / +-----------> +------------> / +--------------------------> / 12.2 For each even numbered node i , i can be written as j 2 k for the largest possi- ble integer k . For example, 8 is 1 2 3 and12is 3 2 2 . Each even numbered node j 2 k stores a pointer to ( j +1)2 k . This makes access time 2log n +1 in the worst case. Odd numbered nodes i can point to node i +2 to speed the search somewhat. 12.3 The average number of pointers for a Skip List with
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n nodes is 2 n (not count-ing the header). 12.4 template <class Key, class Elem, class KEComp, class EEComp> Elem SkipList::remove(Key K) { // Remove from Skip List SkipNode<Elem>* x = head; // Start at header node SkipNode<Elem>* update[level]; // Tracks level ends // Search for element prior to Value for(int i=level; i>=0; i--) { while((x->forward[i] != NULL) && (KEComp.gt(K, x->forward[i]->value))) x = x->forward[i]; 76...
View Full Document

This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.

Ask a homework question - tutors are online