Solved

Check Complete Binary Tree in java

Posted on 2008-06-17
3
1,519 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 500 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now