C, if you know the pre order and mid order traversal of the binary tree, how do you know the post or

Updated on technology 2024-05-23
5 answers
  1. Anonymous users2024-02-11

    It's so troublesome, it seems to have to use a recursive method.

    You see, for example, a simple binary tree, with roots A, B, and C leaves; The pre-order is BAC, the middle sequence is ABC, and the posterior order is CAB. Theoretically, if you know the pre-order and the middle order, you will know the post-order.

    Idea: The first node in the middle order is the root node, followed by the left branch and the right branch; (This is also repeated in the left and right branches, so it's recursive.) Then find the position of the root node in the preface, and the preceding ones are all left-branched; It's time for the next recursion.

    When a node is found in the middle order, there is no previous one in the previous order, then the current one is the leaf, and then the right branch begins. )

    Based on these two traversal results, the binary tree is reconstructed.

    You don't want a binary tree first, but first implement the function of building a binary tree. Come up and make a class, you are not familiar with it, of course there will be a lot of mistakes, and you yourself don't know how to make mistakes.

  2. Anonymous users2024-02-10

    The pre-order first visits the root node, and then traverses the left order and then the right order. The middle order first traverses the left order, then visits the root node, and then traverses the right order! The landlord can give a specific topic! Or refer to the C language common foundation I hope it can help you!

  3. Anonymous users2024-02-09

    The original sentence should be something like this: the traversal of the back root of a tree is the same as the median traversal of the binary tree corresponding to the tree. Because there is no right daughter tree after the tree is converted to a binary tree, the root node of the tree is visited last.

    Guess the vertical root traversal, the middle root traversal, and the back root traversal first.

    Pre-order traversal, mid-order traversal, and post-order traversal.

    are two ways to say the same thing. The precursor traversal sequence of the binary tree is the same as that of the corresponding binary tree, with one exception: each node of the binary tree has only a right subtree, that is, a linear sequence of degenerated right deviations.

  4. Anonymous users2024-02-08

    The pre-order traversal first visits the root node, then traverses the left subtree, and finally traverses the right subtree. When traversing the left and right sub-trees, the root node is still visited first, then the left subtree, and finally the right subtree.

    The middle-order traversal first traverses the left subtree, then visits the root node, and finally traverses the right subtree. If the binary tree is empty, it ends and returns to the shelter.

    Thus, A is the root node, B is the left subtree of A, and F is the right subtree of A. E is the left subtree of B, C is the right subtree of B, and D is the right subtree of C. g is the right subtree of f. h is the left subtree of g and j is the right subtree of g. i is the left subtree of h.

  5. Anonymous users2024-02-07

    Summary...Access the root node of the binary tree and locate 1; 2.Access the left subtree of node 1 and locate node 2; 3.

    Access the left subtree of node 2 and locate node 4; 4.Since accessing the left subtree of node 4 failed, and there was no right subtree, the subtree traversal with node 4 as the root node completes. But node 2 hasn't traversed its right subtree yet, so now start traversing, accessing node 5 5.

    Since node 5 has no left and right subtrees, node 5 traversal is complete, and thus the subtree with node 2 as the root node is also traversed. Now go back to node 1 and start traversing the right subtree of that node, which is done by accessing the node.

    Write out the process of the binary tree traversing in the middle and back order.

    Can you tell us more about that?

    Can you tell us more about that?

    Access the root node of the binary tree and locate 1; 2.Access the left subtree of node 1 and locate node 2; 3.

    Access the left subtree of node 2 and locate node 4; 4.Since accessing the left subtree of node 4 failed, and there was no right subtree, the subtree traversal with node 4 as the root node completes. But node 2 hasn't traversed its right subtree yet, so now start traversing, accessing node 5 5.

    Since node 5 has no left and right subtrees, node 5 traversal is complete, and thus the subtree with node 2 as the root node is also traversed. Now go back to node 1 and start traversing the right subtree of that node, which is done by accessing the node.

Related questions
4 answers2024-05-23

Binary tree. The drawing method can be divided into:

1. Determine the root node. >>>More

10 answers2024-05-23

Summary. A binary tree is a finite set of n (n 0) nodes:

1), or an empty binary tree, i.e. n = 0. >>>More

9 answers2024-05-23

Satisfactory Answer: Telescope Level 8 2010-03-22 Complete Binary Tree. >>>More

9 answers2024-05-23

It is strongly recommended that the landlord make the topic clear, including how to input and what the output format is.

9 answers2024-05-23

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