Class SerializeTreeToList

java.lang.Object
com.amritpandey23.dsalibrary.tree.SerializeTreeToList

public class SerializeTreeToList extends Object
Serialization of binary tree to array/list. This algorithm is useful in comparing contents of two binary trees.
  • Constructor Details

    • SerializeTreeToList

      public SerializeTreeToList()
  • Method Details

    • serializeTree

      public static <T> List<T> serializeTree(TreeNode<T> node)
      Serializes the binary tree rooted at the specified node into a list using level-order traversal. Each level of the tree is represented in order, with `null` values for missing nodes.
      Type Parameters:
      T - the type of the values stored in the tree nodes
      Parameters:
      node - the root of the binary tree to be serialized
      Returns:
      a list containing the values of the tree nodes in level-order, with `null` for absent children