Shortest possible depth of a leaf in decision tree (comparison sorting algorithm)

The absolute best case happens when we just check every element and see that the data’s already sorted. This will result in n-1 comparisons and thus the leaf will have a depth of n-1. Practically, this happens for insertion sort (which isn’t all that good otherwise though). Does it change depending on the algorithm? Absolutely. The best case of an … Read more

Why does the C++ STL not provide any “tree” containers?

There are two reasons you could want to use a tree: You want to mirror the problem using a tree-like structure:For this we have boost graph library Or you want a container that has tree like access characteristics For this we have std::map (and std::multimap) std::set (and std::multiset) Basically the characteristics of these two containers is such that they practically … Read more

Bad Operand Types for Binary Operator “>”?

Sure – you simply can’t apply the > operator between objects. What would you expect it to do? You can’t apply any of the other binary operators either – +, -, / etc (with the exception of string concatenation). Ideally, you should make your TreeNode generic, and either have a Comparator<T> which is able to compare any two instances, or make T extend Comparable<T>. Either way, … Read more

Definition of a Balanced Tree

I am just wondering if someone might be able to clarify the definition of a balanced tree for me. I have that “a tree is balanced if each sub-tree is balanced and the height of the two sub-trees differ by at most one. I apologize if this is a dumb question, but does this definition … Read more