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

Size: px
Start display at page:

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

Transcription

1 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

2

3 i

4 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

5 iii

6 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 Figure 2.3 Insertion of an element with key 5 into the skip list of Figure Figure 2.4 Searching of an element with key 5 in the skip list of Figure Figure 2.5 Removal of the item with key 5 from the skip list of Figure Figure 3.1 An example of a random binary search tree Figure 3.2 An example of searching for an element of key = 19 in the random binary tree of Figure 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 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 Figure 4.1 An example of a jump list...20 iv

7 Figure 4.2 An example of searching for a node of key 19 in the jump list of Figure 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 Figure 4.5 Insertion of a node with key 7 into the jump list of Figure 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 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 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 Figure 5.3 The histogram of the numbers of comparison for search in jump lists for distinct keys Figure 5.4 The histogram of the numbers of comparison for search in skip lists for distinct keys Figure 5.5 The histogram of the numbers of comparison for search in random binary search trees for distinct keys...34 v

8 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 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 vi

9 Contents 1. Introduction Skip Lists Data structure Searching Insertion Deletion Remarks Random Binary Search Trees Data structure Searching Insertion Deletion Remarks Jump Lists Data structure Searching Insertion Deletion...2 vii

10 4.5 Remarks Conclusions The Comparisons of Random Data The Times of Construction The Average Numbers of Comparison for Search The Distribution of The Numbers of Comparison for Search The Comparison for Ordered Data The Times of Construction The Average Numbers of Comparison for Search Summary References.40 viii

11 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

12 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

13 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

14 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

15 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 Figure 2.2 An example of searching for an element of key 4 in the skip list of Figure

16 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

17 Figure 2.3 Insertion of an element with key 5 into the skip list of Figure 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

18 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

19 Figure 2.4 Searching of an element with key 5 in the skip list of Figure Figure 2.5 Removal of the item with key 5 from the skip list of Figure

20 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

21 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

22 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

23 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 Figure 3.2 An example of searching for an element of key = 19 in the random binary tree of Figure

24 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

25 (a) 50 (b) 50 (c) 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 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

26 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

27 (a) (b) (c) 50 (d) 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 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

28 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

29 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

30 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 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

31 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 } Figure 4.2 An example of searching for a node of key 19 in the jump list of Figure

32 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

33 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

34 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

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

36 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

37 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

38 Jump list L header[l] Figure 4. An example of a jump list. Jump list L 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

39 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

40 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 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

41 Jumplist Random binary search tree Skiplist 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

42 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

43 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 distinct keys. Figure 5.4 The histogram of the numbers of comparison for search in skip lists for

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

45 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 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

46 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 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

47 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 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

48 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

49 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

