Question
Given a binary tree, a "zigzag" level order traversal
prints the nodes level by level, but alternating the order of nodes from left-to-right and right-to-left for successive levels. Â Â For example, Level 0 (root) is L-R, Level 1 is R-L, Level 2 is L-R, and so on. Â Â Consider the following binary tree: Â Â ``` Â Â Â Â Â 3 Â Â Â Â Â / \ Â Â Â Â 9Â 20 Â Â Â Â Â /Â \ Â Â Â Â Â 15Â Â 7 Â Â ``` Â Â What is the output of a zigzag level order traversal for this tree?ÂSolution
A zigzag level order traversal alternates the direction of traversal for each level. Â Â Â Â Â Â Level 0 (Left-to-Right): `3` Â Â Â Â Â Â Level 1 (Right-to-Left): Children of `3` are `9` (left) and `20` (right). In right-to-left order: `20, 9`. Â Â Â Â Â Â Level 2 (Left-to-Right): Children of `20` are `15` (left) and `7` (right). In left-to-right order: `15, 7`. (Node `9` has no children in this example). Â Â Â Â Combining these, the output is `3, 20, 9, 15, 7`.
In the following number-pairs, the second number is obtained by applying certain mathematical operations to the first number. Which numbers should repla...
If Pritam takes two times the time that Sameer takes or three times the time that Vikas takes to finish a task, and all three working together can compl...
There are three envelopes with three different addresses writen on them. Three leters are to be enclosed in these three envelopes such that one leter g...
Which of the following military causes are correct for the Revolt of 1857?
1.   Low salary and poor prospects of promotion
2.   Di...
Which of the following environmental factors plays a role in sex determination of few reptiles?
L, P, R, V, X, Y and Z are sitting around a circular table facing the centre. Only one person sits between V and L, when counted from the right of V. On...
Under the Workman's Compensation Act 1923, the Maximum monthly wage considered for compensation calculation is:
Which of the following is not a positive aspect of globalization?
If day before yesterday it was Monday, then which will be the day on day after tomorrow ?
Who is the Chief Election Commissioner of India as on March 2022?