public static boolean isPerfect(TreeNode<Integer> t) {

		if (t == null) {
			return false;
		}

		Queue<TreeNode<Integer>> queue = new LinkedList<TreeNode<Integer>>();

		/* enqueue root node */
		queue.add(t);

		int level = 0;
		int currentLevelNodeNum = 1;
		int nextLevelNodeNum = 0;

		while (queue.size() != 0) {
			TreeNode<Integer> tempNode = queue.remove();
			currentLevelNodeNum--;

			/* add right child to queue */
			if (tempNode.right != null) {
				queue.add(tempNode.right);
				nextLevelNodeNum++;
			}

			/* add left child to queue */
			if (tempNode.left != null) {
				queue.add(tempNode.left);
				nextLevelNodeNum++;
			}

			if (currentLevelNodeNum == 0) {
				/* next level has no node */
				if (nextLevelNodeNum == 0) {
					return true;
				}

				/* number of node of next level does not equal 2 ^ (level + 1) */
				if (nextLevelNodeNum != (1 << (level + 1))) {
					return false;
				}

				currentLevelNodeNum = nextLevelNodeNum;
				nextLevelNodeNum = 0;
				level++;
			}
		}

		return true;
	}