splay-tree

Method to Display a Splay Tree

坚强是说给别人听的谎言 提交于 2019-12-23 02:38:21
问题 I have built a splay tree and I am trying to print it out reverse in order so that when you turn your head to the left you can see the tree in a normal manner. I have written the following code and it outputs the tree somewhat correctly but it adds extra spaces in on the rightmost node and it doesn't add spaces for all of the child nodes that should be placed below the root node: public void printReverseInOrder() { if (root != null) { reverseInOrder(root, 0); } else { System.out.println(); }

Recursive Splay Tree

99封情书 提交于 2019-12-22 10:30:54
问题 I am trying to implement a recursive splay tree, bottom up. I recurse down to the node I am need to splay up, and I find the parent and grandparent of that node. Then I am able to either zig zag or zig zig depending on the situation just fine. The problem is after this is done, I return the node which has been splayed once to the previous recursive call. The previous recursive call is referenced to the parent of the node, which is now the child of that node. How do I recurse up splaying the

Method to Display a Splay Tree

心已入冬 提交于 2019-12-07 16:03:26
I have built a splay tree and I am trying to print it out reverse in order so that when you turn your head to the left you can see the tree in a normal manner. I have written the following code and it outputs the tree somewhat correctly but it adds extra spaces in on the rightmost node and it doesn't add spaces for all of the child nodes that should be placed below the root node: public void printReverseInOrder() { if (root != null) { reverseInOrder(root, 0); } else { System.out.println(); } } public void reverseInOrder(BSTnode h, int indent) { if (h != null) { for (int i = 0; i < indent; i++)

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

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