Since you apparently know the definition of a perfect tree, you should be able to write down the very simple, precise steps in English that one would use to do this "manually". That is one form of pseudocode. Since pseudocode is not any specific, formal language, you can call that your pseudocode, or if you want something that's a little more rigid and closer to what your real code will ultimately look like, you can start with the English steps and refine them to a more "code-like" but still syntactically informal form.
Here is what I have:
William Koch wrote:I already have code working out but it wont pass all my test cases.
So what exactly is the problem? You need to TellTheDetails(←click) to make it easier for people to understand what's not working.
The test case is this:
perfect binary tree : every node should contain exactly 2 childs(except leaf nodes) and all leaf nodes should be at same level
fully binary tree: every node has exactly 0 or 2 childs.
here you are trying to identify a binary tree is perfect or not right? see the properties of perfect binary tree . one property is that
size = (2 power (h+1)) - 1 ;
size = number of nodes and h=height of that tree. now you can write a program that validate above equation.
William Koch wrote:The problem is this JUnit test case will not pass. The tree is defined like this (there are 3 parts; the first part is the element in the node, the second part is the left child and the third part is the right child:
This is extremely difficult to read. Does your Tree class have an addChild method? If so, consider using that instead of all these perplexing nested instantiations.