Objective
Given an unlabelled binary tree, decide whether it is contiguous in indices.
Indices
This challenge gives one-indexing on binary trees. The exact definition expresses all indices in binary numeral:
The root is indexed
1.For every node, to get the index of its left child, replace the most significant
1by10.For every node, to get the index of its right child, replace the most significant
1by11.
A binary tree is contiguous in indices iff the indices of its nodes have no gaps.
Note that every binary tree with contiguous indices is balanced.
I/O Format
Flexible.
Examples
L indicates a leaf. [ , ] indicates a branch.
Truthy
L [L,L] [[L,L],L] [[L,L],[L,L]] [[[L,L],L],[L,L]] [[[L,L],L],[[L,L],L]] Falsy
[L,[L,L]] [[[L,L],L],L] [[[L,L],[L,L]],[L,L]] [[[L,L],L],[L,[L,L]]] 