en/docs/chapter_tree/summary.md
Q: For a binary tree with only one node, are both the height of the tree and the depth of the root node $0$?
Yes, because height and depth are typically defined as "the number of edges passed."
Q: The insertion and removal in a binary tree are generally accomplished by a set of operations. What does "a set of operations" refer to here? Does it imply releasing the resources of the child nodes?
Taking the binary search tree as an example, the operation of removing a node needs to be handled in three different scenarios, each requiring multiple steps of node operations.
Q: Why does DFS traversal of binary trees have three orders: preorder, inorder, and postorder, and what are their uses?
Similar to forward and reverse traversal of arrays, preorder, inorder, and postorder traversals are three methods of binary tree traversal that allow us to obtain a traversal result in a specific order. For example, in a binary search tree, since nodes satisfy the relationship left child node value < root node value < right child node value, we only need to traverse the tree with the priority of "left $\rightarrow$ root $\rightarrow$ right" to obtain an ordered node sequence.
Q: In a right rotation operation handling the relationship between unbalanced nodes node, child, and grand_child, doesn't the connection between node and its parent node get lost after the right rotation?
We need to view this problem from a recursive perspective. The right rotation operation right_rotate(root) passes in the root node of the subtree and eventually returns the root node of the subtree after rotation with return child. The connection between the subtree's root node and its parent node is completed after the function returns, which is not within the maintenance scope of the right rotation operation.
Q: In C++, functions are divided into private and public sections. What considerations are there for this? Why are the height() function and the updateHeight() function placed in public and private, respectively?
It mainly depends on the method's usage scope. If a method is only used within the class, then it is designed as private. For example, calling updateHeight() alone by the user makes no sense, as it is only a step in insertion or removal operations. However, height() is used to access node height, similar to vector.size(), so it is set to public for ease of use.
Q: How do you build a binary search tree from a set of input data? Is the choice of root node very important?
Yes, the method for building a tree is provided in the build_tree() method in the binary search tree code. As for the choice of root node, we typically sort the input data, then select the middle element as the root node, and recursively build the left and right subtrees. This approach maximizes the tree's balance.
Q: In Java, do you always have to use the equals() method for string comparison?
In Java, for primitive data types, == is used to compare whether the values of two variables are equal. For reference types, the working principles of the two symbols are different.
==: Used to compare whether two variables point to the same object, i.e., whether their positions in memory are the same.equals(): Used to compare whether the values of two objects are equal.Therefore, if we want to compare values, we should use equals(). However, strings initialized via String a = "hi"; String b = "hi"; are stored in the string constant pool and point to the same object, so a == b can also be used to compare the contents of the two strings.
Q: Before reaching the bottom level, is the number of nodes in the queue $2^h$ in breadth-first traversal?
Yes, for example, a full binary tree with height $h = 2$ has a total of $n = 7$ nodes, then the bottom level has $4 = 2^h = (n + 1) / 2$ nodes.