Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good and stable C++ tree implementation?

I'm wondering if anyone can recommend a good C++ tree implementation, hopefully one that is stl compatible if at all possible.

For the record, I've written tree algorithms many times before, and I know it can be fun, but I want to be pragmatic and lazy if at all possible. So an actual link to a working solution is the goal here.

Note: I'm looking for a generic tree, not a balanced tree or a map/set, the structure itself and the connectivity of the tree is important in this case, not only the data within. So each branch needs to be able to hold arbitrary amounts of data, and each branch should be separately iterateable.

like image 363
Robert Gould Avatar asked Oct 08 '08 07:10

Robert Gould


People also ask

What is the best use for a tree algorithm?

Tree based algorithms empower predictive models with high accuracy, stability and ease of interpretation. Unlike linear models, they map non-linear relationships quite well. They are adaptable at solving any kind of problem at hand (classification or regression).

Does STL have binary tree?

Given a Binary Tree, convert it to a Binary Search Tree. The conversion must be done in such a way that keeps the original structure of the Binary Tree. This solution will use Sets of C++ STL instead of array-based solution.

Does C++ have a tree data structure?

Coding Trees The code to represent a tree in C++ is what is shown below. It consists of a data part and references to the left and right nodes, respectively.


1 Answers

I don't know about your requirements, but wouldn't you be better off with a graph (implementations for example in Boost Graph) if you're interested mostly in the structure and not so much in tree-specific benefits like speed through balancing? You can 'emulate' a tree through a graph, and maybe it'll be (conceptually) closer to what you're looking for.

like image 88
Roel Avatar answered Sep 25 '22 16:09

Roel