Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Interview Problems on Tree
  • Practice Tree
  • MCQs on Tree
  • Tutorial on Tree
  • Types of Trees
  • Basic operations
  • Tree Traversal
  • Binary Tree
  • Complete Binary Tree
  • Ternary Tree
  • Binary Search Tree
  • Red-Black Tree
  • AVL Tree
  • Full Binary Tree
  • B-Tree
  • Advantages & Disadvantages
Open In App
Next Article:
What are the different types of Nodes in a Tree
Next article icon

What are the different types of Nodes in a Tree

Last Updated : 26 Nov, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Trees are nonlinear data structures that organize data hierarchically and in a recursive manner. 

It is a method of organizing and storing data in the computer in a way that makes it more effective to use. Nodes in the graph are connected via edges. It has different types of nodes which are called parent node, child node, leaf node, etc.

What is a root node?

A node that is the first or topmost node in a tree is called a root node. In every tree, there is always one root node, which is the only node that has never previously been connected to another node.

The root node in this tree is node (A).
The root node in this tree is node (A).

Importance of root node:

  • The root node, which has no parents, is the highest node in the tree structure. 
  • The entire message is represented by this node, which is a global element. 
  • It may have one or more child nodes, but it is never recurring or able to have sibling nodes. 
  • You can change the root node's name.

What is a parent node?

The node which is a predecessor of another node is known as a parent node. 

Or we can also say that if a node (A) is connected to another node (B) then node (A) will be known as the parent node for node (B) and similarly for other nodes as well if you refer to the below example.

  • Node (A) is the parent of node (B) and node (C).                                                                                                  
  • Similarly, node (B) is the parent of node (D) and node (E).                                                                                            
  • And node (C) is the parent of node (F) and node (G).
Parent nodes in a tree.
Parent nodes in a tree.

What is a child node?

The node which is the descendant(node which follows another node) of any node on a tree is known as a child node.

Or we can also say that every node excluding the root node is a child node in the tree. A child node always has a parent node to which it is connected. As you can see in the example below.

  • Where nodes (B) and (C) are children of the node (A).
  • Similarly, node (D) and node (E) are child nodes of (B).
  • And node (F) and node (G) are child nodes of  (C).
Child node in a tree.
Child node in a tree.

What is a leaf node?

A node that does not have any child node is called a leaf node. 

Sometimes in this case if there is a single node (A) present in the tree then that node is also called a leaf node because of no child node connected to it. There is nothing connected to a leaf node further which is the endmost node of a tree in a direction.

Leaf node in a tree.
Leaf node in a tree.

What is a height of a tree?

The height of a tree is the total number of edges from a leaf node to any particular node usually a root node. 

The height of a tree at the leaf node is minimum at (height of node F = 0) and maximum at the root node (Height of node A = 2).
 

Example of the Height of a tree
Example of the Height of a tree

What is the depth of the tree?

The depth of a tree is the number of edges from the root node to a particular node, usually, a leaf node and the path followed from the root node to the particular node is the longest path of a tree.

At the root node, the depth is minimum and at the leaf node, it is maximum. In the example given below at root node (A), it is 0 and at leaf node (F) it is maximum which is 2.

Example of depth of tree
Example of depth of tree

Let's take one more example to clarify the concept.

Here you can notice that the depth of node (C) is zero as it is a leaf node.
Here you can notice that the depth of node (C) is zero as it is a leaf node.

What is the degree of a node in a tree?

The Degree of a node in the tree is the summation of the number of child nodes connected to it, and the node which has the highest number of child nodes in a tree is also known as the Degree of a tree.

Degree of tree
Degree of tree

Next Article
What are the different types of Nodes in a Tree

D

devgarg05
Improve
Article Tags :
  • Tree
  • Technical Scripter
  • DSA
  • Technical Scripter 2022
Practice Tags :
  • Tree

Similar Reads

    What is Generic Tree or N-ary Tree?
    Generic tree or an N-ary tree is a versatile data structure used to organize data hierarchically. Unlike binary trees that have at most two children per node, generic trees can have any number of child nodes. This flexibility makes them suitable for representing hierarchical data where each node can
    4 min read
    Find the type of Tree based on the child count
    Given a tree that has some nodes and each node has a certain number of child nodes, the task is to find the type of tree based on the child count. For example, if each node has two children, then we can say it is a binary tree, and if each node has almost three children, then we can say it is a Tern
    7 min read
    Print Ancestors of a given node in Binary Tree
    Given a Binary Tree and a key, write a function that prints all the ancestors of the key in the given binary tree. For example, if the given tree is following Binary Tree and the key is 7, then your function should print 4, 2, and 1. 1 / \ 2 3 / \ 4 5 / 7Recommended PracticeAncestors in Binary TreeT
    13 min read
    How is an AVL tree different from a B-tree?
    AVL Trees: AVL tree is a self-balancing binary search tree in which each node maintain an extra factor which is called balance factor whose value is either -1, 0 or 1. B-Tree: A B-tree is a self - balancing tree data structure that keeps data sorted and allows searches, insertions, and deletions in
    1 min read
    What is Tree | Tree Definition & Meaning in DSA
    A tree is defined as a hierarchical data structure in which the elements (known as nodes) are linked together via edges such that there is only one path between any two node of the tree. Tree Data StructureProperties of Trees:Number of edges: An edge can be defined as the connection between two node
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences