Goseeko blog

What is Tree data structure?

A tree data structure is a non-linear data structure since it does not store data in a sequential order. A Tree is a hierarchical structure since the components are organize at multiple levels. Nodes, which are things or entities that connect together to show or imitate hierarchy, make up a tree data structure.

The root node in a Tree data structure is the topmost node. Moreover, Each node has some data, which can be of any kind. Because the node in the above structure contains the employee’s name, the data type is a string.

Tree terminology

• Root – In a tree hierarchy, the root node is the highest node. To put it another way, the root node is the one that has no children. The root node of the tree is numbered 1 in the above structure. A parent-child relationship exists when one node is directly linked to another node.
• Child node – If a node is a descendant of another node, it is refer to as a child node.
• Parent – If a node has a sub-node, the parent of that sub-node is said that node.
• Sibling – Sibling nodes are those that have the same parent.
• Leaf node – A leaf node is a node in the tree that does not have any descendant nodes. Moreover, A leaf node is the tree’s bottommost node. In a generic tree, there can be any number of leaf nodes. External nodes are also define as leaf nodes.
• Internal node – An internal node is a node that has at least one child node.
• Degree – The total number of branches of a node determines its degree. In addition, The highest degree of a node among all the nodes in the tree is calls the tree’s degree.
• Level – Each step from the top to the bottom of a tree is refer to as a level. At each level or step, the level count starts at 0 and increases by one.
• Depth – The depth of a node refers to the total number of edges connecting it to the root node. Furthermore, The total number of edges in the longest path from the root node to the leaf node is the tree’s depth. The root node’s depth is equal to zero. The terms “level” and “depth” are interchangeable in this context.
• Height of node – The number of edges from the node to the deepest leaf determines a node’s height (ie. the longest path from the node to a leaf node).
• Height of tree – The height of a tree is equal to the depth of the deepest node or the height of the root node.

Interested in learning about similar topics? Here are a few hand-picked blogs for you!