* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download I Semester I, 2007-08 Submitted By :Y6279 and Y6154
Survey
Document related concepts
Transcript
ESO211/CS210 Data Structures and Algorithms - I Semester I, 2007-08 Submitted By :Y6279 and Y6154 Programming Assignment : OBJECTIVE: The aim of this exercise is to compare the performance of the following data structures for maintaining a set of integers in a fixed range [0, 216−1] 1. Binary Search Tree 2. Red-Black Tree 3. van Emde Boas (vEB) Queues BINARY SEARCH TREE: A binary search trees (BST) is the most non-trivial and yet the most useful data structure. It has numerous applications. A binary search tree (BST) is a binary tree data structure which has the following properties: • • • • each node has a value; a total order is defined on these values; the left subtree of a node contains only values less than the node's value; the right subtree of a node contains only values greater than or equal to the node's value. It supports the following operations the following operations : • Search(S , x) • Delete(S , x) • Insert(S , x) • predecessor(S , x) • Successor(S , x) RED BLACK TREE: A red-black tree is a binary search tree data structure , i.e. most of the common operations (such as insert, delete, search, predecessor, successor etc.) are performed in O(h) time where h is tree height. In a red-black tree each node has a color which can be either Red or Black. The also contains a NULL object which is black, and for each node if its parent or children do not exist, it should point to the tree null object. Properties satisfied by a red-black tree: 1. Every node is either red or black. 2. Every leaf is black(i.e. every leaf is the tree null object). 3. Every red node has two black children. 4. Every simple path from a node to a descendant leaf contains the same number of black nodes. VEB QUEUES: A van Emde Boas tree (or van Emde Boas priority queue), also known as a vEB tree, is a tree data structure which implements an associative array with m‐bit integer keys. It performs all operations in O(log m) time. Notice that m is the size of the keys — therefore O(log m) is O(log log n) in a full tree, exponentially better than a self‐balancing binary search tree. They also have good space efficiency when they contain a large number of elements . Supported operations: The operations supported by a vEB tree are those of an ordered A, which includes the usual associative array operations along with two more order operations, SUCCESSOR and PREDESSOR : • • • • • Insert: insert a key/value pair with an m‐bit key Delete: remove the key/value pair with a given key SEARCH: find the value associated with a given key SUCCESSOR: find the key/value pair with the smallest key at least a given k PREDESSOR: find the key/value pair with the largest key at most a given k DATA STRUCTURE BST RB TREE VEB TREE INSERT(S,x) SEARCH(S,x) PREDESSOR(S,x) Log(n) Log(n) Log(log(n)) Log(n) Log(n) Log(log(n)) Log(n) Log(n) Log(log(n)) OBSERVATIONS: Color code for the graph: Green :bst Blue: rb tree Red: veb tree 1. Time for inserting is minimum for the veb trees. Out of bst and rb tree ,rb tree take more time to insert the numbers (to build the tree) . This is evident since insert operation takes O(log(log(n))) time as compared to O(log(n)) time for inserting in rb tree and bst. 2. For the search operation, though the three data structures take almost comparable time for small sixe of trees,, but for the asymptodically large size of the inputs (size of tree) veb tree takes minimum time ( O(log(log(n))) ) than the rb tree and the bst . The graph resembles clog(n) for large values of n for rb tree and bst . 3. For finding the predecessor , for small size of the tree, rb tree is the most efficient and veb happens to be least efficient . Whereas for large size of the tree bst is the least effective and veb trees are the most effective data structure to be used. 4. It should be noted that the maximum height of the tree in case of red black tree is 2(log(n+1)) , whereas in binary search tree the height is larger than the height of the rb tree(it can even be n in the worst case) . SWo bst should take more time to search than rb tree. Although it can be proved that the average height of the randomized binary tree for n distinct keys is O(log(n)). 5. Insert operation takes larger time in rb tree than bst because in addition to inserting we have to do the color balance as well. 6. As far as the space complexity is concerned binary tree takes less space than rb tree because in bst we have to store only parent , left and the right node only whereas in rb tree we have to color additionally. All the three data structures take O(n) space. CONCLUSION: If we have integer inputs veb trees happens to be the best data structure for insert , delete and search operations.