I have an Array that I need to transform it to an N-ary tree. I know the value of N, and the total number of nodes.
I give you an example in the picture below. The N-ary tree should be ordered as illustrated.
I can't figure it out. I need an algorithm to do that. The program I'm writing is in javascript but an answer in pseudocode is fine also.
Appreciate your help!
[Edited]
I found a solution using the algorithm from here: Construct a complete K-ary tree from preorder traversal
I found a solution using the algorithm from here: