DEV Community

Nijeesh Joshy
Nijeesh Joshy

Posted on

How often You Have to use the Concepts of Trees in your algo

I really dont get it
I haven't Used Trees in any of my Programs so far is it me or everyone feels the same ?

I may be a bad programmer but its just a thought...

Top comments (9)

Collapse
 
kayis profile image
K

I use XML, HTML or JSON in all of my software, so basically everywhere, I guess

Collapse
 
hkrogstie profile image
Håvard Krogstie • Edited

It really depends on the program, but even then you rarely build trees yourself, even in algorithms competitions I find. Save for when the algorithm input itself is a tree, or when a Binary Segment Tree is useful.

But I do use trees, just without it being obvious. The set datastructure has O(log n) complexity for insertion, deletion and search, AND it's sorted! Super useful in a plethora of tasks, also outside of the world of algorithms competitions. Sets use an underlying tree in the C++ STL. Sure you could use a linked list and achieve O(1) insertion and deletion, but the cache misses and memory fragmentation is awful.

Point is, know your data structures and you'll probably use trees when applicable.

Sidenote: I dont know how your language implements sets and maps, but it may use a hash map, where the data isn't sorted.
Also heeps are sorta implemented as trees, used by every priority queue I've ever known.

Collapse
 
karfau profile image
Christian Bewernitz

At work we are dealing with huge (XML) trees as input, that are very dynamic in nature.
We are actually very happy to have found a way to convert the input into maps/ lists. Our algorithms are still recursive, but much easier to grasp and extend because we don't need to "think in trees" all the time.

Collapse
 
jvarness profile image
Jake Varness

I don't think you're a bad programmer for not using trees. I have used trees maybe once in my 6+ years of experience.

It's all about knowing what structures to use and which ones to not use. For most programmers I think Maps and Lists/Sets/Arrays give them all of the flexibility they need.

Collapse
 
etcwilde profile image
Evan Wilde

I use trees in nearly everything I do. Whether I implement them is a different story. In C++ the std::map is usually implemented with a red-black tree. If you interact with a file system, you're usually working with a tree. Databases, trees. maps, trees. (unordered maps are not trees, they're a hash table). Sets, usually are trees.

Collapse
 
jasogamol profile image
Mark Piffer

I think it largely depends on the field of work that you are in. As soon as there is some form of language involved (think 'language' as the symbolic way to represent the problem, even if its never explicitly used) which allows recursive formulation of problems, a tree will be a natural and human-friendly solution to it. Also many problems which deal with out-of-order input/output are approachable with a hierarchical organisation and therefore tree algorithms. And if you happen to be confined in a functional language environment, trees are most often the natural way to deal even with ordinary (that is: iterative) data. The GNU make library I've written recently has quite a few of these, as well as a decision tree for arbitrary length division.

Collapse
 
miniharryc profile image
Harold Combs

I use them all the time.

My domain maps directly to serving organization structures (Corporate LDAP trees, inherited permissions and roles, etc.).

Collapse
 
inondle profile image
Quentin Fulsher

Had to write a Selenium test for a Boolean expression builder. The recursive data structures I used to model it can best be thought of as an inorder tree traversal.

Collapse
 
galdin profile image
Galdin Raphael