English 中文(简体)
简称 树木序曲理解
原标题:Binary Tree preorder traversal understanding

This homework assignment ask me to write the preorder traversal of the tree but I m confuse on how this would work because it visit node, left subtree, right subtree but it doesn t go to the middle. Would it just skip it or give an error? or do i just ignore the middle one?

enter image description here

问题回答

That s not a binary tree

与2个单元相关的是: 因此,一 tree树是一种树,任何树子要么是一leaf(没有孩子),要么是“有2个孩子”。 基本上,所有节点都有0至2名儿童。

Your picture isn t a binary tree: Node D has 3 children. Node B has only 1.

But you can pre-order traversal just fine

序前的 trav树与纯双 trees树毫不相干。 它是一种适用于树木的算法。 不需要树木是双向树。

To pre-order this one:

  1. Start at the root.
  2. Emit the value of the currently selected node.
  3. Go through the children it has in left-to-right order. For each child, recursively apply this algorithm at step 2.

各位都必须这样做。 此处适用:

  1. Start at the root.
  2. Emit its value: We have "A"
  3. Loop through its direct children - apply this algorithm to B and C.

对B的再保险将最终印成<代码>“BDHIJ”,对C的再保险将印成“CEG。 最终结果为ABDHIJCEG>

There s no such thing as skipping the middle node unless you are reading some tutorial or explanation that says first iterate the left side, then, iterate the right side . Those terms ( left side and right side ) presume a binary tree. There is no mention of the middle node because the explanation assumes a binary tree; binary trees don t have middle nodes.

一些穿透器,如在座的,不适用于非白化树。 这是因为他们访问了左边,然后是 no子,然后是右手。 这对非白化树没有意义。 但是,顺序前并没有这样做,因此可以轻而易举地扩大到N-ary 树木。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签