Log In Sign Up
Day 14

Day 14: Binary Trees

14/60 Days

Binary Trees #

Welcome to Day 14 of our 60 Days of Coding Algorithm Challenge! Today, we’ll dive deep into Binary Trees, a fundamental data structure in computer science and a specific type of tree we introduced yesterday.

What is a Binary Tree? #

A Binary Tree is a tree data structure in which each node has at most two children, referred to as the left child and the right child. This restriction on the number of children makes binary trees particularly useful in various applications and algorithms.

Properties of Binary Trees #

  1. The maximum number of nodes at level ’l’ of a binary tree is 2^l.
  2. The maximum number of nodes in a binary tree of height ‘h’ is 2^(h+1) - 1.
  3. In a binary tree with N nodes, the minimum possible height or the minimum number of levels is log2(N+1) - 1.
  4. A binary tree with L leaves has at least log2(L) + 1 levels.

Types of Binary Trees #

  1. Full Binary Tree: Every node has 0 or 2 children.
  2. Complete Binary Tree: All levels are completely filled except possibly the last level, which is filled from left to right.
  3. Perfect Binary Tree: All internal nodes have two children and all leaves are at the same level. …