In this post we will check “Striver’s Tree Series : Tree Data Structure”.
What is a tree data structure?
There are two major types of data structures:
Tree is a Non-linear data structure where as Arrays, LinkedList are linear data structures. What makes tree a non-linear data structure is, the information or data is not stored in a sequential fashion, same is for traversal or retrieval.
Unlike, in arrays, we know that elements are stored at contiguous memory locations, however, it is not the same with trees. The nodes in a tree can be stored at random memory locations and can be linked to each other using pointers to define the structure of the tree.
Why is tree data structure important?
To understand why tree? Think about why we created other data structures. In order to do that, link every data structure to some real world entity and see where it fit’s well.
Will you use an array to store information of your family’s hierarchy? No right, what do you visualise this hierarchy as? I visualise it as a tree.
That is it, tree is used and important to store hierarchical data.
Tree data structure in C, C++, Java, Python
However, no data-structure is bound by any programming language. You can choose any of the above popular programming language and implement all possible trees in it. But, we highly recommend to go with any one of C++, Java or Python. These are object oriented language with a good number of inbuilt library functions.
Why Striver’s Tree Series?
This is sheet is prepared by Raj Vikramaditya A.K.A Striver, Candidate Master, 6*, who has bagged offers from Google Warsaw, Facebook London, Media.net(Directi). He has also interned at Amazon India. He is also one of the top educators at Unacademy and was at GeeksforGeeks as well.
More over, these simple set of questions in the Striver’s Tree Series contains all important concepts required to excel in the Tree Data Structure.
Problems on Tree Data Structure:
Also, check out Striver’s SDE Sheet to clear interviews of Amazon, Microsoft, or any other top tech startup.