3 ms·
An algorithm that builds a tree out of some other data source matching some criteria can return an empty tree if no element matches the filter. Then, algorithms
by the_af 7y ago
An algorithm that builds a tree out of some other data source matching some criteria can return an empty tree if no element matches the filter. Then, algorithms that process trees must take empty trees in consideration. (Yes, you could write "if notEmpty(tree) then f(tree)" in your language, but then you have a partial function f which doesn't work if tree is empty, and partial functions often lead to bugs because we tend to forget about their partial-ness).
Almost every "collection" data structure needs to have an empty representation. Trees are no different.