-
Binary tree. The drawing method can be divided into:
1. Determine the root node.
2. Determine the left son and right son of the node.
3. Recursion until all nodes no longer have child nodes.
Depending on the specific storage structure of the binary tree, the methods for determining the root and child nodes are also different.
From your diagram, a g is traversal by layer.
, both from top to bottom, left to right.
If the liquid is stored in an array, it can be expressed as.
Index 0 1 2 3 4 5 6 7 8
Node a, b, c, d, null, e f, null g
The first node is the root node.
Node with index number i:
Left son index number 2i 1
The right son has an index number of 2i 2
Recursion from the root node allows you to draw the entire tree; If it's a linked list.
storage, its physical address.
There is no direct connection with the logical address, and it can only be deduced by the logic between the first points.
-
reat(). You're using recursion, and you're building a full binary tree. It builds the root node first, then the left subtree, and then the right subtree when the left subtree is finished. But if you just keep typing non-zero values, you're building the left subtree endlessly.
Note that since your program is building a full binary tree (that is, each root node has two child nodes), if you want to complete the construction of the left subtree, the 0 you need to enter (to build your null node) will increase exponentially with the number of layers of your tree, once you enter enough non-zero values, even if it is 10, the number of 0s you need to enter will run between 8 and 16, if you are not patient, of course you think you have entered an endless loop.
put t->lchild=creat(); change to t->data=x; Before, then run, you don't enter too many non-zero values, 7 is enough, and then keep typing 0s, you count yourself, how many zeros you want to enter, see if it's 2 3. If you have to construct a full binary tree, you don't have to change the program, at most change it to what I said above, and the breadth will be prioritized.
Breadth-first, you only need to enter 0 one last time, you don't have to enter 0 at the end, as is the case with depth first, and you don't know when to enter 0 at the end.
Please add a detailed explanation.
-
The method of searching and inserting is similar to re-establishing a one-dimensional array, and the time complexity o(n) will develop into the shape of a single chain because the depth is not aware of the balance, which is as deep as a line n points.
The binary sort tree is inserted when there are no nodes in the tree with keywords equal to a given value in the search process. The newly inserted node must be a newly added leaf node, and is the left or right node of the last node accessed on the path, if the lookup is unsuccessful.
Therefore, the maximum time complexity of binary sorting tree insertion is o(n). If the binary sorted tree is more balanced, the time complexity and complexity decrease, and the minimum time complexity is o(logn).
-
1) Traverse in order, according to the order of the root left and right, along a certain path through the nodes on the path. In a binary tree, the root is followed by the left and then the right.
2) Middle-order traversal, first traversing the left subtree, then visiting the root node, and finally traversing the right subtree.
3) Post-order traversal, which can be recorded as left and right roots. In the binary wisdom tree, the left and then the right are then rooted, that is, the left subtree is traversed first, then the right subtree, and finally the root node is visited.
4) The root node of this binary tree is a.
5) Draw a binary tree:
Satisfactory Answer: Telescope Level 8 2010-03-22 Complete Binary Tree. >>>More
It is strongly recommended that the landlord make the topic clear, including how to input and what the output format is.
A node without a daughter tree is a leaf node.
The degree of a node refers to the number of subtrees of the node, and there is no node with a degree greater than 2 in the binary tree. That is, each node can have a maximum of two subtrees. >>>More
Complete**, the global variable outstr contains the traversal result. >>>More
<> the first number as the root node, divide the next number into those larger than 30 and smaller than 30, the small number is placed on the left, the large number is placed on the right, and then in the order in which the numbers appear, one by one, the larger than the root node is placed on the right, and the small one is placed on the left.