50 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, , STACS [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, [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) , [9] W. Pugh, Skip list: a probabilistic alternative to balanced trees. Comm. ACM, 40

51 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., [12] R. Sedgewick, and P. Flajolet, An Introduction to the Analysis of Algorithms. Addison-Wesley, Reading, Mass.,

A Comparison of Dictionary Implementations

A Comparison of Dictionary Implementations A Comparison of Dictionary Implementations Mark P Neyer April 10, 2009 1 Introduction A common problem in computer science is the representation of a mapping between two sets. A mapping f : A B is a function

More information

- 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

- 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 Skip Lists CMSC 420 Linked Lists Benefits & Drawbacks Benefits: - Easy to insert & delete in O(1) time - Don t need to estimate total memory needed Drawbacks: - Hard to search in less than O(n) time (binary

More information

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

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child Binary Search Trees Data in each node Larger than the data in its left child Smaller than the data in its right child FIGURE 11-6 Arbitrary binary tree FIGURE 11-7 Binary search tree Data Structures Using

More information

S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India e-mail: nellailath@yahoo.co.in. Dr. R. M.

S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India e-mail: nellailath@yahoo.co.in. Dr. R. M. A Sorting based Algorithm for the Construction of Balanced Search Tree Automatically for smaller elements and with minimum of one Rotation for Greater Elements from BST S. Muthusundari Research Scholar,

More information

Converting a Number from Decimal to Binary

Converting a Number from Decimal to Binary Converting a Number from Decimal to Binary Convert nonnegative integer in decimal format (base 10) into equivalent binary number (base 2) Rightmost bit of x Remainder of x after division by two Recursive

More information

From Last Time: Remove (Delete) Operation

From Last Time: Remove (Delete) Operation CSE 32 Lecture : More on Search Trees Today s Topics: Lazy Operations Run Time Analysis of Binary Search Tree Operations Balanced Search Trees AVL Trees and Rotations Covered in Chapter of the text From

More information

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:

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: Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)

More information

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

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb Binary Search Trees Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 27 1 Properties of Binary Search Trees 2 Basic BST operations The worst-case time complexity of BST operations

More information

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

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 Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent

More information

Randomized Binary Search Trees

Randomized Binary Search Trees CONRADO MARTÍNEZ AND SALVADOR ROURA Universitat Politècnica de Catalunya, Barcelona, Catalonia, Spain Abstract. In this paper, we present randomized algorithms over binary search trees such that: (a) the

More information

An Evaluation of Self-adjusting Binary Search Tree Techniques

An Evaluation of Self-adjusting Binary Search Tree Techniques SOFTWARE PRACTICE AND EXPERIENCE, VOL. 23(4), 369 382 (APRIL 1993) An Evaluation of Self-adjusting Binary Search Tree Techniques jim bell and gopal gupta Department of Computer Science, James Cook University,

More information

root node level: internal node edge leaf node CS@VT Data Structures & Algorithms 2000-2009 McQuain

root node level: internal node edge leaf node CS@VT Data Structures & Algorithms 2000-2009 McQuain inary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from each

More information

Binary Heap Algorithms

Binary Heap Algorithms CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell

More information

Binary Search Trees CMPSC 122

Binary Search Trees CMPSC 122 Binary Search Trees CMPSC 122 Note: This notes packet has significant overlap with the first set of trees notes I do in CMPSC 360, but goes into much greater depth on turning BSTs into pseudocode than

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 17 October 23, 2014 1 Introduction In this lecture, we will continue considering associative

More information

Analysis of Algorithms I: Binary Search Trees

Analysis of Algorithms I: Binary Search Trees Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning Lecture 17 March 17, 2010 1 Introduction In the previous two lectures we have seen how to exploit the structure

More information

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

How To Create A Tree From A Tree In Runtime (For A Tree) Binary Search Trees < 6 2 > = 1 4 8 9 Binary Search Trees 1 Binary Search Trees A binary search tree is a binary tree storing keyvalue entries at its internal nodes and satisfying the following property:

More information

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

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

More information

Analysis of Binary Search algorithm and Selection Sort algorithm

Analysis of Binary Search algorithm and Selection Sort algorithm Analysis of Binary Search algorithm and Selection Sort algorithm In this section we shall take up two representative problems in computer science, work out the algorithms based on the best strategy to

More information

Binary Search Trees (BST)

Binary Search Trees (BST) Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to node 2. Each node has at most two child nodes (a left and a right child) 3. Nodes are organized by the Binary Search

More information

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

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: Chapter 12: Binary Search Trees A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: For all nodes x and y, if y belongs to the left subtree

More information

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

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * * Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest

More information

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

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in

More information

Chapter 14 The Binary Search Tree

Chapter 14 The Binary Search Tree Chapter 14 The Binary Search Tree In Chapter 5 we discussed the binary search algorithm, which depends on a sorted vector. Although the binary search, being in O(lg(n)), is very efficient, inserting a

More information

TREE BASIC TERMINOLOGIES

TREE BASIC TERMINOLOGIES TREE Trees are very flexible, versatile and powerful non-liner data structure that can be used to represent data items possessing hierarchical relationship between the grand father and his children and

More information

Algorithms Chapter 12 Binary Search Trees

Algorithms Chapter 12 Binary Search Trees Algorithms Chapter 1 Binary Search Trees Outline Assistant Professor: Ching Chi Lin 林 清 池 助 理 教 授 chingchi.lin@gmail.com Department of Computer Science and Engineering National Taiwan Ocean University

More information

Full and Complete Binary Trees

Full and Complete Binary Trees Full and Complete Binary Trees Binary Tree Theorems 1 Here are two important types of binary trees. Note that the definitions, while similar, are logically independent. Definition: a binary tree T is full

More information

PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC QUESTION BANK PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

More information

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

Lecture 6: Binary Search Trees CSCI 700 - Algorithms I. Andrew Rosenberg Lecture 6: Binary Search Trees CSCI 700 - Algorithms I Andrew Rosenberg Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort Today Binary Search Trees Data Structures Data structure is a

More information

A COMPARATIVE STUDY OF LINKED LIST SORTING ALGORITHMS

A COMPARATIVE STUDY OF LINKED LIST SORTING ALGORITHMS A COMPARATIVE STUDY OF LINKED LIST SORTING ALGORITHMS by Ching-Kuang Shene 1 Michigan Technological University Department of Computer Science Houghton, MI 49931-1295 shene@mtu.edu 1 Introduction Carraway

More information

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

Skip List Data Structure Based New Searching Algorithm and Its Applications: Priority Search Skip List Data Structure Based New Searching Algorithm and Its Applications: Priority Search Mustafa Aksu Department of Computer Technologies Vocational School of Technical Sciences, Sutcu Imam University

More information

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

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees Learning Outcomes COMP202 Complexity of Algorithms Binary Search Trees and Other Search Trees [See relevant sections in chapters 2 and 3 in Goodrich and Tamassia.] At the conclusion of this set of lecture

More information

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

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

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)

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) Sorting revisited How did we use a binary search tree to sort an array of elements? Tree Sort Algorithm Given: An array of elements to sort 1. Build a binary search tree out of the elements 2. Traverse

