We define the width of a level of a BT as the number of nodes located at this level.

A BT is a fairly well developed if the width of each level of the BT is $>$ than the one of the previous level.

Write a function that determines whether a BT is fairly well developed.


Difficulty level
This exercise is mostly suitable for students
typedef  struct 
{
	Btree tree; 
	int level;
} element;


int fwd(Btree A)
{
    	int current_count = 1, max_count = 1, current_level = 1;
	queue q;
	element E, X;

    	if (A == NULL) 
       		return 0;
	q = CreateQueue();

    	E.tree = A;
    	E.level = 1;
	EnQueue(&q,E);
	while(Front(q,&E))
    	{
        	if (E.level == current_level) current_count++ ;
        	else
        	{
            		if (current_count <= max_count) 
				return 0;
                	max_count = current_count;
            		current_count = 1;
            		current_level = E.level;
        	}
		DeQueue(&q);
        	if (E.tree->left) {X.tree = E.tree->left; X.level = E.level+1; EnQueue(&q,X);}
        	if (E.tree->right) {X.tree = E.tree->right; X.level = E.level+1; EnQueue(&q,X);}
    	}
    	return max_count;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Path with a given sum in binary trees