Traversing through all nodes of a binary tree in Java

前端 未结 2 1521
北海茫月
北海茫月 2020-12-28 18:05

Let\'s say I have a simple binary tree node class, like so:

public class BinaryTreeNode {
    public String identifier = \"\";
    public BinaryTreeNode pare         


        
2条回答
  •  攒了一身酷
    2020-12-28 18:51

    codeMan is right. The traversal will visit every node on the left. Once it reaches the last node on the left, it begins working its way back along the right-side nodes. This is a depth-first search (DFS) traversal. As such, each node is visited only once, and the algorithm runs in O(n) time. Happy coding.

提交回复
热议问题