Serialized Tree Representation

A common approach to use a vector to represent a binary tree is serialized representation. All LeetCode OJ use this kind of representation: the serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below.

Here's an example:

   1
  / \
 2   3
    /
   4
    \
     5

The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}".

For testing propose, I tried to write transform functions between serialized tree and binary tree. Essentially we could use level order traversal. The following class provides several methods to implement this.


Comments

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 4 Trees and Graphs