Question: / * * This method determines if a BST forms a zig - zag pattern. By this we mean that each node has exactly one
This method determines if a BST forms a zigzag pattern. By this we mean
that each node has exactly one child, except for the leaf. In addition,
the nodes alternate between being a left and a right child. An empty tree
or a tree consisting of just the root are both said to form a zigzag
pattern. For example, if you insert the elements into a
BST in that order. you will get a zigzag.
@return True if the tree forms a zigzag and false otherwise.
public boolean isZigZag
TODO: Write this.
ifroot NULLNODE
rootleft NULLNODE && root.right NULLNODE
return true;
Node orgroot root;
ifrootleft NULLNODE && root.right NULLNODE
return false;
Node temp root.right;
root root.left;
ifroot NULLNODE
isZigZag;
boolean zigzagLeft isZigZag;
root temp;
boolean zigzagRight isZigZag;
root orgroot;
return zigzagLeftigzagRight;
public void insertT e
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