More information

Persistent Binary Search Trees

Persistent Binary Search Trees Persistent Binary Search Trees Datastructures, UvA. May 30, 2008 0440949, Andreas van Cranenburgh Abstract A persistent binary tree allows access to all previous versions of the tree. This paper presents

More information

Big Data and Scripting. Part 4: Memory Hierarchies

Big Data and Scripting. Part 4: Memory Hierarchies 1, Big Data and Scripting Part 4: Memory Hierarchies 2, Model and Definitions memory size: M machine words total storage (on disk) of N elements (N is very large) disk size unlimited (for our considerations)

More information

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

CSE 326: Data Structures B-Trees and B+ Trees Announcements (4//08) CSE 26: Data Structures B-Trees and B+ Trees Brian Curless Spring 2008 Midterm on Friday Special office hour: 4:-5: Thursday in Jaech Gallery (6 th floor of CSE building) This is

More information

Ordered Lists and Binary Trees

Ordered Lists and Binary Trees Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:

More information

A Randomized Self-Adjusting Binary Search Tree

A Randomized Self-Adjusting Binary Search Tree A Randomized Self-Adjusting Binary Search Tree Mayur Patel VFX Department Supervisor Animal Logic Film patelm@acm.org We present algorithms for a new self-adjusting binary search tree, which we call a

More information

Symbol Tables. Introduction

Symbol Tables. Introduction Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

More information

Introduction to data structures

Introduction to data structures Notes 2: Introduction to data structures 2.1 Recursion 2.1.1 Recursive functions Recursion is a central concept in computation in which the solution of a problem depends on the solution of smaller copies

More information

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

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)! The Tower of Hanoi Recursion Solution recursion recursion recursion Recursive Thinking: ignore everything but the bottom disk. 1 2 Recursive Function Time Complexity Hanoi (n, src, dest, temp): If (n >

More information

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

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Problem 1. In each of the following question, please specify if the statement

More information

Analysis of a Search Algorithm

Analysis of a Search Algorithm CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,

More information

Space-Efficient Finger Search on Degree-Balanced Search Trees

Space-Efficient Finger Search on Degree-Balanced Search Trees Space-Efficient Finger Search on Degree-Balanced Search Trees Guy E. Blelloch Bruce M. Maggs Shan Leung Maverick Woo Computer Science Department, Carnegie Mellon University, Pittsburgh, PA 113 {guyb,bmm,maverick}@cs.cmu.edu

More information

Fast Sequential Summation Algorithms Using Augmented Data Structures

Fast Sequential Summation Algorithms Using Augmented Data Structures Fast Sequential Summation Algorithms Using Augmented Data Structures Vadim Stadnik vadim.stadnik@gmail.com Abstract This paper provides an introduction to the design of augmented data structures that offer

More information

Analysis of Algorithms I: Optimal Binary Search Trees

Analysis of Algorithms I: Optimal Binary Search Trees Analysis of Algorithms I: Optimal Binary Search Trees Xi Chen Columbia University Given a set of n keys K = {k 1,..., k n } in sorted order: k 1 < k 2 < < k n we wish to build an optimal binary search

More information

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

Heaps & Priority Queues in the C++ STL 2-3 Trees Heaps & Priority Queues in the C++ STL 2-3 Trees CS 3 Data Structures and Algorithms Lecture Slides Friday, April 7, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks

More information

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

What Is Recursion? Recursion. Binary search example postponed to end of lecture Recursion Binary search example postponed to end of lecture What Is Recursion? Recursive call A method call in which the method being called is the same as the one making the call Direct recursion Recursion

More information

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

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2016S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

Data Structures For IP Lookup With Bursty Access Patterns

Data Structures For IP Lookup With Bursty Access Patterns Data Structures For IP Lookup With Bursty Access Patterns Sartaj Sahni & Kun Suk Kim sahni, kskim @cise.ufl.edu Department of Computer and Information Science and Engineering University of Florida, Gainesville,

More information

The ADT Binary Search Tree

The ADT Binary Search Tree The ADT Binary Search Tree The Binary Search Tree is a particular type of binary tree that enables easy searching for specific items. Definition The ADT Binary Search Tree is a binary tree which has an

More information

Optimal Binary Search Trees Meet Object Oriented Programming

Optimal Binary Search Trees Meet Object Oriented Programming Optimal Binary Search Trees Meet Object Oriented Programming Stuart Hansen and Lester I. McCann Computer Science Department University of Wisconsin Parkside Kenosha, WI 53141 {hansen,mccann}@cs.uwp.edu

More information

Data Structures and Data Manipulation

Data Structures and Data Manipulation Data Structures and Data Manipulation What the Specification Says: Explain how static data structures may be used to implement dynamic data structures; Describe algorithms for the insertion, retrieval

More information

Binary Trees and Huffman Encoding Binary Search Trees

Binary Trees and Huffman Encoding Binary Search Trees Binary Trees and Huffman Encoding Binary Search Trees Computer Science E119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Motivation: Maintaining a Sorted Collection of Data A data dictionary

More information

Binary Coded Web Access Pattern Tree in Education Domain

Binary Coded Web Access Pattern Tree in Education Domain Binary Coded Web Access Pattern Tree in Education Domain C. Gomathi P.G. Department of Computer Science Kongu Arts and Science College Erode-638-107, Tamil Nadu, India E-mail: kc.gomathi@gmail.com M. Moorthi

More information

11 Finger Search Trees

11 Finger Search Trees 11 Finger Search Trees Gerth Stølting Brodal University of Aarhus 11.1 Finger Searching... 11-1 11.2 Dynamic Finger Search Trees... 11-2 11.3 Level Linked (2,4)-Trees... 11-3 11.4 Randomized Finger Search

More information

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

B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers B+ Tree and Hashing B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers B+ Tree Properties Balanced Tree Same height for paths

More information

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92. Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

More information

Parallelization: Binary Tree Traversal

Parallelization: Binary Tree Traversal By Aaron Weeden and Patrick Royal Shodor Education Foundation, Inc. August 2012 Introduction: According to Moore s law, the number of transistors on a computer chip doubles roughly every two years. First

More information

Sequential Data Structures

Sequential Data Structures Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year

More information

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

Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015 Data Structures Jaehyun Park CS 97SI Stanford University June 29, 2015 Typical Quarter at Stanford void quarter() { while(true) { // no break :( task x = GetNextTask(tasks); process(x); // new tasks may

More information

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

For example, we have seen that a list may be searched more efficiently if it is sorted. Sorting 1 Many computer applications involve sorting the items in a list into some specified order. For example, we have seen that a list may be searched more efficiently if it is sorted. To sort a group

More information

10CS35: Data Structures Using C

10CS35: Data Structures Using C CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(1) Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Overview on simple data structures

More information

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

Data Structures, Practice Homework 3, with Solutions (not to be handed in) Data Structures, Practice Homework 3, with Solutions (not to be handed in) 1. Carrano, 4th edition, Chapter 9, Exercise 1: What is the order of each of the following tasks in the worst case? (a) Computing

More information

6. Standard Algorithms

6. Standard Algorithms 6. Standard Algorithms The algorithms we will examine perform Searching and Sorting. 6.1 Searching Algorithms Two algorithms will be studied. These are: 6.1.1. inear Search The inear Search The Binary

More information

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

GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE AND O(n) TIME J. Patera ˆ ˆŠ Œ ˆ ˆ Œ ƒ Ÿ 2002.. 33.. 7 Š 539.12.01 GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE AND O(n) TIME J. Patera Department of Mathematics, Faculty of Nuclear Science and Physical Engineering, Czech

More information

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

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 Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number

More information

Simple Balanced Binary Search Trees

Simple Balanced Binary Search Trees Simple Balanced Binary Search Trees Prabhakar Ragde Cheriton School of Computer Science University of Waterloo Waterloo, Ontario, Canada plragde@uwaterloo.ca Efficient implementations of sets and maps

More information

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)

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) Hash Tables 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) Worst O(lg n) O(lg n) O(lg n) Table naïve array implementation

