Questions tagged [splay-tree]

A splay tree is a self-adjusting binary search tree with excellent amortized performance.

70 questions
1
vote
2 answers

Range function for values in a splay tree?

I am a beginner at data structures. I am trying to write some pseudocode for a range function with splay trees: Range(S, A, B), which changes S to the set of all its members for which the key value C satisfies A ≤ C ≤ B. I know a splay trees fall…
1
vote
1 answer

Calculating a Sum Range in a Splay Tree

I need to calculate a range sum using a splay tree. I have implemented Insert,Find,Remove and Splay methods and they are working fine, But i'm having trouble with calculating the summation of a given range in the tree. Note: The trees in the test…
Alireza Moradi
  • 308
  • 3
  • 10
1
vote
0 answers

Clarity regarding deletion in a splay tree

I am writing a code for splay tree but I have doubts regarding the deletion aspect of the splay tree. After researching about it on the internet, this is what I found: First search the element to be deleted and splay it to the top.Then do the…
Souvik Ray
  • 2,899
  • 5
  • 38
  • 70
1
vote
1 answer

Using a 2-3-4 tree instead of a splay tree

I'm in a data structures course right now and we learned about 2-3-4 trees and splay trees. I was wondering in what circumstances would you use a 2-3-4 tree instead of a splay tree? They're both self balancing and sorted so I don't see that much…
user479988
  • 56
  • 5
1
vote
1 answer

Splay trees: how do the zig-zig and zig-zag rotations work, in details?

I need help understanding a specific example of zig-zag and zig-zig rotations in splay trees. I have read about them in a book, and on Wikipedia as well as a few other online resources, and whilst I can understand them when they are applied on…
Pauline
  • 3,566
  • 8
  • 23
  • 39
1
vote
1 answer

Splay tree: does an inorder traversal look at nodes in increasing order for a splay tree?

I just finished an exam on this, where I used an inorder traversal to check correct node order in one of my splay trees. Is this valid?
Chicken Crimpy
  • 91
  • 1
  • 2
  • 6
1
vote
1 answer

Strange bug in my splay tree implementation

I am attempting to write a C++ template struct for a splay tree, but when I try to test the code, I am getting very strange results. This is my code for the template: template struct splaytree { struct node { splaytree
1
vote
2 answers

Splay tree: worst-case sequence

I want to try trying executing the worst-case sequence on Splay tree. But what is the worst-case sequence on Splay-trees? And are there any way to calculate this sequence easily given the keys which is inserted into the tree? Any can help me with…
1
vote
1 answer

C++ Implementation of Splay Tree

So I was to implement Splay function after inserting a new tree. However, when I tried to insert multiple ints it says Segmentation Fault (core dump) then exit. Can anyone check where my problem is? void SplayTree::splay(Node* node) { if (node…
Walle
  • 197
  • 1
  • 10
1
vote
1 answer

On a Splay tree (top-down splaying version), how do I maintain node invariants?

I am trying to implement a Splay tree with top-down splaying, like the one described here (http://www.nocow.cn/index.php/Code:Splay_Tree/C) (first one). I have already implemented a bottom-up splaying version which also maintains the subtree-size at…
pratyai
  • 21
  • 2
1
vote
1 answer

Time Complexity of the makeEmpty() of the Top-Down splay tree

In this implementation of a splay tree, the listed time complexity of the makeEmpty() function (which removes all elements) is O(n). It is implemented as follows: while( !isEmpty( ) ) { findMax( ); // Splay max item to root …
1
vote
2 answers

Does the subtree under x being splayed become necessarily balanced after the splay operation?

Here is the problem: Let T be a splay tree on n nodes, and let x be a node of T. Consider a splay operation at x. Does the subtree under x become necessarily balanced (i.e., the height of the subtree rooted at x in the splay tree becomes O(logn)…
Bi Wu
  • 55
  • 5
1
vote
1 answer

Null Pointer Splay Tree

Im working on a right rotate method for a splay tree. I keep getting a null pointer exception when I try to run my program but im not sure why. This is my tree 5 / 2 / 1 this is where i get the null pointer, its on the lr…
user214577
  • 363
  • 1
  • 7
  • 15
1
vote
1 answer

Java Pass object to method

I have a program that allows the user to choose between a binary search tree a splay tree and a red black tree. I wrote the class for the binary search tree and now im working on the splay tree but ive realized that my method that interacts with the…
user214577
  • 363
  • 1
  • 7
  • 15
1
vote
1 answer

Method to Display a Splay Tree

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…
clifgray
  • 4,313
  • 11
  • 67
  • 116