Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

import java.util.*; public class PoD { //============================================================================= /** * Returns true if the binary tree is a strict binary tree, in which * each node

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

import java.util.*; public class PoD { //============================================================================= /**  * Returns true if the binary tree is a strict binary tree, in which  * each node in the tree has either zero or two children.  * @param bTree BinaryTree of interest  * @return boolean true if strict binary tree, false otherwise  */   public static boolean isStrictBinaryTree(BinaryTree bTree) { } //============================================================================= public static void main( String [] args ) { Scanner in = new Scanner( System.in ); int i = in.nextInt(); int j = in.nextInt(); BinaryTree newBT = makeBT(i,j); boolean isStrictBT = isStrictBinaryTree(newBT); if (isStrictBT) { System.out.println("Strict binary tree"); } else { System.out.println("NOT a strict binary tree"); } in.close(); System.out.print("END OF OUTPUT"); } public static BinaryTree makeBT(int n, int k) { BinaryTree b; if ((n>0) && (n%2==0)) { b = new BinaryTree(n,makeBT(n-1,k),makeBT(n-2,k)); } else if (n>0 & n%2==k) { b = new BinaryTree(n, null, makeBT(n - 2,k)); } else { b = new BinaryTree(0,null,null); } return b; } }
Today you are going to take a look at a binary tree and decide if it is a strict binary tree or not. Strict binary tree A binary tree is considered a strict binary tree if each node in the tree has either zero or two children. n other words: If either subtree is empty, both left and right subtrees are empty If neither are empty, both the left or right subtrees are each strict binary trees as well. Details Download the ZIP files named FilesNeeded.zip for use in Intellij. When you are happy with your solution, upload the files into the src folder and run. You are going to finish off PoD.java to finish the isStrictBinaryTree method Input The main method (already completed) creates a binary tree and passes that binary tree to the isStrictBinary Tree method. Processing You are going to complete the details of isStrictBinaryTree method. Details of each method and their expected parameters are described in the Javadoc comments preceding it. The method should return true if the binary tree is a strict binary tree and return false if it is not

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students explore these related Databases questions