


Suppose given ‘LABEL’ is ‘14’ then:
The shortest path in the zigzag binary tree from the root where the Ninja starts to reach the node with the given label where the enemy is hiding is 1 -> 3 -> 4 -> 14.
The first line of input contains a single integer ‘T’ denoting the number of test cases given. Then next ‘T’ lines follow:
The first line of each test case input contains a single integer i.e. the ‘LABEL’ of the node where the enemy is hiding.
For every test case, print a single line containing space-separated integers denoting the labels of the nodes in the shortest path from the root of the tree to the node 'LABEL' which Ninja can follow to reach and defeat the enemy quickly.
Print the list/vector of the elements from the root to the node 'LABEL'.
The output of each test case will be printed in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10 ^ 4
1 <= ‘LABEL’ <= 10 ^ 6
Time Limit: 1 sec.
Where 'T' denotes the number of test cases and 'LABEL' denotes the label of the node the enemy is hiding in.
Time limit: 1 sec.
The basic idea behind the algorithm is fairly to realize that if you take the node that corresponds to the label given as input then you can assign an index value to that node. Then take that index value and divide it by two. This will give the index value of the parent node and keep repeating the above idea to get all the nodes from root to label.
The algorithm to calculate the required will be:-
The basic idea behind the algorithm is fairly straightforward that first, we can add the node (‘LABEL’ given) to the back of the result list. Find the depth of the node. Find the parent of the node. Repeat steps with the parent as the new node.
The algorithm to calculate the required will be:-