(Java) Problem 10.14 variants

#1

Hi,

I do have 2 separate questions actually:

  1. Problem 10.14 Version 1: “Solve the same problem when there is no next-level field. Your result should be stored in the right child field”. Does this actually means I have to destroy the tree and set the right child property of a node to the node’s right sibling?
  2. Problem 10.14 Version 2: “Solve the same problem for a general binary tree.”. In this case, would a BFS approach (with queue) actually be a good (the best) solution?
0 Likes

#2

For the first question, the answer is “yes”, and it is called left-child right-sibling binary tree (https://en.wikipedia.org/wiki/Left-child_right-sibling_binary_tree). For the second, question, I think BFS would be ok but there are some extra attentions you should take a look at.

1 Like

#3

Thank you. I’ll dig into it.

0 Likes