CS301-Lec41 handout - CS301 Data Structures Lecture No. 41...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS301 – Data Structures Lecture No. 41 _____________________________________________________________________ Data Structures Lecture No. 41 Reading Material Data Structures and Algorithm Analysis in C++ Chapter. 10 10.4.2 Summary Review Quad Node Performance of Skip Lists AVL Tree Hashing Examples of Hashing Review In the previous lecture, we studied three methods of skip list i.e. insert , find and remove and had their pictorial view. Working of these methods was also discussed. With the help of sketches, you must have some idea about the implementation of the extra pointer in the skip list. Let’s discuss its implementation. The skip list is as under: We have some nodes in this skip list. The data is present at 0, 1 st and 2 nd levels. The actual values are 12, 23, 34 and 45. The node 34 is present in three nodes. It is not necessary that we want to do the same in implementation. We need a structure with next pointers. Should we copy the data in the same way or not? Let’s have a look at the previous example: -∞ + ∞ S 0 S 1 S 2 S 3 -∞ + ∞ 45 12 23 34 -∞ + ∞ 34 -∞ + ∞ 23 34
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS301 – Data Structures Lecture No. 41 _____________________________________________________________________ Here, the data is 20, 26, 30, 40, 50, 57, 60. At the lowest level, we have a link list. A view of the node 26, node 40 and node 57 reveals that there is an extra next ‘pointer’. The head pointer is pointing to a node from where three pointers are pointing at different nodes. We have seen the implementation of link list. At the time of implementation, there is a data field and a next pointer in it. In case of doubly link list, we have a previous pointer too. If we add an extra pointer in the node, the above structure can be obtained. It is not necessary that every node contains maximum pointers. For example, in the case of node 26 and node 57, there are two next pointers and the node 40 has three next pointers. We will name this node as ‘TowerNode’. TowerNode will have an array of next pointers. With the help of this array of pointers, a node can have multiple pointers. Actual number of next pointers will be decided by the random procedure. We also need to define MAXLEVEL as an upper limit on number of levels in a node. Now we will see when this node is created. A node is created at a time of calling the insert method to insert some data in the list. At that occasion, a programmer flips the coin till the time he gets a tail. The number of heads represents the levels. Suppose we want to insert some data and there are heads for six times. Now you know how much next pointers are needed to insert which data. Now we will create a listNode from the TowerNode factory. We will ask the factory to allocate the place for six next pointers dynamically. Keep in mind that the next is an array for which we will allocate the memory dynamically. This is done just due to the fact that we may require different number of next pointers at different times. So at the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/21/2010 for the course CS CS301 taught by Professor Dr.naveed malik during the Spring '10 term at Virtual University of Pakistan.

Page1 / 10

CS301-Lec41 handout - CS301 Data Structures Lecture No. 41...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online