Trees
Trees organize their elements in a hierarchical branched structure (hence the name) and are very good when we are searching for items. Due to their hierarchical organization, the search has the O(log n) complexity (assuming a well-balanced, nondegenerate tree). However, the same caveats as with lists apply—there are bad memory locality and dynamic allocations.
But the search times are very nice indeed. Could we keep them, somehow? Well, if we wanted to maintain this search speed, we could replace a tree structure with a sorted array, assuming we won't be changing it often. For a more general case, there is a Boost implementation of flat_map which projects the tree structure onto an array, preserving the hierarchies but improving the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access