- #1

evinda

Gold Member

MHB

- 3,836

- 0

How can we find the depth of a perfect binary tree and how of a complete one? (Thinking)

Since a perfect binary tree is a full binary tree, at which the leaves have the same depth, I thought that we can find the depth, by just looking at the leftmost nodes, like that:

Code:

```
Algorithm(NODE *tree){
pointer p=tree;
int depth=0;
while (p!=NULL){
p=p->next;
depth++;
}
return depth;
}
```

The leaves have been placed at the leftmost positions of the tree.

I thought that we could use again the above algorithm.

Am I right or have I done someething wrong? (Thinking)