3

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 tree is "splay-constructible" if the tree can be produced by inserting its elements into an initially empty splay tree in some order.

Not all binary search trees are splay-constructible. For example, the following is a minimal non-splay-constructible binary search tree:

BST with preorder traversal (1, -, 3, 2, -)

What is an efficient algorithm that, given a binary search tree, determines whether it is splay-constructible?

This question was inspired by a related question regarding concordance between AVL and splay trees.

More details: I have code to generate a splay tree from a given sequence, so I could perform a brute-force test in O(n! log(n)) time or so, but I suspect polynomial time performance is possible using some form of dynamic programming over the tree structure. Presumably such an algorithm would exploit the fact that every splay-constructible tree of size n can be produced by inserting the current root into some splay-constructible tree of size n-1, then do something to take advantage of overlapping/isomorphic subproblems.

Community
  • 1
  • 1
augurar
  • 9,426
  • 4
  • 40
  • 57
  • What do you already know? – Niklas B. Mar 14 '14 at 19:17
  • @NiklasB. Very little beyond the definition of splay trees (which I only learned yesterday). – augurar Mar 14 '14 at 19:20
  • Any ideas, intuitions, feelings, code? Or basically just dropping an assignment here? – Niklas B. Mar 14 '14 at 19:21
  • @NiklasB. I have some code to generate a splay tree from a given insertion sequence (see [my answer](http://stackoverflow.com/a/22399494/2572431) to the linked question). This isn't for school, just personal interest. – augurar Mar 14 '14 at 19:23
  • Having been on [so] for a while already, you should know to show an attempt at solving the problem (regardless of where the problem came from) - others may be less forgiving, but I really don't mind if you even just share a few thoughts you've had in trying to come to a solution (assuming you're happy with a high-level approach and/or hints as an answer). The code in the linked answer doesn't appear to be solving this problem, so that doesn't really count, in my opinion. – Bernhard Barker Mar 14 '14 at 19:28
  • @Dukeling The code can be used to solve the problem, albeit very inefficiently; see my edit to the question. – augurar Mar 14 '14 at 23:16
  • "dynamic programming over the tree structure" is good, but it's not polynomial because there are *Cn* possible binary search trees formed by *n* nodes. I doubt the valid splay trees are an exponentially small subset of that – Niklas B. Mar 14 '14 at 23:18
  • @NiklasB. Maybe it could be, with some clever problem reduction. – augurar Mar 14 '14 at 23:20
  • You know that the root of a splay-constructible tree must be the last item inserted AND you know that there must be a sequence of inverse splay operations such that the resultant tree has the root as a leaf and the remaining tree when the root is removed is still splay-constructible. I wonder if looking at all possible sequences of inverse splays produces a small enough search space to make this slightly feasible. There are a small number of possible splays and you only need log n of them (on average) for each node you remove. – Jeremy West Feb 12 '15 at 02:15
  • But the real trick is that part: Can you determine the set of possible inverse splay sequences that move the root of a tree to a leaf while still preserving the ordering of the tree. – Jeremy West Feb 12 '15 at 02:17

0 Answers0