More information

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

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later). Binary search tree Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later). Data strutcure fields usually include for a given node x, the following

More information

Loop Invariants and Binary Search

Loop Invariants and Binary Search Loop Invariants and Binary Search Chapter 4.3.3 and 9.3.1-1 - Outline Ø Iterative Algorithms, Assertions and Proofs of Correctness Ø Binary Search: A Case Study - 2 - Outline Ø Iterative Algorithms, Assertions

More information

Exam study sheet for CS2711. List of topics

Exam study sheet for CS2711. List of topics Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure

More information

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

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

More information

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

Binary Search Tree. 6.006 Intro to Algorithms Recitation 03 February 9, 2011 Binary Search Tree A binary search tree is a data structure that allows for key lookup, insertion, and deletion. It is a binary tree, meaning every node of the tree has at most two child nodes, a left

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Chapter: Binary Search Trees Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Search Trees Search trees can be used

More information

An Immediate Approach to Balancing Nodes of Binary Search Trees

An Immediate Approach to Balancing Nodes of Binary Search Trees Chung-Chih Li Dept. of Computer Science, Lamar University Beaumont, Texas,USA Abstract We present an immediate approach in hoping to bridge the gap between the difficulties of learning ordinary binary

More information

DYNAMIC DOMAIN CLASSIFICATION FOR FRACTAL IMAGE COMPRESSION

