All lessons

8. Trees

Binary trees

0 of 5 activities0%

Reading 1

Hierarchical structure

Open

A binary tree node has at most two children: left and right.

Root at the top; leaves have no children. Height/depth measure distance.

Dynamic nodes with pointers, or heap-style arrays for complete trees.

struct TNode {
  int val;
  TNode* left;
  TNode* right;
};

Check 2

Max children

Open

A binary tree node has at most how many children?

Fill in 3

No children

Open

A node with no children is a

Try it 4

Tiny tree

Open

Root with two children.

main.cpp
Loading editor…
Output will appear here.

Assignment 5

Count nodes formula

Open

A perfect binary tree of height h (root height 0) has how many nodes? Read h, print 2^(h+1)-1.

main.cpp
Loading editor…