Discuss Trees and write some applications of Trees?

  • A tree is a nonlinear hierarchical data structure that consists of nodes connected by edges.

  • The first node from where the tree originates is called as a root node.

  • The connecting link between any two nodes is called as an edge.

  • The node which has a branch from it to any other node is called as a parent node.

  • The node which is a descendant of some node is called as a child node.

  • Nodes which belong to the same parent are called as siblings.

  • The node which does not have any child is called as a leaf node.

  • In a tree, each step from top to bottom is called as level of a tree.

  • Total edges that lie on the longest path from any leaf node to a particular node is called as height of that node.

  • 10. Total edges from root node to a particular node is called as depth of that node.

Finally, after understanding the basics, let’s talk about the use-cases/applications of trees where they make it easy to solve problems with a repeating pattern such as: -

1. Binary Search Trees (BSTs) quickly check whether an element is present in a set or not.

2. Heap is a kind of tree that is used for heap sort.

3. Tries is used in modern routers to store routing information.

4. Most popular databases use B-Trees and T-Trees, which are variants of the tree structure.

5. Compilers use a syntax tree to validate the syntax of every program you write.