Learn R Programming

msBP (version 1.4-1)

tree2vec: Conversions between tree and vector

Description

Convert a binary tree object into a vector and _vice versa_

Usage

tree2vec(tree)
vec2tree(vec)

Value

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\()\).

Arguments

tree

An object of the class binaryTree

vec

A vector of numbers. It must have size 2^s - 1, with s an integer.

Details

An object of the class binaryTree is a binary tree containing at each node a value.

Examples

Run this code
tree <- vec2tree(1:(2^5 - 1))
vector <- tree2vec(tree)

Run the code above in your browser using DataLab