Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
skip_list.cpp File Reference

Data structure for fast searching and insertion in \(O(\log n)\) time. More...

#include <array>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <vector>
Include dependency graph for skip_list.cpp:

Classes

struct  data_structures::Node
 
class  data_structures::SkipList
 

Namespaces

namespace  data_structures
 for IO operations
 

Functions

int main ()
 

Variables

constexpr int data_structures::MAX_LEVEL = 2
 Maximum level of skip list.
 
constexpr float data_structures::PROBABILITY = 0.5
 Current probability for "coin toss".
 

Detailed Description

Data structure for fast searching and insertion in \(O(\log n)\) time.

A skip list is a data structure that is used for storing a sorted list of items with a help of hierarchy of linked lists that connect increasingly sparse subsequences of the items

References used: GeeksForGeek, OpenGenus for PseudoCode and Code

Author
enqidu
Krishna Vedala

Function Documentation

◆ main()

int main ( void )

Main function: Creates and inserts random 2^[number of levels] elements into the skip lists and than displays it

212 {
213 std::srand(std::time(nullptr));
214
216
217 for (int j = 0; j < (1 << (data_structures::MAX_LEVEL + 1)); j++) {
218 int k = (std::rand() % (1 << (data_structures::MAX_LEVEL + 2)) + 1);
219 lst.insertElement(k, &j);
220 }
221
222 lst.displayList();
223
224 return 0;
225}
Definition skip_list.cpp:55
void insertElement(int key, void *value)
Definition skip_list.cpp:90
void displayList()
Definition skip_list.cpp:191
double k(double x)
Another test function.
Definition composite_simpson_rule.cpp:117
constexpr int MAX_LEVEL
Maximum level of skip list.
Definition skip_list.cpp:27
T rand(T... args)
T srand(T... args)
T time(T... args)
Here is the call graph for this function: