Course contentsShow
← Computer Science
Lesson 460 of 2,87211. Binary TreesFree lesson

Node-Based Tree Structure

Learn how binary tree nodes store data and references to left and right children using pointers or object references.

Node-Based Tree Structure

What you'll learn: How binary tree nodes actually store data and connect to their children using references.

The Core Idea

Unlike arrays where data sits in contiguous memory slots, binary trees live in memory as a network of independent node objects. Each node is like a small container that holds:

  1. Data (the actual value stored)
  2. A reference to its left child (a pointer/link to another node, or null if none exists)
  3. A reference to its right child (a pointer/link to another node, or null if none exists)

Think of each node as a person holding two strings—one in each hand. The left string connects to their left child (if any), and the right string to their right child. If there's no child in a direction, that hand is empty (null).

How It Works in Memory

When you create a binary tree node, you're allocating a small chunk of memory that contains these three pieces of information. The "references" (also called pointers or links) are memory addresses pointing to where the child nodes live—they could be anywhere in memory, not necessarily nearby.

For example, a node storing the number 10 with two children would have:

  • data = 10
  • left = <reference to left child node>
  • right = <reference to right child node>

If this node is a leaf (has no children), both left and right would be null.

The root node is special—it's your entry point to the entire tree. Lose the reference to the root, and you lose access to everything.

Key Takeaway: Binary tree nodes use a linked structure where each node stores data plus two references (left and right) that point to child nodes, allowing the tree to grow dynamically in non-contiguous memory locations.