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
  • Learn & ask questions
Solved

Check Complete Binary Tree in java

Posted on 2008-06-17
3
1,524 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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
diffSum example 4 50
Way to decrease size of apk file 9 86
web application structure 18 95
Adding multiple JVM environments to RedHat 6 7 45
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

765 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