A Study on Skip Lists, Jump Lists and Random Binary. Search Trees. (Kuan-Chien Wang) (Prof. Wei-Mei Chen)



Similar documents
A Comparison of Dictionary Implementations

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India Dr. R. M.

Converting a Number from Decimal to Binary

From Last Time: Remove (Delete) Operation

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Randomized Binary Search Trees

An Evaluation of Self-adjusting Binary Search Tree Techniques

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

Binary Heap Algorithms

Binary Search Trees CMPSC 122

Lecture Notes on Binary Search Trees

Analysis of Algorithms I: Binary Search Trees

Lecture Notes on Binary Search Trees

How To Create A Tree From A Tree In Runtime (For A Tree)

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Analysis of Binary Search algorithm and Selection Sort algorithm

Binary Search Trees (BST)

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Chapter 14 The Binary Search Tree

TREE BASIC TERMINOLOGIES

Algorithms Chapter 12 Binary Search Trees

Full and Complete Binary Trees

PES Institute of Technology-BSC QUESTION BANK

Lecture 6: Binary Search Trees CSCI Algorithms I. Andrew Rosenberg

A COMPARATIVE STUDY OF LINKED LIST SORTING ALGORITHMS

Skip List Data Structure Based New Searching Algorithm and Its Applications: Priority Search

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Persistent Binary Search Trees

Big Data and Scripting. Part 4: Memory Hierarchies

CSE 326: Data Structures B-Trees and B+ Trees

Ordered Lists and Binary Trees

A Randomized Self-Adjusting Binary Search Tree

Symbol Tables. Introduction

Introduction to data structures

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Analysis of a Search Algorithm

Space-Efficient Finger Search on Degree-Balanced Search Trees

Fast Sequential Summation Algorithms Using Augmented Data Structures

Analysis of Algorithms I: Optimal Binary Search Trees

Heaps & Priority Queues in the C++ STL 2-3 Trees

What Is Recursion? Recursion. Binary search example postponed to end of lecture

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

Data Structures and Algorithms

Data Structures For IP Lookup With Bursty Access Patterns

The ADT Binary Search Tree

Optimal Binary Search Trees Meet Object Oriented Programming

Data Structures and Data Manipulation

Binary Trees and Huffman Encoding Binary Search Trees

Binary Coded Web Access Pattern Tree in Education Domain

11 Finger Search Trees

B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Parallelization: Binary Tree Traversal

Sequential Data Structures

Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

For example, we have seen that a list may be searched more efficiently if it is sorted.

10CS35: Data Structures Using C

Introduction to Data Structures and Algorithms

Data Structures, Practice Homework 3, with Solutions (not to be handed in)

6. Standard Algorithms

GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE AND O(n) TIME J. Patera

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Simple Balanced Binary Search Trees

Tables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n)

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later).

Loop Invariants and Binary Search

Exam study sheet for CS2711. List of topics

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

Binary Search Tree Intro to Algorithms Recitation 03 February 9, 2011

Introduction to Data Structures and Algorithms

An Immediate Approach to Balancing Nodes of Binary Search Trees

DYNAMIC DOMAIN CLASSIFICATION FOR FRACTAL IMAGE COMPRESSION

THIS CHAPTER studies several important methods for sorting lists, both contiguous

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

Binary Heaps. CSE 373 Data Structures

DNS LOOKUP SYSTEM DATA STRUCTURES AND ALGORITHMS PROJECT REPORT

Zabin Visram Room CS115 CS126 Searching. Binary Search

Why Use Binary Trees?

Computer Science 210: Data Structures. Searching

DATABASE DESIGN - 1DL400

Data Structures UNIT III. Model Question Answer

Chapter 13: Query Processing. Basic Steps in Query Processing

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Introduction Advantages and Disadvantages Algorithm TIME COMPLEXITY. Splay Tree. Cheruku Ravi Teja. November 14, 2011

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Algorithms. Margaret M. Fleck. 18 October 2010

Binary Search Trees. basic implementations randomized BSTs deletion in BSTs

