Sobes.tech
Junior

What is a binary tree?

sobes.tech AI

Answer from AI

A binary tree is a tree data structure in which each node has at most two children: a left and a right.

Main properties:

  • Root: The topmost node of the tree.
  • Node: An element of the tree containing data and references to its children.
  • Child: A node directly below another node (the parent).
  • Parent: A node that has one or more children directly below it.
  • Leaf: A node with no children.
  • Branch: The path from the root to a leaf.
  • Subtree: A tree consisting of a node and all its descendants.

Different types of binary trees:

  • Full Binary Tree: Every node has either 0 or 2 children.
  • Perfect Binary Tree: All levels except possibly the last are fully filled, and all nodes on the last level are as far left as possible.
  • Balanced Binary Tree: The height difference between the left and right subtrees of any node is at most 1. Examples include AVL trees, red-black trees.
  • Degenerate (or stretched) Binary Tree: Each node has at most one child. Essentially, this is a linked list.

Used in various algorithms and data structures such as binary search trees, heaps, and syntax trees.