The half-full node

A complete binary tree has every level full except possibly the last, which is filled left-to-right. Stored in a 00-indexed array of 100100 nodes (node ii has children at 2i+12i+1 and 2i+22i+2), how many of its nodes have exactly one child (as opposed to two children or none)?

Show hints (2)+
  1. A one-child node needs its left-child index in range but its right-child index out of range: 2i+1=N−12i+1 = N-1.
  2. That equation has an integer solution only when NN is even - how many solutions, and is 100100 even?

Answer

Reveal answer →

1

Create a free account to see the full worked solution and track your progress.

Interview format: Hedge Fund Quant, Prop Trading

Related questions