{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

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

View Full Document Right 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 time of creation, the factory will take care of this thing. When we get this node from the factory, it has six next pointers. We will insert the new data item in it. Then in a loop, we will point all these next pointers to next nodes. We have already studied it in
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern