SKIP LIST IMPLEMENTATION (C++)
Described a Skip List implementation where every SkipNode had four pointers: up, down, prev, and next. Describe how we can insert into a Skip List where the SkipNode has only down and next pointers instead. You may assume, for this problem, that you will never flip a coin with enough heads in a row to increase the height of the Skip List.
Implementing the skip list data structure
![]() |
public class SkipListEntry
{
public String key;
public Integer value;
public SkipListEntry up; // up link
public SkipListEntry down; // down link
public SkipListEntry left; // left link
public SkipListEntry right; // right link
...
(methods)
}
|
Note:
|
|
public class SkipListEntry
{
public String key;
public Integer value;
public SkipListEntry up, down, left, right;
public static String negInf = "-oo"; // -inf key value
public static String posInf = "+oo"; // +inf key value
....
}
|
SkipListEntry x = new SkipListEntry( SkipListEntry.posInf, null ); |
How to check if an Skip List entry x contains +∞:
key == SkipListEntry.posInf |
OK, now we move on to the Skip list itself....
But.... It is never the less a list
|
public class SkipList
{
public SkipListEntry head; // First element of the top level
public SkipListEntry tail; // Last element of the top level
public int n; // number of entries in the Skip List
public int h; // Height
public Random r; // Coin toss
....
}
|
Note:
|
![]() |
Note:
|
![]() |
public SkipList() // Constructor...
{
SkipListEntry p1, p2;
/* -----------------------------------
Create an -oo and an +oo object
----------------------------------- */
p1 = new SkipListEntry(SkipListEntry.negInf, null);
p2 = new SkipListEntry(SkipListEntry.posInf, null);
/* --------------------------------------
Link the -oo and +oo object together
--------------------------------------- */
p1.right = p2;
p2.left = p1;
/* --------------------------------------
Initialize "head" and "tail"
--------------------------------------- */
head = p1;
tail = p2;
/* --------------------------------------
Other initializations
--------------------------------------- */
n = 0; // No entries in Skip List
h = 0; // Height is 0
r = new Random(); // Make random object to simulate coin toss
}
|
public class SkipList
{
public SkipListEntry head; // First element of the top level
public SkipListEntry tail; // Last element of the top level
public int n; // number of entries in the Skip List
public int h; // Height
public Random r; // Coin toss
public SkipList() // Constructor...
{
SkipListEntry p1, p2;
p1 = new SkipListEntry(SkipListEntry.negInf, null);
p2 = new SkipListEntry(SkipListEntry.posInf, null);
head = p1;
tail = p2;
p1.right = p2;
p2.left = p1;
n = 0;
h = 0;
r = new Random();
}
...
}
|
|
Notice that each basic operation must first find (search) the appropriate entry (using a key) before the operation can be completed.
So we must learn how to search a Skip List for a given key first....
![]() |
p = head;
repeat
{
Move to the right until your right neighbor node
contains a key that is greater than k
if ( not lowest level )
Drop down one level
else
exit
}
|
/* ------------------------------------------------------
findEntry(k): find the largest key x <= k
on the LOWEST level of the Skip List
------------------------------------------------------ */
public SkipListEntry findEntry(String k)
{
SkipListEntry p;
/* -----------------
Start at "head"
----------------- */
p = head;
while ( true )
{
/* ------------------------------------------------
Search RIGHT until you find a LARGER entry
E.g.: k = 34
10 ---> 20 ---> 30 ---> 40
^
|
p must stop here
p.right.key = 40
------------------------------------------------ */
while ( (p.right.key) != SkipListEntry.posInf &&
(p.right.key).compareTo(k) <= 0 )
{
p = p.right; // Move to right
}
/* ---------------------------------
Go down one level if you can...
--------------------------------- */
if ( p.down != null )
{
p = p.down; // Go downwards
}
else
{
break; // We reached the LOWEST level... Exit...
}
}
return(p); // Note: p.key <= k
}
|
|
/** Returns the value associated with a key. */
public Integer get (String k)
{
SkipListEntry p;
p = findEntry(k);
if ( k.equals( p.key ) )
return(p.value);
else
return(null);
}
|
put(k, v)
{
SkipListEntry p;
p = findEntry(k);
if ( k.equals( p.key ) ) // Found !
{
p.value = v; // Update the value |
SKIP LIST IMPLEMENTATION (C++) Described a Skip List implementation where every SkipNode had four pointers: up,...
at the back of ly deaths. About 58 million people die every year each day, on average? Wake-up call. Suppose you has a one-in-a-thousand the event you thought of in the morning the chances you will not experience your What are the chances you will pass an entire year without of these coincidences? About how many die 2. wake up each morning and chance of happening that day. think of an event that What are the will not that day7...
C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use to implement your program can have a profound impact on it's overall performance. A poorly written program will often need much more RAM and CPU time then a well-written implementation. One of the most basic data structure questions revolves around the difference between an array and a linked list. After you finish this assignment you should have a firm understanding of their operation. Problem...
c++ code
In mythology, the Hydra was a monster with many heads. Every time the hero chopped off a head, two smaller heads would grow in its place. Fortunately for the hero, If the head was small enough, he could chop it off without two more growing in its place. To kill the Hydra, all the hero needed to do was to chop off all the heads. Write a program that simulates the Hydra. Instead of heads, we will use...
Please write a c++ header file, class implementation file and
main file that does all of the following and meets the requirements
listed below. Also include a Output of your code as to show that
your program works and functions properly.
EXERCISING A DOUBLY-LINKED LIST CLASS
This project consists of two parts, the second of which appears
below. For the first part, write a class that
implements an unordered list abstract data type
using a doubly-linked list with pointers to...
In this lab, using C++, you will create an abstract data type, using a doubly-linked circular structure to store the values and links. You must create it by your own and not use any existing containers. You will need a QueueNode. You can use a struct for this, as each node will not have any associated functions. It will have members for data, and the next and previous pointers. Data will be positive integers. There will be no NULL pointers....
I need help with the Implementation of an Ordered List (Template Files) public interface OrderedStructure { public abstract int size(); public abstract boolean add( Comparable obj ) throws IllegalArgumentException; public abstract Object get( int pos ) throws IndexOutOfBoundsException; public abstract void remove( int pos ) throws IndexOutOfBoundsException; public abstract void merge( OrderedList other ); } import java.util.NoSuchElementException; public class OrderedList implements OrderedStructure { // Implementation of the doubly linked nodes (nested-class) private static class Node { private Comparable value; private...
Fill in code on right in c++ and follow all constraints and
directions.
1 hode expand (node* head) // fill in code here This problem has you modify a linked lists composed of node objects chained together via node pointers. Each node has a next pointer which points to the next node in the chain. The last node is identified by having a NULL next pointer 4 The linked lists for this lab store string data. Some of the strings...
Hello I need help with this program. Should programmed in C!
Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...
Creating linked list data structure Overview The purpose of this assignment is for you to write a data structure called a Linked List, which utilizes templates (similar to Java’s generics), in order to store any type of data. In addition, the nature of a Linked List will give you some experience dealing with non-contiguous memory organization. This will also give you more experience using pointers and memory management. Pointers, memory allocation, and understand how data is stored in memory will...
PLEASE ANSWER ALL QUESTIONS: Your help is appreciated, THANK YOU :) 5. List four personal characteristics of a Professional Rescuer: 6. What are the two classifications of responders that are more advanced then an EMR? more advanced Pre-hospital Care Personnel? 7. Upon arrival at the scene of an emergency, the first responder’s first priority is— 8. What agency is concerned with regulations dealing with exposure to blood born pathogens? 9. What are the two major diseases of concern caused by...