binary tree serialization and deserialization