A binary tree is called complete if all its non-leaf nodes have two children.

Write a function that tests whether a binary tree statically implemented is complete.


Difficulty level
This exercise is mostly suitable for students
int isComplete(Btree tree, int i)
{
	 if(i == 0)
		 return 1;
	 if(tree.data[i].left_subtree && !tree.data[i].right_subtree || !tree.data[i].left_subtree && tree.data[i].right_subtree)
		 return 0;
	 if(!isComplete(tree, tree.data[i].left_subtree) || !isComplete(tree, tree.data[i].right_subtree)) 
		 return 0;
	 return 1;
 }
 
 
int Complete(Btree tree)
{
	return isComplete(tree, tree.root_index);
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Articulation points cut bridges and cut edges