Trees
A tree is a branching structure of nodes with children. A binary search tree gives each node up to two children and keeps order: smaller values go left, larger values go right. That ordering makes lookups fast — you halve the search at each step.
class TreeNode {
constructor(value) { this.value = value; this.left = null; this.right = null }
}
Try it yourself
Loading editor…
Reading a binary search tree in order (left, node, right) returns the values sorted. Trees also model the page DOM, file systems and category menus.