short ^^
Serialize: BFS, time O(N);\nDeserialize: iterative insert into BST, time O(NlogN).\n\nclass Codec \n{\npublic:\n    string serialize(TreeNode* r) \n    {\n     
**Serialize:** BFS, time `O(N)`;\n**Deserialize:** iterative insert into BST, time `O(NlogN)`.\n```\nclass Codec \n{\npublic:\n    string serialize(TreeNode* r) \n    {\n        string out;\n        for(queue<TreeNode*> q({r}); !empty(q); q.pop())\n            if(q.front())\n            {\n                q.push(q.front()->left);\n                q.push(q.front()->right);\n                out += to_string(q.front()->val) + " "s;\n            }\n        return out;\n    }\n                             \n    TreeNode* deserialize(string d) \n    {\n        TreeNode* out{nullptr};\n        auto r{&out};\n        int val{-1};\n        for(stringstream ss{d}; ss>>d; *r = new TreeNode(val))\n            for(val = stoi(d), r = &out; *r; r = val<=(*r)->val ? &(*r)->left : &(*r)->right);\n        return out;\n    }\n};\n```\n<details>\n<summary>\nRecursive insert variation:\n</summary>\n\n```\nclass Codec \n{\npublic:\n    string serialize(TreeNode* r) \n    {\n        string out;\n        for(queue<TreeNode*> q({r}); !empty(q); q.pop())\n            if(q.front())\n            {\n                q.push(q.front()->left);\n                q.push(q.front()->right);\n                out += to_string(q.front()->val) + " "s;\n            }\n        return out;\n    }\n\n    TreeNode* insert(TreeNode* r, int val)\n    {\n        if(!r) return new TreeNode(val);\n        TreeNode* & child = val<=r->val ? r->left : r->right;\n        child = insert(child,  val);\n        return r;\n    }\n                              \n    TreeNode* deserialize(string d) \n    {\n        TreeNode* out{nullptr};\n        for(stringstream ss{d}; ss>>d; out = insert(out, stoi(d)));\n        return out;\n    }\n};\n```\n</details>
['C', 'C++']