Frage

As C++ sets are implemented in binary trees, if we insert items in incremental or decremental order, then the set would be more a list than a tree. Is there any method to balance the tree AFTER items are inserted?

War es hilfreich?

Lösung

C++ sets (i.e. std::set) are usually implemented as red-black trees. They are self balancing.

However it is implemented, your suggestion that the set would become more like a list cannot happen, because the standard makes complexity guarantees which cannot be fulfilled by a list.

Andere Tipps

Although the standard imposes no restrictions on the implementation, it's usually a red-black tree. So the library deal with it well, and don't worry about it

Look this problem

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top