Complete Guide to the Tree Data Structure

What is Tree Data Structure

A Tree represents data in hierarchical order. Each data point in the tree is called a node. The topmost

Tree Data structure

Tree Data structure

node is called as root node from where the tree begins.

Important Terms:

Nodes: Each data point in tree

Root Node: First or topmost node in tree

Child Node: A subsequent node. Every node apart from root node is a child node.

Leaf Node: A node which does not have subsequent child nodes. The tree ends here.

Parent Node: A node which has subsequent child nodes. All nodes except leaf nodes are parent nodes.

Height of Tree: The maximum number of nodes from root node to leaf node.

Applications of Tree Data Structure

The primary application of tree data structure is in applications where we have hierarchical data.

  1. File Systems: As you must have observed, files are stored in Operating Systems in hierarchies where files come under directories or folders. So, naturally, the tree data structure can be used to store or access file structure.
  2. Database Index: Database Indexes are created on database tables, to quickly fetch information from the table. Tree Data structure is used here to create an index on tables.
  3. Markup Languages like XML and HTML: XML & HTML are markup languages in which data is stored between tags. These tags are also present in a hierarchy of Parent-child relationships. Thus, the tree data structure is a natural choice to represent markup languages.
  4. Compilers: Compilers use tree data structures to represent and parse program syntax.

Types of Trees

Based on the number of child nodes:

  1. Binary Tree – up to 2 child nodes
  2. Ternary Tree – up to 3 child nodes
  3. N-ary Tree – up to N child nodes (more than 3)

Add Comment

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.