1

When we are inserting into a self-balancing tree, can we also assume it is sorting itself using those same operations? Or rather is there a traversal method that gets us the elements as a sorted list?

geocodezip
3903 gold badges5 silver badges11 bronze badges
asked Oct 22, 2019 at 17:53
3
  • 2
    Possible duplicate of Which self balancing binary tree would you recommend? Commented Oct 22, 2019 at 18:24
  • How could it be a possible duplicate? That thread doesn't discuss whether the balanced trees are sorted or not. Commented Oct 22, 2019 at 18:31
  • What do you mean by "sorted"? Commented Oct 22, 2019 at 18:51

1 Answer 1

4

Self-balancing trees are required to maintain their structure so that the keys are always sorted (that is, so an inorder traversal of the tree results in all the elements in order). If your rotations are producing a tree that is no longer in order, then your rotations are incorrect. Keys can move "vertically" (children can become parents, and vice-versa), but are always required to maintain their relative position.

answered Oct 22, 2019 at 18:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.