avl-tree

Search max value between 2 AVL nodes [duplicate]

懵懂的女人 提交于 2019-12-19 10:25:48
问题 This question already has an answer here : AVL Tree: Finding the key with the smallest data values in keys between two values in O(logn) time (1 answer) Closed 4 years ago . I have an AVL tree while each node consists of: Key Value The AVL tree is ordered by the keys . So if I got 2 keys and now I want to find the maximum value between those 2 keys. I've tried adding additional information to each node like the max value in the left subtree and same for the right subtree but I can't get the

AVL tree in C language

江枫思渺然 提交于 2019-12-12 19:06:40
问题 i am currently doing a project that requires the use of AVL trees , the insert function i wrote for the avl does not seem to be working , it works for 3 or 4 nodes at maximum ; i would really appreciate your help The attempt is below Tree insert(Tree t,char name[80],int num) { if(t==NULL) { t = (Tree)malloc(sizeof(struct node)); if(t! = NULL) { strcpy(t->name,name); t->num = num; t->left = NULL; t->right = NULL; t->height = 0; } } else if(strcmp(name,t->name)<0) { t->left = insert(t->left

Handling duplicates keys within an AVL tree

扶醉桌前 提交于 2019-12-12 07:50:01
问题 I want to make my avl-tree support duplicate keys but there is a problem with the default behavior of the binary search tree with duplicates that the rotation could make nodes with equal key be on the left and the right of the parent. For example when adding three nodes all with key A will cause the tree to do a rotation to be something like this: A / \ A A So getting all the entries with that key will be a problem...and searching in both direction is not good. The solution that i have

Calculating the balance factor of a node in avl tree

試著忘記壹切 提交于 2019-12-12 04:32:10
问题 I want to calculate the balance factor of a node in avl tree without using any recursive procedure. How can i do that? Please tell me method or provide C++ code snippet. 回答1: You can save the balance factor as a part of the information each node saves. Specifically, you can save the height of the left and right subtrees, and update the values with every insertion/deletion on the insertion/deletion path. Example: class Node { public: // stuff... int GetBF() { return lHeight - rHeight; }

Implementing Bentley–Ottmann Algorithm with an AVL tree

心已入冬 提交于 2019-12-11 20:34:47
问题 I'm having a problem implementing this method in java. I'm specifically implementing the algorithm FINDINTERSECTIONS in Computational Geometry 3rd Edition using an AVL BST tree for the status. The description from the book is shown below: The problem I'm having is implementing step 5 in HANDLEEVENTPOINT . When the event point is an intersection, the status is no longer totally ordered there, because for intersection lines, they cross at their intersection point and need to be swapped in the

Searching a node with balance factor of -2 in an AVL tree

大城市里の小女人 提交于 2019-12-11 14:15:35
问题 I know how to search a node with a particular key into an AVL tree . But I want to know how to search in an AVL tree with a balance factor of -2 Here is the code that I have tried. void searchForUnrequiredBalanceFactor(avlnode *n , avlnode *r) { avlnode *ptr ; ptr = n ; if (ptr==NULL) return; else { if (ptr ->balFact == -2) { r = ptr ; return ; } else { searchForUnrequiredBalanceFactor(ptr->left,r); searchForUnrequiredBalanceFactor(ptr->right,r); } } } But the code isn't working as required ,

Formula for finding number of possible AVL trees with n nodes

℡╲_俬逩灬. 提交于 2019-12-11 11:56:54
问题 let the number of nodes be 3. If a,b,c.. are in order c>a>b then possible avl trees are: n=1 gives 1,n=2 gives 2..(look image) As we know for a BST it is 2n C n/ (n+1). Have anyone tried to deduce a formula that can find the number of avl trees when the number of nodes are given. example question:what is the number of possible avl trees with 11 nodes? 回答1: I doubt that simple formula exists. But you can find number of possible AVL trees with dynamic programming, filling 2D table, where n is

Keeping avl tree balanced without rotations

半世苍凉 提交于 2019-12-11 09:29:44
问题 B Tree is self balancing tree like AVL tree. HERE we can see how left and right rotations are used to keep AVL tree balanced. And HERE is a link which explains insertion in B tree. This insertion technique does not involve any rotations, if I am not wrong, to keep tree balanced. And therefore it looks simpler. Question: Is there any similar (or any other technique without using rotations) to keep avl tree balanced ? 回答1: The answer is... yes and no. B-trees don't need to perform rotations

Performance of an AVL Tree in C#

不想你离开。 提交于 2019-12-11 06:59:49
问题 I have implemented an AVL tree in C# whose insertion matrix is as follows Number of Elements Time taken to insert (sec) ------------------------------------------------------ 10 0.067 100 0.073 200 0.112 500 0.388 900 1.205 1000 1.466 5000 44.314 10000 195.435 Now my question is, is it a good performance for an AVL tree or do I have to re-consider changing the algorithm or refactoring the code? Edit: The elements are integer starting from 0 to #of elements Test code is as follows [Test]

multiple AVL tree rotation

泄露秘密 提交于 2019-12-11 06:49:58
问题 Say i have a unordered set s{3,6,5,1,2,4} and i need to construct an AVL tree, this much is fine... i understand basic rotations and i get to this point here: 5 / \ 2 6 / \ 1 3 but it all falls apart when i try to insert 4 and i get my final answer as (the left one) 4 But the actual answer is: 3 / \ / \ 2 5 2 5 / \ \ / / \ 1 3 6 1 4 6 And when i break it down i get stuck doing the same rotation so im asking how do i do a rotation with the parent that is valid for this AVL? and is my solution