Data storage Tree indexes

Data Structures. Level 6 C Module Descriptor

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Exercises Software Development I. 11 Recursion, Binary (Search) Trees. Towers of Hanoi // Tree Traversal. January 16, 2013

Transcription:

A Study on Skip Lists, Jump Lists and Random Binary Search Trees (Kuan-Chien Wang) (Prof. Wei-Mei Chen) Thesis for Master of Science Department of Applied Mathematics Tatung University July 2004

kevin_9999@hotmail.com 2004.07.28 i

Abstract When we look for some specific materials in a group of data, different data structure will have a very great impact on efficiency. We should choose appropriate data structure according to target data so that we can get optimal benefit. We study on the performance of three random data structure, included skip lists, jump lists and random binary search trees. We give experimental results and comparative conclusions on the three randomized data structures. ii

iii

List of Figures Figure 2.1 An example of a skip list... 4 Figure 2.2 An example of searching for an element of key 4 in the skip list of Figure 2.1..... 5 Figure 2.3 Insertion of an element with key 5 into the skip list of Figure 2.2..7 Figure 2.4 Searching of an element with key 5 in the skip list of Figure 2.3 9 Figure 2.5 Removal of the item with key 5 from the skip list of Figure 2.4.....9 Figure 3.1 An example of a random binary search tree... 10 Figure 3.2 An example of searching for an element of key = 19 in the random binary tree of Figure 3.1.......13 Figure 3.3 Insertion of a node with key 28 into the random binary search tree. (a)suppose that 28 is inserted at 40. (b) Because 28 < 40, 40 and the right subtree of 40 is adjusted as the right subtree of 28. (c) Because 28 > 27, 27 and the left subtree of 27 is adjusted as the left subtree of 28....15 Figure 3.4 Delectation of a node with key 28 from the random binary search tree. (a) Searching for 28 in a random binary tree and remove the key. (b) Suppose 2 and the left subtree of 2 is adjusted as the right subtree of 20. (c) Suppose 40 and the right subtree of 40 is adjusted as the right subtree of 2. (d) Finally 27 is adjusted as the left subtree of 40.. 17 Figure 4.1 An example of a jump list...20 iv

Figure 4.2 An example of searching for a node of key 19 in the jump list of Figure 4.1...21 Figure 4.3 An example for a jump list.2 Figure 4.4 Insertion of a node with key 3 into the jump list of Figure 4.3..2 Figure 4.5 Insertion of a node with key 7 into the jump list of Figure 4.3..2 Figure 4. An example of a jump list..28 Figure 4.7 Delectation of a node with key 10 from the jump list of Figure 4. and reconstruct jump list... 28 Figure 4.8 Shows the improvement after preprocessing the input data...29 Figure 5.1 The times of construction in jump lists, random binary search tree, and skip lists in random data for size from 0 to 30000....31 Figure 5.2 The average numbers of comparison search in jump list, random binary search tree and skip list data structure in random data for size from 0 to 30000..32 Figure 5.3 The histogram of the numbers of comparison for search in jump lists for 20000 distinct keys....33 Figure 5.4 The histogram of the numbers of comparison for search in skip lists for 20000 distinct keys... 33 Figure 5.5 The histogram of the numbers of comparison for search in random binary search trees for 20000 distinct keys...34 v

Figure 5. The times of construction in jump list, binary search tree, random binary search tree, and skip list in random data for size from 0 to 10000....3 Figure 5.7 The average numbers of comparison for search in jump lists, binary search tree, random binary search trees and skip lists data structure in ordered data for size from 1 to 30000. 37 vi

Contents 1. Introduction.......1 2. Skip Lists........... 3 2.1 Data structure.........3 2.2 Searching....... 4 2.3 Insertion.......... 2.4 Deletion.. 7 2.5 Remarks....10 3. Random Binary Search Trees..........11 3.1 Data structure.......12 3.2 Searching......12 3.3 Insertion....14 3.4 Deletion....15 3.5 Remarks... 17 4. Jump Lists..........19 4.1 Data structure...19 4.2 Searching..... 20 4.3 Insertion...22 4.4 Deletion...2 vii

