All lessonsOpen Open Open Open Open
8. Trees
Binary trees
0 of 5 activities0%
Reading 1
Hierarchical structure
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
A binary tree node has at most how many children?
Fill in 3
No children
Try it 4
Tiny tree
Root with two children.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Count nodes formula
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…