Binary tree serialization