Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Check Complete Binary Tree in java

Posted on 2008-06-17
Medium Priority
1,538 Views
How would i check in a recursive way if a given java tree where nodes are called p is binary complete??
0
Question by:axtur
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 23

Accepted Solution

Christopher Kile earned 2000 total points
ID: 21806819
The recursion is:

Function BinaryComplete(p) As Boolean

if Not(HasRightChild(p) or HasLeftChild(p)) then
return True
else if HasRightChild(p) And HasLeftChild(p)
return BinaryComplete(LeftChild(p)) And BinaryComplete(RightChild(p))
else 'only one child exists, the tree is not binary-complete
return False
end if

End Function

I used functional form, but LeftChild(p) is most likely to be p.leftChild in the actual implmentation, and HasRightChild(p) is likely to be implemented as the Boolean expression p.rightChild is Nothing.
0

LVL 23

Expert Comment

ID: 21806852
I just realized that this sounds like a homework assignment.  If it is, the Moderators may feel free to delete this.
0

Author Comment

ID: 21807991
It isn't homework assignment, its the answer to a question in an exam from the last year.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
###### Suggested Courses
Course of the Month8 days, 14 hours left to enroll