avl-tree

Computational Complexity of TreeSet methods in Java

偶尔善良 提交于 2019-12-05 07:55:55
Is the computational complexity of TreeSet methods in Java, same as that of an AVLTree? Specifically, I want to know the computational complexity of the following methods: 1.add 2.remove 3.first 4.last 5. floor 6. higher Java Doc for method description: http://docs.oracle.com/javase/6/docs/api/java/util/TreeSet.html For an AVL Tree, there are all O(logn)? Whats the complexity of the above TreeSet Methods? Operations which work on a single element are all O(ln n) comparisons except first and last which are O(1) comparisons or O(ln N) node search time. comparator(), iterator(), clear(), first(),

Implementing an AVL tree in JAVA

三世轮回 提交于 2019-12-05 04:56:30
问题 I want to implement an AVL Tree in Java, here is what I have so far: public class AVLNode { private int size; /** The size of the tree. */ private int height; /** The height of the tree. */ private Object key;/** The key of the current node. */ private Object data;/** The data of the current node. */ private Comparator comp;/** The {@link Comparator} used by the node. */ /* All the nodes pointed by the current node.*/ private AVLNode left,right,parent,succ,pred; /* Instantiates a new AVL node

A sequence that forms the same AVL and splay trees?

自古美人都是妖i 提交于 2019-12-04 22:51:17
问题 Is there such a sequence of numbers (1-7, all numbers used, only once each), that would form equal AVL and splay tree? 回答1: Well, in the interests of science, I implemented both AVL and splay trees in Python based on their respective Wikipedia articles. Assuming I didn't make a mistake somewhere, my finding is that there are no permutations of {1, ..., 7} that produce the same AVL and splay tree . I conjecture the same is true for all sets of size k > 3. As to the fundamental reasons for this

Is kd-tree always balanced?

放肆的年华 提交于 2019-12-04 18:48:43
问题 I have used kd-tree algoritham and make tree. But i found that tree is not balanced so my question is if we used kd-tree algoritham then that tree is always balanced if not then how can we make it balance ?. We can use another algoritham likes AVL or Red-Black for balancing kd tree ? I have some sample data for that i used kd-tree algoritham but that tree is not balanced. (14,31), (15,32), (17,42), (16,44), (18,52), (16,62) 回答1: This is a fairly broad topic and the questions themselves are

A sequence that forms the same AVL and splay trees?

旧巷老猫 提交于 2019-12-03 14:45:54
Is there such a sequence of numbers (1-7, all numbers used, only once each), that would form equal AVL and splay tree? Well, in the interests of science, I implemented both AVL and splay trees in Python based on their respective Wikipedia articles. Assuming I didn't make a mistake somewhere, my finding is that there are no permutations of {1, ..., 7} that produce the same AVL and splay tree . I conjecture the same is true for all sets of size k > 3. As to the fundamental reasons for this, I have no idea. If someone would like to vet my code, here it is: ##################### # Class

What is the minimum sized AVL tree where a deletion causes 2 rotations?

我的未来我决定 提交于 2019-12-03 14:26:57
It is well known that deletion from an AVL tree may cause several nodes to eventually be unbalanced. My question is, what is the minimum sized AVL tree such that 2 rotations are required (I'm assuming a left-right or right-left rotation is 1 rotation)? I currently have an AVL tree with 12 nodes where deletion would cause 2 rotations. My AVL tree is inserting in this order: 8, 5, 9, 3, 6, 11, 2, 4, 7, 10, 12, 1. If you delete the 10, 9 becomes unbalanced and a rotation occurs. In doing so, 8 becomes unbalanced and another rotation occurs. Is there a smaller tree where 2 rotations are necessary

Is kd-tree always balanced?

扶醉桌前 提交于 2019-12-03 12:35:05
I have used kd-tree algoritham and make tree. But i found that tree is not balanced so my question is if we used kd-tree algoritham then that tree is always balanced if not then how can we make it balance ?. We can use another algoritham likes AVL or Red-Black for balancing kd tree ? I have some sample data for that i used kd-tree algoritham but that tree is not balanced. (14,31), (15,32), (17,42), (16,44), (18,52), (16,62) This is a fairly broad topic and the questions themselves are kind of general. Hopefully this will give you some useful insights and material to work with: Kd tree is not

Finding the minimum and maximum height in a AVL tree, given a number of nodes?

て烟熏妆下的殇ゞ 提交于 2019-12-03 05:15:52
问题 Is there a formula to calculate what the maximum and minimum height for an AVL tree, given a certain number of nodes? For example: Textbook question: What is the maximum/minimum height for an AVL tree of 3 nodes, 5 nodes, and 7 nodes? Textbook answer: The maximum/minimum height for an AVL tree of 3 nodes is 2/2, for 5 nodes is 3/3, for 7 nodes is 4/3 I don't know if they figured it out by some magic formula, or if they draw out the AVL tree for each of the given heights and determined it that

How to generate maximally unbalanced AVL trees

老子叫甜甜 提交于 2019-12-03 04:55:42
问题 I have written a C language library of AVL trees as general purpose sorted containers. For testing purposes, I would like to have a way to fill a tree so that it is maximally unbalanced, i.e., so that it has the maximum height for the number of nodes it contains. AVL trees have the nice property that if, starting from the empty tree, you insert nodes in ascending (or descending) order, the tree is always exactly balanced (i.e., it has its minimum height for a given number of nodes). One

When to choose RB tree, B-Tree or AVL tree?

喜夏-厌秋 提交于 2019-12-03 01:30:49
问题 As a programmer when should I consider using a RB tree, B- tree or an AVL tree? What are the key points that needs to be considered before deciding on the choice? Can someone please explain with a scenario for each tree structure why it is chosen over others with reference to the key points? 回答1: Take this with a pinch of salt: B-tree when you're managing more than thousands of items and you're paging them from a disk or some slow storage medium. RB tree when you're doing fairly frequent