4.5 Remarks....28 5. Conclusions...... 30 5.1 The Comparisons of Random Data.....30 5.1.1 The Times of Construction......30 5.1.2 The Average Numbers of Comparison for Search..32 5.1.3 The Distribution of The Numbers of Comparison for Search.33 5.2 The Comparison for Ordered Data.......35 5.2.1 The Times of Construction..35 5.2.2 The Average Numbers of Comparison for Search..3 5.2.3 Summary.....3 References.40 viii

CHAPTER 1 INTRODUCTION Searching is a very common and important operation when look for some specific materials in a group of data. When we want to look for an element in a large amount of data, different data structure will have a very great impact on efficiency. The choice of the structure of the data will affect the quality of the performance of the application program. In general, a binary search tree is a simple and efficient data structure insertion, deletion and search by operation applying the motivation of the binary search procedure to a tree structure. Since the cost of search depends on height of the tree, the binary search tree performs not very well when it is built by almost ordered data. Particularly, the binary search tree built by sorted data is similar to a linked list. There are many data structures proposed to improve the search efficiency for the worst-case, such as AVL trees [1], red-black trees [4], splay trees [10], and random binary search trees [8], skip lists [9], jump lists [2]. We are interested in the randomize data structure, included random binary search trees, skip lists and jump lists. These three data structures perform the search operation very well on average by using random choices and they do not depend on the order of given data. The advantage of using randomization in data structure and algorithm design is that the structures and methods that result are usually simple and efficient. This 1

particular implementation may not necessarily be faster or use less space, but in superficial testing, it does appear to be a reasonably faster substitute for some tree modules. The random binary search tree was introduced by Martinez and Roura [8]. Because random binary search trees build by random insertion, the worst case of binary search tree occurs with low probability. The performance of search operation is O(log n) time [3,7,12]. The skip list was presented by Pugh. Skip list [9] is a simple implementation of an ordered dictionary. It improves search operations by using a random number generator to decide the position of the new inserted item. The jump list was proposed by Bronnimann et. al.[2]. The data structures only need a little space of storage and simple mode of search. The purpose of this thesis is to investigate experimental results for the performances of skip lists, random binary search threes, and jump lists. In Chapter 2 we introduce the skip list and its insertion, search and deletion algorithms. In Chapter 3 we introduce the random binary search tree and its insertion, search and deletion algorithms. In Chapter 4 we introduce the jump list and its insertion, search and deletion algorithms. Finally we give experimental results and comparative conclusions in Chapter 5. 2

CHAPTER 2 SKIP LISTS In this chapter, we will describe the data structure and elementary operations for skip lists. 2.1 Data structure Skip list was proposed by William Pugh [9]. The data structure is basically an ordered list with distributed short-cuts in order to improve search time, in which searches, insertions, and deletions have an expected cost of O(log n ), where n is the number of elements. Skip lists are similar to linked lists, except that they have random links at various levels that allow searches to skip over sections of the list. A skip list for a set S of distinct (key, element) items is a series of lists S 0, S 1,,S h such that 1. Each list S i contains the special keys + and - 2. List S 0 contains the keys of S in nondecreasing order 3. Each list is a subsequence of the previous one. S 0 S1 Λ S h An example of a skip list data structure is show in Figure 2.1. 3

3 1 3 4 1 3 4 1 2 3 4 7 Figure 2.1 An example of a skip list 2.2 Searching The search algorithm for skip lists is very simple. Starting at the leftmost node L in the highest level, we scan through each level as far as we can without passing the target value x, and then proceed down to the next level. The search ends when we either reach a node with search key x or fail to end x on the lowest level. We illustrate this algorithm in Figure 2.2. 4

Program 2.1 Algorithm for searching in a skip list. search( skiplist, key){ x=skiplist->header; for i= skiplist->level downto 1 do while x-> forward[i]->key< key do x=x->forward[i] x= x->forward[1] if x->key =key then return x->key else return NO_SUCH_KEY} Start 3 1 3 4 1 3 4 1 2 3 4 7 Figure 2.2 An example of searching for an element of key 4 in the skip list of Figure 2.1. 5

