Loading

Quipoin Menu

Learn • Practice • Grow

data-structure-with-java / Tree Introduction
tutorial

Tree Introduction

A tree is a hierarchical data structure consisting of nodes connected by edges. It's like an upside-down tree with the root at the top and leaves at the bottom. Trees are used in file systems, HTML DOM, network routing, and many algorithms.

Terminology:
  • Root – topmost node (no parent).
  • Node – an element containing data and links to children.
  • Edge – connection between two nodes.
  • Parent/Child – relationship between connected nodes.
  • Leaf – node with no children.
  • Subtree – a node and all its descendants.
  • Height – number of edges in longest path from node to leaf.
  • Depth – number of edges from root to node.

A simple tree node in Java:


public class TreeNode {
int val;
TreeNode left;
TreeNode right;

TreeNode(int val) {
this.val = val;
}
}
Two Minute Drill
  • Tree is a non-linear hierarchical data structure.
  • Nodes contain data and references to children.
  • Root, leaf, parent, child, subtree are key terms.
  • Height and depth measure distances.
  • Used in file systems, compilers, and algorithms.

Need more clarification?

Drop us an email at career@quipoinfotech.com