Josh Theisen

Ranch Hand

Posts: 31

posted 6 years ago

Hey guys - so not a programming problem here, but one that I just can't seem to figure out.

In my notes, it says,

A binary tree of depth d is almost complete if:

1)Each leaf in the tree is either at level d or at d-1

2)For any node n in the tree with a right descendant at level d,

all the left descendant of n that are leaves are also at level d.

Here are two examples:

The first one, according to my notes, is not almost complete because: "Since A has a right descendant J at level 3, but it has a left descendant E that is a leaf at level 2"

I think that makes sense.

However, for the second one...we didn't get an answer. But, from what I can tell, we have a right descendant F at level 2, and at least all the leaves on the left are at level 2 - so that would be an almost complete binary tree.

Am I even thinking straight here? Finals week...brain's almost fried.

Thanks,

Josh

In my notes, it says,

A binary tree of depth d is almost complete if:

1)Each leaf in the tree is either at level d or at d-1

2)For any node n in the tree with a right descendant at level d,

all the left descendant of n that are leaves are also at level d.

Here are two examples:

The first one, according to my notes, is not almost complete because: "Since A has a right descendant J at level 3, but it has a left descendant E that is a leaf at level 2"

I think that makes sense.

However, for the second one...we didn't get an answer. But, from what I can tell, we have a right descendant F at level 2, and at least all the leaves on the left are at level 2 - so that would be an almost complete binary tree.

Am I even thinking straight here? Finals week...brain's almost fried.

Thanks,

Josh

posted 6 years ago

I think you're a bit off. The tree is of level 3, correct?

So in the right-hand example, which are the nodes which have a right descendant at level 3?

Okay, now that you have identified those nodes, and only those nodes, do they in fact satisfy this requirement?

(I can't really answer those myself, because I don't know what a "right descendant" is, but that's the process you have to follow to answer the question.)

2)For any node n in the tree with a right descendant at level d...

So in the right-hand example, which are the nodes which have a right descendant at level 3?

all the left descendant of n that are leaves are also at level d.

Okay, now that you have identified those nodes, and only those nodes, do they in fact satisfy this requirement?

(I can't really answer those myself, because I don't know what a "right descendant" is, but that's the process you have to follow to answer the question.)