Search code examples
red-black-tree

How to insert ascending numbers in a Red Black Tree


Can someone show me a step by step tutorial on how to insert numbers 1-10 in a Red-black tree?

I already tried doing so but I seem to be failing

*by insert I mean adding 1,2,3,4,5,6,7,8,9,10 in an initially empty rbt. thanks!


Solution

  • It depends on what you mean by " insert numbers 1-10 in a Red-black tree":

    • If you mean a legal tree obtained from these values, you can build a red-black tree from an ordered vector in linear time.

    • If you mean a visualization of 10 insert operations, you can try here.

    Drawn with the help of the link mentioned here