Y12 Unit 0 - Class Structure
Y12 Unit 1 - Computational Thinking
Y12 Unit 2 - Networks
Y12 Unit 3 - OOP
Y12 Unit 4 - System Fundamentals
Abstract Data Structures (HL) Year 13 Unit

How do Binary Trees work?

Trees are dynamic data structures, meaning that they are created to hold any data and can grow and shrink automatically; unlike Java arrays, which have a fixed size. An important characteristic of Binary Trees is that they are very efficient data structures for searching, insertion and deletion. They are much faster than ArrayLists, Arrays and Linked Lists in terms of searching for an item.

Let’s go over a few terms for binary trees in the following diagrams:

A node

Trees are made up of nodes, just like linked lists. Each node can contain data and a reference to other nodes. The first node on a tree, the one at the top-most position, is called the Root. Any node, including the root node, can have children. This means that the left reference or right reference is not null. A node that has no children is called a leaf. A node that has children is called a parent node.

A set of nodes along a path is a branch. A path is a sequence of nodes. As you travel through a tree looking for specific data you want to follow a specific path. There are different strategies for traversing a tree, which we will discuss in future sections.

TermExplanation
ChildrenNodes below another node.
ParentA node that holds references to other nodes below it.
RootThe first node on a tree. It sits at the top-most position.
PathA set of nodes found in a sequence.
BranchA set of nodes found on a path in a manner in which the bottom-most is directly below the next node in the path.
HeightThe number of levels from the top to the bottom.
LevelIn a sense, the number of layers found in a tree. The example above has three levels.
SubtreeAny node can be considered the root of a subtree. A tree can be composed of many subtrees.
TraversingVisiting all notes in a tree in a specific order.
VisitingArriving at a node and performing an operation with the data held by the node.