1. DFS (Recursion)
According to the relative order of the root node, the left node, and the right node, the depth-first search strategy can be further divided into: sequential traversal within sequential traversal before sequential traversal
Serialization: Conversion of a data structure or object to sequential bits deserialization: conversion of sequential bits to tree nodes
Serialization: sequential traversal if the tree node is empty, then STR += “null,”; Otherwise the STR + = String. The valueOf (root. Val); Recursively left subtree recursively right subtree
Deserialization: The string is divided into an array of strings based on commas and converted to a list structure. If equals(“null “) is read,return otherwise the left subtree of the new tree node is the right subtree of the tree node
2. BFS sequence traversal
Serialization: Maintain a queue, enter the root node and consider the exit node. If the exit node is empty, push “null” into the RES array. Otherwise, push the node into the array and enqueue the left and right nodes of this node
Deserialization: First convert to list array, maintain a queue, the root node in the queue. A node is enqueued. The left and right nodes of the current node are the next and next elements in the array