Vertical Order Print Concept

I dont know, how to build tree from level order input and height of the tree, so HELP

@Kinjal
Level order input is taken and tree is build by using the queue, in which firstly u will take a queue of nodes, and then it will have a data which will represent a root node, and then u will accept the left and right child of root node, -1 value means that the node does not have any child.

U can refer to this code for your help(it contains the function for level order input) :smiley:


donr forget to hit like and mark resolved if cleared :smiley:

Oh, you mean BFS approach

@Kinjal yes bfs is level order only

But, what about height of the tree given in the input?

wait let me see @Kinjal

@Kinjal i dont think height will come into the use in creating the tree just refer this level order build i told

But, there is reason to give height of the tree in the input of this problem, right?

@Kinjal some times a input is given which can be of use or not. like in this case you can calculate the height after building the tree only

Isn’t that feel like extra work, where you have to create height function to check height of the tree is equal to the given input height or not?

@Kinjal yes was just giving an example that sometimes all the inputs given are not necessary to be used in the solution
just try solving it you will know whether it will be used or not

Or maybe I can pass this height as a parameter into the BFS(), right?

@Kinjal yes you can but it would be extra work . why will you do it?

so that I can make it as a base case, like if(height==0) then stop build tree

@Kinjal that would be extra work too you can try if you want

I’m suspicious about the input of height because CB question makers are not creating this input illogically, right? There is something, may be I’m overlooked

@Kinjal you are thinking too much height is not necessary in the input. i even looked at the editorial they also haven’t used it anywhere
(ignore the height its just a simple lever order input)

1 Like

Oh, okay. Then I will implement BFS

@Kinjal yes it will work