Questions tagged [splay-tree]

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

64 questions
49
votes
2 answers

Difference between AVL trees and splay trees

I am studying about various trees, and came across AVL trees and splay trees. I want to know What is difference between AVL trees and splay trees? On what basis do we select these tress? What are positive's and negative's of these trees? What are…
venkysmarty
  • 10,013
  • 19
  • 87
  • 165
6
votes
2 answers

Is std::map allowed to re-balance after read-only operations (like a Splay tree)

Some binary tree data structures (such as Splay trees) will re-balance on reads to move recently accessed items toward the root, such that the subsequent look-up time may be reduced. Are the standard containers (std::map, std::set) allowed to do…
Darren Engwirda
  • 6,660
  • 3
  • 19
  • 41
6
votes
1 answer

amortized cost of splay tree : cost + P(tf) - P(ti) ≤ 3(rankf(x) - ranki(x)) explanation

While reading about splay trees I found some expression about the rank of the splay node 'X' and the amortized cost in wikipedia. It is given as, { We can bound the amortized cost of any zig-zig or zig-zag operation by: amortized cost = cost + P(tf)…
poddroid
  • 795
  • 12
  • 26
6
votes
1 answer

Intuition behind splay tree (self balancing trees)

I am reading the basics of splay trees. The amortized cost of an operation is O(log n) over n operations. Some rough basic idea is that when you access a node, you splay it i.e. you take it to root so next time this is quickly accessed and also if…
xyz
  • 7,885
  • 15
  • 61
  • 88
6
votes
3 answers

How can I implement a splay tree that performs the zig operation last, not first?

For my Algorithms & Data Structures class, I've been tasked with implementing a splay tree in Haskell. My algorithm for the splay operation is as follows: If the node to be splayed is the root, the unaltered tree is returned. If the node to be…
Jakob
  • 2,329
  • 4
  • 25
  • 33
6
votes
1 answer

A sequence that forms the same AVL and splay trees?

Is there such a sequence of numbers (1-7, all numbers used, only once each), that would form equal AVL and splay tree?
4
votes
1 answer

ZigZag and ZigZig operation in splay tree?

consider my tree is like this 5 / \ 3 7 / \ / \ 2 4 6 8 in that, when we search a element 2 that time zigzig operation will be performed, so first we rotate the parent…
Bhuvanesh
  • 1,203
  • 1
  • 12
  • 23
4
votes
3 answers

Splay tree insertion

Going through some excercises to hone my binary tree skills, I decided to implement a splay tree, as outlined in Wikipedia: Splay tree. One thing I'm not getting is the part about insertion. It says: First, we search x in the splay tree. If x does…
Lasse V. Karlsen
  • 350,178
  • 94
  • 582
  • 779
3
votes
3 answers

Why are persistent splay trees particularly useful in functional programming?

On the Splay Trees Wikipedia page it is said (in the Advantages section): Possibility of creating a persistent data structure version of splay trees—which allows access to both the previous and new versions after an update. This can be useful in…
Iulius Curt
  • 4,526
  • 4
  • 28
  • 51
3
votes
0 answers

How to manipulate a string (move substring to other part of string) in O(log n) using a rope or an order statistics splay tree

Two weeks ago I've finished an implementation of a splay tree that allows basic functions, like insert, delete, find key and and obtain the sum of a range of elements of the three. You can find this implementation here as reference for this question…
Nooblhu
  • 525
  • 12
  • 32
3
votes
2 answers

Is there any faster implementation for this Splay Tree range sum?

I have coded a splay tree. The nodes are represented like this. struct Node{ Node *l; /// The left Node Node *r; /// The right Node int v; /// The Value }; Now, I need to know the summation of all the numbers in the tree within a…
jbsu32
  • 856
  • 1
  • 9
  • 27
3
votes
2 answers

What is the Difference between Bottom-up and Top down methods in splay tree?

I have read about Splay tree and I found,there are two methods for constructing the splay tree. They are Bottom-up Top-down So I need to know What is the difference between the two methods and their working ?
Bhuvanesh
  • 1,203
  • 1
  • 12
  • 23
3
votes
1 answer

When I traverse in the splay tree, then now which one is root?

I had a doubt when we are using a splay tree, the last accessed element will come to the root node. consider my tree is 5 / \ 3 7 / \ / \ 2 4 6 …
Bhuvanesh
  • 1,203
  • 1
  • 12
  • 23
3
votes
2 answers

Recursive Splay Tree

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…
Andrew
  • 31
  • 2
3
votes
0 answers

Determining if a binary search tree can be constructed by a sequence of splay tree insertions

A splay tree is a type of self-adjusting binary search tree. Inserting a node into a splay tree involves inserting it as a leaf in the binary search tree, then bringing that node up to the root via a "splay" operation. Let us say a binary search…
augurar
  • 9,426
  • 4
  • 40
  • 57
1
2 3 4 5