2.3 Insertion The insertion for skip list uses randomization to decide how many references to the new item should be a add to the skip list. We call a method random that we flip a coin. If the flip comes up heads, we add number of level until the coin become tails. We give the insertion algorithm for a skip list in program 2.2. For example, we insert an element with key 5 into the skip list. First, search for it terminated at level 1, then choose a random level and put key in skip list level 1 to level. Figure 2.3 shows the new skip list for key = 5. Program 2.2 Algorithm for insertion in a skip list. insert(key, skiplist){ x=skiplist->header for i= skiplist->level downto 1 do while x-> forward[i]->key< key do x=x->forward[i] updata[i]=x x= x->forward[1] newlevel=randomlevel() for i = 1 to newlevel do x->forward[i]=updata[i]->forward[i] update[i]->forward[i]=x } Figure 2.3 Searching the position of insertion

5 5 3 5 1 3 4 5 1 3 4 5 1 2 3 4 5 7 + Figure 2.3 Insertion of an element with key 5 into the skip list of Figure 2.2. 2.4 Deletion For the deletion operation, we first search for the location of node v, then we splice the node when delete the node v. After every deletion, we check see if we have deleted the key of the list and if so, decrease the maximum level of the list. we illustrate this algorithm in Figure 2.4 and 2.5. 7

