Home > Back-end >  In the binary tree traversal
In the binary tree traversal

Time:01-16

This is a sequence of binary tree traversal, when performing the first judgment after received the value on the left, which is the root, hold values determine whether the right after, so called again, if the left there is no value on the right values are not stopped? Then the value of is how to traverse the out?
Don't think this algorithm, guide request bosses,

CodePudding user response:

This is a normal DFS traversal, if two child nodes of the current node explain the current node is a leaf node is empty, this route can be ended, otherwise continue down the recursive search, until the leaf node of the current line

CodePudding user response:

Do you have any misunderstanding on recursion?
If the left and continue the recursive traversal left. (this is the first if)
If does not meet the above, or if, after the traversal, above is traverse the current node, called the assignment statements in the middle of the two sentences if the
If the right, then continue to recursive traversal right subtree (that is, the second if)
So, to your question, about all have no, only perform intermediate one (about cycle for the first time, if all have no, only perform intermediate that sentence, that is 2; If the left will recursive traversal 1 first, for recursive Lai said 1, around which all have no, it is only carried out in the middle of the statement, in the middle of the statement is 1)
You draw a diagram to the execution of a program step by step the intermediate results was clear to draw

CodePudding user response:

refer to the second floor qybao response:
do you have any misunderstanding on recursion?
If the left and continue the recursive traversal left. (this is the first if)
If does not meet the above, or if, after the traversal, above is traverse the current node, called the assignment statements in the middle of the two sentences if the
If the right, then continue to recursive traversal right subtree (that is, the second if)
So, to your question, about all have no, only perform intermediate one (about cycle for the first time, if all have no, only perform intermediate that sentence, that is 2; If the left will recursive traversal 1 first, for recursive Lai said 1, around which all have no, it is only carried out in the middle of the statement, in the middle of the statement is 1)
You draw a diagram to the execution of a program step by step the intermediate results was clear to draw

Traverse 1 after all have no, please don't trigger the execution of this method, it is how to execute (that) back again, the current object is 2?
When you use the debug debugging is the 1 later again back to the middle of statements, the current object is 2 (the root node), and then save, to run the right below nodes,

CodePudding user response:

reference 1/f, a handsome and forced response:
this is a common DFS traversal, if two child nodes of the current node explain the current node is a leaf node is empty, this route can be over, or continue down the recursive search, until the current route leaf node

Thank you bosses to give directions

CodePudding user response:

refer to the third floor does not enter the development does not work reply:
traversal 1 after all have no, please don't trigger the execution of this method, it is how to execute (that) back again, the current object is 2?
When you use the debug debugging is the 1 later again back to the middle of statements, the current object is 2 (the root node), and then save, to run the following nodes, right

After the first if recursive don't execute in the middle of the statement? You think if performed over the program will go?
If performs after 1, because there is no child node 1 (so can't again into the if, perform in the middle of the statement, the assignment 1), then the recursive ended; After the recursion will come to the if part of the original (recursive end only if part of the end, not the entire program end), so they will continue to execute if the back of the statement in the middle of the

CodePudding user response:

reference 5 floor qybao reply:
Quote: refer to the third floor does not enter the development does not work reply:

Traverse 1 after all have no, please don't trigger the execution of this method, it is how to execute (that) back again, the current object is 2?
When you use the debug debugging is the 1 later again back to the middle of statements, the current object is 2 (the root node), and then save, to run the following nodes, right

After the first if recursive don't execute in the middle of the statement? You think if performed over the program will go?
If performs after 1, because there is no child node 1 (so can't again into the if, perform in the middle of the statement, the assignment 1), then the recursive ended; After the recursion will come to the if part of the original (recursive end only if part of the end, not the entire program end), so they will continue to execute if the back of the statement in the middle of the

Thanks to the interpretation of bosses, puzzled a day finally understand!
  • Related