Ask Your Question
3

What is the reason for passing newBst.root as an argument when implementing the preorder traversal method?

asked 2023-05-04 12:01:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-04 12:06:01 +0000

qstack gravatar image

The reason for passing newBst.root as an argument when implementing the preorder traversal method is that the method needs to start traversing the tree from the root node. By passing the root node as an argument, the method knows where to start traversing from and can then recursively traverse the entire tree in a preorder fashion. Without passing the root node as an argument, the method would have no starting point and would not be able to traverse the tree.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-04 12:01:00 +0000

Seen: 8 times

Last updated: May 04 '23