What is zero branches in the binary tree

OttosBinaryKnights / AuD

/*BinaryTree: maxWidthWrite the MyBinTree class as an extension of the BinaryTree class.The method public int maxWidth (),should return the largest width (i.e. the maximum number of nodes in the same level) for the given binary (subtree) tree.For the following binary tree, e.g. B. three is the greatest width.Hints:The BinaryTree class can be found under "Slides and Materials" on the "Code / Examples" page.The class BinaryTree is available in the backend and should be included withimport aud.BinaryTree;be integrated.The Queue class is available in the backend and should be entered withimport aud.Queue; be integrated.*/importjava.util.ArrayList;publicclassMyBinTree extendsBinaryTree {publicMyBinTree (Tdata) {super (data); }publicMyBinTree (Tdata, BinaryTree left, BinaryTree right) {super (data, left, right); }// get level of 'this' (root level = 1)privateintgetLevel () {BinaryTree node = this;int level = 1;while (! node.isRoot ()) {++ level; node = node.getParent (); }return level; }publicintmaxWidth () {// store every level's width by using levelorder traverseint currentLevel = 1, currentWidth = 0;ArrayList widthList = newArrayList ();for (BinaryTree current: levelorder ()) {int level = ((MyBinTree ) current) .getLevel ();if (level == currentLevel)++ currentWidth;else {++ currentLevel; // advance to the next level widthList.add (currentWidth); currentWidth = 1; } }// find largest widthint maxWidth = 0;for (int width: widthList) {if (width> maxWidth) maxWidth = width; }return maxWidth; }publicstaticvoidmain (String [] args) {MyBinTree root = newMyBinTree (-8); root.setLeft (newMyBinTree (4)); root.setRight (newMyBinTree (1)); root.getLeft (). setLeft (newMyBinTree (6)); root.getLeft (). setRight (new