powered by
Convert a binary tree object into a vector and _vice versa_
tree2vec(tree) vec2tree(vec)
A vector of size \(2^{D+1}-1\), where \(D\) is the depth of the binary tree, or a binary tree with depth \(\log_2(\)length(vec) + 1\()\).
length(vec) + 1
An object of the class binaryTree
A vector of numbers. It must have size 2^s - 1, with s an integer.
An object of the class binaryTree is a binary tree containing at each node a value.
tree <- vec2tree(1:(2^5 - 1)) vector <- tree2vec(tree)
Run the code above in your browser using DataLab