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`.
Which rock type is formed from the cooling and solidification of magma below Earth’s surface?
Which of the following statement is correct about Rouging?
Which one the following is responsible for Rice tungro virus transmission?
Which one of the following moisture will be available if the filed capacity is 18% and permanent wilting point is 6%?
Cotton variety bollgourd is resistant toÂ
The key symptom of Cotton Wilt (Fusarium oxysporum) includes:
Breeder seed is the progeny ofÂ
What is the primary reason for classifying horticulture separately from agriculture?
Late Blight is an important disease of potato.
A. Phytophthora is the causal organism of Late Blight in potato.
B. Kufri Chipsona is resis...
Which among the following is a goal of Integrated Pest Management (IPM) ?