Just like multiset is a Binary Search Tree implementation in STL, is there any RB tree or AVL tree implementation available?
-
5std::map is a red/black tree. The standard doesn't say it must be one, but the performance guarantees make it unlikely that something else would be used. – Mar 04 '17 at 15:26
-
2Pretty sure that most standard library implementations use RB trees for all four of (multi)set|map. The standard doesn't specify the implementation though. – Zulan Mar 04 '17 at 15:26
2 Answers
Normally you would not implement a multiset
as a binary search tree. Using one would break the performance guarantees of the standard as the tree could wind up looking like a linked list which does not have O(logN) insert and removals.
Typically std::set
/std::multiset
/std::map
/std::multimap
are implemented as a RB tree as it has those performance guarantees. This is not required though. The standard only guarantees the performance of the container in different operations and it is up to the implementation how to achieve that.
If you want to guarantee you are using an RB tree you either need to check your implementation, roll your own, or get a third party library that guarantees it is a RB tree.

- 171,901
- 28
- 288
- 402
From what I was told on my post is No, there is not a standard C++ library yet for Red-Black Trees as of today, January 10th, 2022.
-
But I can give out a red black tree function that can be available for everyone to use. – Apr 07 '22 at 02:11
-