Skip to content
Given a binary tree, write a function to determine if it is a complete binary tree or not. A complete binary tree is a binary tree in which all levels, except possibly the last, are completely filled, and all nodes are as far left as possible. Implement the function ‘isCompleteBinaryTree(root)’ that takes the root of the binary tree as input and returns True if the tree is complete, and False otherwise. Example: Consider the following binary tree: 1 / 2 3 / / 4 5 6 The tree shown above is a complete binary tree, so the function should return True. Now, let’s consider another example: 1 / 2 3 / 4 5 7 / / 8 9 10 In this case, the tree is not a complete binary tree because the second level is not completely filled, and the node with value 7 is not as far left as possible. Therefore, the function should return False.
Tags:
Assignment Help for Students,
Assignment Help Free,
Assignment Help Online Free,
Assignment Help Websites,
assignmenthelp,
AssignmentHelpOnline,
BestAssignmentHelp,
myassignmenthelp,
OnlineAssignmentHelp,
Student Assignment Help,
University Assignment Help