Program 2.3 Algorithm for deletion in a skip list. delet(key, skiplist){ x=skiplist->header for i= skiplist->level downto 1 do while x-> forward[i]->key< key do x=x->forward[i] updata[i]=x x= x->forward[1] if x->key = key then for i = 1 to skiplist->level do if updata[i]-> forward[i] x then break updata[i]-> forward[i] = x->dorward[i] free(x) while skiplist->level > 1 and skiplist->header->foeward[skiplist->level]= NULL do skiplist->level = skiplist->level -1 8

5 5 3 5 1 3 4 5 1 3 4 5 1 2 3 4 5 7 Figure 2.4 Searching of an element with key 5 in the skip list of Figure 2.3. 3 1 3 4 1 3 4 1 2 3 4 7 Figure 2.5 Removal of the item with key 5 from the skip list of Figure 2.4. 9

2.5 Remarks Skip lists provide a simple implementation of an ordered dictionary. In fact, if we don t officially prevent an insertion from continuing significantly past the current highest level, then the insertion algorithm can go into what is almost an infinite loop. In addition, we cannot infinitely add elements to a list without eventually running out of memory. In any case, if we terminate item insertion at the highest level h, then the worst-case running time for performing the insertion operation in a skip list.this worst-case performance occurs when the tower of every item reaches level h -1. However, this event has very low probability. 10

CHAPTER 3 RANDOM BINARY SEARCH TREES In this chapter, we will describe the data structure and elementary operations for random binary search trees. 3.1 Data structure In a binary search tree, we consider the three basic operations searching, insertion and deletion. If the height of binary search tree is too large, the times of operations will become long. In generally speaking, the search operation takes O( log n) time in average when binary search tree with size n, while it takes O(n) time for the worst care. We introduce random binary search tree here, since it can avoid height of binary search tree too large when the input data is ordered. The greatest differences between two data structure in the way that insertion. Binary search tree proceeds from root, walks downwards along the route. A new key will be insert at an empty node. Random binary search tree proceed from root and walk downwards along the route. While comparing with every node, it will choose a random number from 0 to n (n is the size of the subtree). If the chosen number just equally size of the subtree, this node will be inserted in this seat, and the following nodes will be reset. Finally, set up into binary search tree. So we can avoid height of binary search tree too large when the data input is order. An example of a random binary search tree data structure is show in Figure 3.1. 11

20 1 24 14 18 22 28 13 15 17 19 21 23 2 32 Figure 3.1 An example of a random binary search tree. 3.2 Searching For the search operation, we start at the root. If the search key is less then the node key, the search key turn to left on the node key. If the search key is greater then the node key, the search key is turn to right on the node key. Repeat the processing for a key until find key or node is NULL. We illustrate this algorithm in Figure 3.2. 12

Program 3.1 Algorithm for searching in a random binary search. bst search(key x, bst T ){ node t t = T; while(t!=null){ if(x > t->key) t = t->right; else if(x < t->key) t = t->left; else return x } Start 20 1 24 14 18 22 28 13 15 17 19 21 23 2 32 Figure 3.2 An example of searching for an element of key = 19 in the random binary tree of Figure 3.1. 13

3.3 Insertion Next we introduce the insertion operation for random binary search trees. Insertion algorithm of random binary search trees is similar to standard insertion algorithm [3,11,5] of binary search trees. Random binary search tree is build using random insertions. Similar to binary search trees, we generating a random integer r in the range 0 to n(n is size of subtree) when compare with each node. If r equal to n, we will replace the originally node position and reset its subtree. Finally, let the structure of subtree become binary search tree. We illustrate this algorithm in Figure 3.3. Program 3.2 Algorithm for insertion in a random binary search tree. bst insert(int x,bst T){ int n,r; n=t->size; r=random(0,n); if(r == n) return insert_at_root(x,t); if(x<t->key) T->left = insert(x,t->left); else T->right = insert(x,t->right); Return T;} 14

(a) 50 (b) 50 (c) 50 25 0 25 0 25 0 14 40 14 28 14 28 27 45 27 40 27 40 2 2 45 2 45 Figure 3.3 Insertion of a node with key 28 into the random binary search tree. (a)suppose that 28 is inserted at 40. (b) Because 28 < 40, 40 and the right subtree of 40 is adjusted as the right subtree of 28. (c) Because 28 > 27, 27 and the left subtree of 27 is adjusted as the left subtree of 28. 3.4 Deletion We want to delete the key x form a random binary search tree. In the first place, we should search for the location of key x. There are only subtree whose root is x will be modified when deleted x. Let T be a subtree which root is x. Let L and R is the left and right subtree of T. When deleted x, we build a new binary search tree which containing L and R of x. Now, we introduce how to join the two subtree of x. Assume that L and R are trees 15

of size m > 0 and n > 0. Let L l and L r is the left and right subtree of L and R l and R r is the left and right subtree of R. Further, let x and y denote the root of the trees L anf R. We choose a random number a between 0 and n + m. If a < m, we choose x become the root of T and join L r and R become the right subtree of L. If a > m, we choose y become the root of T and join L and R l become the left subtree of R. We will do it until subtree of left or right is empty. An example of a random binary search tree we illustrate this algorithm in Figure 3.4. Program 3.3 Algorithm for deletion in a random binary search tree. bst delete(int x,bst T){ bst S; if(t == NULL) return NULL; if(x < T->key) T->left = delete(x,t->left); else if (x > T->key) T->right = delete(x,t->right); else S = join(t->left, T->right); Free_node(t); T = S; Return T;} 1

(a) 50 20 0 14 28 2 22 27 40 45 (b) 14 20 22 50 2 0 27 40 45 (c) 50 (d) 50 20 0 20 0 14 2 14 2 22 40 22 40 45 27 27 45 Figure 3.4 Delectation of an element with key 28 from the random binary search tree. (a) Searching for 28 in a random binary tree and remove the key. (b) 2 and the left subtree of 2 is adjusted as the right subtree of 20. (c) 40 and the right subtree of 40 is adjusted as the right subtree of 2. (d) Finally, 27 is adjusted as the left subtree of 40. 3.5 Remarks Random binary search tree is like binary search tree. If binary search tree is more balance, we have more efficiency for search, insertion and deletion. Random binary search tree performance of search operation is O(log n). Because random binary search trees are build by random insertion, it can avoid height of binary search tree too large. We 17

need additional operation when insertion the key. So we need more time to build the random binary search tree. However, it can avoid the worst-case of binary search tree. The worst-case of random binary search tree occurs with very low probability. 18

CHAPTER 4 JUMP LIST In this chapter, we will describe the data structure and elementary operations for jump lists. 4.1 Data structure A jump list is a linked list whose nodes are endowed with an additional pointer, the so-called jump pointer. For every node in the jump list have two pointer: next[x] point and jump[x] pointer. A jump list is circularly connect, the first element and the last element is the same. The search algorithm of Jump lists is based on the jump-and-walk strategy: whenever possible use to the jump pointer to speed-up the search, and walk along the list otherwise. Similar to skip lists, we use jump pointer to speed-up searches. But jump lists do not have hierarchy of jump pointers. In the jump list data structure, we have the following invariants 1. A jump list L is a double link list. A jump list L have a special node call header[l] for every node x header[l]. 2. For every node x, x < jump[x], except the last node x for which jump[y] = next[x] = header[y]. 3.For any two node x < y, either x < y < jump[y] < jump[x], or jump[x] y, or 19

jump[y] = jump[x] = next[y] 4. In order to close the loop, jump[x]= header[l] and next[x]=header[l] for the last point x, this last point that we called exception. An example of a jump list data is show in Figure 4.1. 0 1 2 3 4 5 header[l] Figure 4.1 An example of a jump list. 4.2 Searching In a jump list, the basic search algorithm is jump-and-walk. We start at the header. If the search key is greater than or equal to key of jump point, the search key go to jump point. If the search key is greater than or equal to key of next point and the search key is less then key of jump point, the search key go to next point. Search for a key until found the key or next pointer equal header. The search algorithm is presented in Figure 4.2. 20

Program 4.1 Algorithm for searching in a jump list. search(header[l],key){ y=header[l] key[x]=key while next[y] header[l] if key[jump[y]] key then y=jump[y] else if key[next[y]] key then y=next[y] else return y return y } 0 1 2 3 4 5 Figure 4.2 An example of searching for a node of key 19 in the jump list of Figure 4.1. 21

4.3 Insertion Before inserting, we first introduce the construction operation for a jump list from a sorted linked list. We only choose the jump point of header, and recursively build the next and jump sublist. Similar to skip list, we will search location of insert key. There two case when we find the location of insert key. Case 1 x is inserted in the jump list rooted at C, and [C, X] becomes the new fundament arch. The randomness property of the jump list rooted at C, that is C X, has to be reconstruct jump list. For example, insertion of an element with key 3 in Figure 4.4 into the jump list L of Figure 4.3. Case 2 x is inserted right after C. The randomness property of the jump list rooted at X, that is X N(next sublist of C), has to be reconstruct jump list. For example, insertion of an element with key 7 in Figure 4.4 into the jump list L of Figure 4.3. 22

Program 4.2 Jumplistfromlist y=header[l] n=size(l) Productjumplist(y, n){ while n>1 do m =random(0,n) jump[x]= Productjumplist(next[x], m-2) x = jump[x] n = n-m+1 return x } 23

Program 4.3 Algorithm for insertion in a jump list. insert(header[l),key){ y=header[l] x->key=key while next[y] header[l] if jump[y]->key key then y=jump[y] else if next[y]->key key then y=next[y] else{ Case 1:if y = header[l] then next[x]=next[y] next[y]=x Productjumplist(header[L], size(l)) Case 2: next[x]=next[y] next[y]=x Productjumplist(x,size[next[y]]+1 ) } } 24

Jump list L 5 9 20 30 35 header[l] Figure 4.3 An example for a jump list. Jump list L 3 5 9 20 30 35 header[l] Figure 4.4 Insertion of a node with key 3 into the jump list of Figure 4.3. Jump list L 5 9 20 30 35 7 header[l] Figure 4.5 Insertion of a node with key 7 into the jump list of Figure 4.3. 25

4.4 Deletion We show it how to deleted key x from jump list. In the first place, we should search for the location of node C such that key[jump[c]] = x or key[next[c]] = x. There two case when we find the location of C. Case 1 Deleting X with key[jump[c]] = x: 1. The removal of X requires the knowledge of its predecessor. 2. The system of arches starting at X needs to be recomputed. Case 2 Deleting X with key[next[c]] = x: 1. If we have a length one arch jump[x] = next[x], the situation is trivial. 2. To create a random arch root at next[c]. For example, delectation of an element with key 10 in Figure 4.7 into the jump list L of Figure 4.. 2

Program 4.4 Algorithm for deletion in a jump list. delete(header[l),key){ y=header[l]; x->key=jump[y]->key; while next[y] header[l] if jump[y]->key key then y=jump[y] else if next[y]->key key then y=next[y] else{ Case 1: if jump[y]->key < x->key then free(next[y]) Productjumplist(header[L], size(jump[x]+1)) Case 2: if jump[y]->key > x->key then free(next[y]) Productjumplist(y,size(jump[y]]+1) ) } } 27

Jump list L 5 9 10 20 30 35 header[l] Figure 4. An example of a jump list. Jump list L 5 9 20 30 35 header[l] Figure 4.7 Delectation of a node with key 10 from the jump list of Figure 4. and reconstruct jump list. 4.5 Remarks The jump lists is stored as a singly connect list. It affect for searching by only use two pointers. Although the space required by a jump list is less and the traversal is very simple, we need more time to construct the jump lists. In some cases, we can improve constructional time. If we know size of data is n in random data, we can sort by quicksort. 28

We link the data need O(n) time and construct a jump list operation is O(n). Figure 4.8 Shows the improvement after preprocessing the input data. It is obvious that improve the performance of construction. 29

CHAPTER 5 CONCLUSIONS Binary search tree is simple and efficiency data structure for random data. But its search operations and times of construction is ineffectually for ordered data. Skip lists, jump lists and random binary search trees are more efficient for search operation no matter data is ordered or random. We will compare times of search and construction for ordered and random data. 5.1 The Comparisons of Random Data We are interested in the randomize data structure, included random binary search trees, skip lists and jump lists. These three data structures perform the search operation very well on average by using random choices. 5.1.1 The Times of Construction Figure 5.1 shows the times of construction in jump lists, random binary search trees and skip lists for random input data. The experimental result points out that skip lists need less time of construction than those of the other two data structures. It is quite obvious that a jump list is inefficient for construction, because it needs to re-establish sublist for each insertion. 30

500 450 400 350 300 250 200 150 100 50 0 Jumplist Random binary search tree Skiplist 0 5000 10000 15000 20000 25000 30000 Figure 5.1 The times of construction in jump lists, random binary search tree, and skip lists in random data for size from 0 to 30000. 31

5.1.2 The Average Numbers of Comparison for Search Figure 5.2 shows the average numbers of comparison for search in jump lists, random binary search trees and skip lists for random input data. The experimental result regards that skip lists do more comparisons than the other two data structures. It is quite obvious that the search operations of jump lists and random binary search trees are almost the same. Figure 5.2 The average numbers of comparison search in jump list, random binary search tree and skip list data structure in random data for size from 0 to 30000. 32

5.1.3 The Distribution of The Numbers of Comparison for Search From Figure 5.3 to Figure 5.5 are the distributions of average numbers of comparison for search in jump lists, random binary search trees, and skip lists for random input data. Figure 5.3 The histogram of the numbers of comparison for search in jump lists for 20000 distinct keys. Figure 5.4 The histogram of the numbers of comparison for search in skip lists for 20000 33

distinct keys. Figure 5.5 The histogram of the numbers of comparison for search in random binary search trees for 20000 distinct keys. 34

5.2 The Comparison for Ordered Data We are interested in the ordered data structure, included random binary search trees, binary search trees, skip lists and jump lists. We know that the binary search tree performs the search operation not very well for ordered data, but random binary search trees, skip lists and jump lists perform the search operation very well by experimental result. 5.2.1 The Times of Construction Figure 5. shows the times of construction in jump lists, random binary search trees, skip lists and binary search tree for ordered data. The experimental result indicates that skip lists and random binary search trees need less times of construction than those of the other two data structures. Skip lists and random binary search trees are more efficient for ordered data. 35

Figure 5. The times of construction in jump list, binary search tree, random binary search tree, and skip list in random data for size from 0 to 10000. 5.2.2 The Average Numbers of Comparison for Search The search efficiency of binary search tree is worse in ordered data. Figure 5.7 shows the average comparative number of search in jump lists, binary search tree, and random binary search trees and skip lists for ordered data. The experimental result regards that jump lists, random binary search trees and skip lists are more efficient at searching. 3

Figure 5.7 The average numbers of comparison for search in jump lists, binary search tree, random binary search trees and skip lists data structure in ordered data for size from 1 to 30000. 5.3 Summary When we look for some specific materials in a group of data, different data structure will have a very great impact on efficiency. We should choose appropriate data structure according to target data so that we can get optimal benefit. We investigate three randomized data structures, included jump lists, random binary search trees and skip lists. Skip lists require less time of construction. For search operations, jump lists and random binary trees are more efficient. The space required by a jump list is the least. In general, binary search tree is simple and efficiency data structure. But its search 37

operations is ineffectually and it takes more times of construction for ordered data. According to experimental results, skip lists, jump lists and random binary search trees are more efficient than binary search tree for ordered data both in time and space requirements. Therefore, these three data structures are considerable methods to solve the worst-case of binary search tree. Jump lists only use two pointers, so it needs less space. The experimental result also regards that it is more efficient for search operations. However, it needs to reconstruct sublist so that the times of construction would be much. But it can be improved if the entire data is known. Because jump lists need to reestablish sublist for each insertion, it will takes much time. If we know the entire data, we can sort it. We only link the data and construct a jump list at a time. It indeed improves jump lists by experimental result. Random binary search trees are enhancement of binary trees. According to the experimental result, it has good search operations and less time of construction because the height of its tree is less. Comparing with jump lists and random binary search trees, skip lists has less insert operations, so its time of construction is less. However, it limits the amount of input data so that the search operations is not so good. Up to now, there is not a data structure applied to all kinds of data. Every data 38

structure has pros and cons. The experimental result provides the advantages of these three data structures. We should choose appropriate data structure according to target data so that we can get optimal benefit. 39

References [1] G. Adel son-vel skii, and E. Landis, An algorithm for the organization of information. Dokl. Akad. Nauk SSSR 14, 2, 23-2,192. [2] H. Bronnimann, F. Cazals, and M. Durand, Random Jumplists-A Jump-and-Walk Dictionary Data Structure, 283-294, STACS 2003. [3] D. E. Knuth, The Art of Computer Programming: Sorting and Searching, vol. 3. Addison-Wesley, Reading, Mass.,1973. [4] L. Guibas, and R. Sedgewick, A dichromatic framework for balanced trees. In Proceedings of the 19th Annual IEEE Symposium on Foundations of Computer Science (FOCS) (Oct.). IEEE, New York, 8-21. 1978. [5] G. H. Gonnet and R. Baeza-Yates, Handbook of Algorithms and Data Structures In Pascal and C. 2nd ed. Addison-Wesley, Reading, Mass.,1991. [] D. E. Knuth, The Art of Computer Programming: Sorting and Searching, vol. 3. Addison-Wesley, Reading, Mass.,1973. [7] H. M. Mahmoud, Evolution of Random Search Trees. Wiley Interscience, New York.,1992. [8] C. Martinez and S. Roura, Random binary search trees. J. Assoc. Comput. Mach., 45(2) 282-323, 1998. [9] W. Pugh, Skip list: a probabilistic alternative to balanced trees. Comm. ACM, 40

33():8-7,1990. [10] D. D. Slcator and R. E. Targan, Self-adjusting binary search trees. J. ACM, 32(3) 52-8,1985. [11] R. Sedgewick, Algorithms, 2nd ed. Addison-Wesley, Reading, Mass., 1988. [12] R. Sedgewick, and P. Flajolet, An Introduction to the Analysis of Algorithms. Addison-Wesley, Reading, Mass.,199. 41