DYNAMIC DOMAIN CLASSIFICATION FOR FRACTAL IMAGE COMPRESSION DYNAMIC DOMAIN CLASSIFICATION FOR FRACTAL IMAGE COMPRESSION K. Revathy 1 & M. Jayamohan 2 Department of Computer Science, University of Kerala, Thiruvananthapuram, Kerala, India 1 revathysrp@gmail.com

More information

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

THIS CHAPTER studies several important methods for sorting lists, both contiguous Sorting 8 THIS CHAPTER studies several important methods for sorting lists, both contiguous lists and linked lists. At the same time, we shall develop further tools that help with the analysis of algorithms

More information

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

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139 ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139 Instructions: No aides. Turn off all electronic media and store them under your desk. If

More information

Binary Heaps. CSE 373 Data Structures

Binary Heaps. CSE 373 Data Structures Binary Heaps CSE Data Structures Readings Chapter Section. Binary Heaps BST implementation of a Priority Queue Worst case (degenerate tree) FindMin, DeleteMin and Insert (k) are all O(n) Best case (completely

More information

DNS LOOKUP SYSTEM DATA STRUCTURES AND ALGORITHMS PROJECT REPORT

DNS LOOKUP SYSTEM DATA STRUCTURES AND ALGORITHMS PROJECT REPORT DNS LOOKUP SYSTEM DATA STRUCTURES AND ALGORITHMS PROJECT REPORT By GROUP Avadhut Gurjar Mohsin Patel Shraddha Pandhe Page 1 Contents 1. Introduction... 3 2. DNS Recursive Query Mechanism:...5 2.1. Client

More information

Zabin Visram Room CS115 CS126 Searching. Binary Search

Zabin Visram Room CS115 CS126 Searching. Binary Search Zabin Visram Room CS115 CS126 Searching Binary Search Binary Search Sequential search is not efficient for large lists as it searches half the list, on average Another search algorithm Binary search Very

More information

Why Use Binary Trees?

Why Use Binary Trees? Binary Search Trees Why Use Binary Trees? Searches are an important application. What other searches have we considered? brute force search (with array or linked list) O(N) binarysearch with a pre-sorted

More information

Computer Science 210: Data Structures. Searching

Computer Science 210: Data Structures. Searching Computer Science 210: Data Structures Searching Searching Given a sequence of elements, and a target element, find whether the target occurs in the sequence Variations: find first occurence; find all occurences

More information

DATABASE DESIGN - 1DL400

DATABASE DESIGN - 1DL400 DATABASE DESIGN - 1DL400 Spring 2015 A course on modern database systems!! http://www.it.uu.se/research/group/udbl/kurser/dbii_vt15/ Kjell Orsborn! Uppsala Database Laboratory! Department of Information

More information

Data Structures UNIT III. Model Question Answer

Data Structures UNIT III. Model Question Answer Data Structures UNIT III Model Question Answer Q.1. Define Stack? What are the different primitive operations on Stack? Ans: Stack: A stack is a linear structure in which items may be added or removed

More information

Chapter 13: Query Processing. Basic Steps in Query Processing

Chapter 13: Query Processing. Basic Steps in Query Processing Chapter 13: Query Processing! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions 13.1 Basic Steps in Query Processing 1. Parsing

More information

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

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate

More information

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

Introduction Advantages and Disadvantages Algorithm TIME COMPLEXITY. Splay Tree. Cheruku Ravi Teja. November 14, 2011 November 14, 2011 1 Real Time Applications 2 3 Results of 4 Real Time Applications Splay trees are self branching binary search tree which has the property of reaccessing the elements quickly that which

More information

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

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

More information

Algorithms. Margaret M. Fleck. 18 October 2010

Algorithms. Margaret M. Fleck. 18 October 2010 Algorithms Margaret M. Fleck 18 October 2010 These notes cover how to analyze the running time of algorithms (sections 3.1, 3.3, 4.4, and 7.1 of Rosen). 1 Introduction The main reason for studying big-o

More information

Binary Search Trees. basic implementations randomized BSTs deletion in BSTs

Binary Search Trees. basic implementations randomized BSTs deletion in BSTs Binary Search Trees basic implementations randomized BSTs deletion in BSTs eferences: Algorithms in Java, Chapter 12 Intro to Programming, Section 4.4 http://www.cs.princeton.edu/introalgsds/43bst 1 Elementary

More information

Data storage Tree indexes

Data storage Tree indexes Data storage Tree indexes Rasmus Pagh February 7 lecture 1 Access paths For many database queries and updates, only a small fraction of the data needs to be accessed. Extreme examples are looking or updating

More information

Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor

Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor The Further Education and Training Awards Council (FETAC) was set up as a statutory body on 11 June 2001 by the Minister for Education and Science. Under the Qualifications (Education & Training) Act,

More information

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.

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. 1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The

More information

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

Exercises Software Development I. 11 Recursion, Binary (Search) Trees. Towers of Hanoi // Tree Traversal. January 16, 2013 Exercises Software Development I 11 Recursion, Binary (Search) Trees Towers of Hanoi // Tree Traversal January 16, 2013 Software Development I Winter term 2012/2013 Institute for Pervasive Computing Johannes

More information