Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check Complete Binary Tree in java

Posted on 2008-06-17
3
Medium Priority
?
1,548 Views
Last Modified: 2010-10-05
How would i check in a recursive way if a given java tree where nodes are called p is binary complete??
0
Comment
Question by:axtur
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
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

by:Christopher Kile
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

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

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question