Skip to main content
deleted 264 characters in body
Source Link

I have an exercise in my algorithm's Course for which I have the correction but do not understand it.

1.Exercise .

Let Th be a full binary three of height h(meaning all the levels all completely full).

(1.a) : Let f(h) be the number of leaves of Th(nodes of the last level). Establish a relation for f(h) and solve it recursively. Give the exact expression for f(h) in terms of h, and the asymptote expression (in Big-O notation)

My resolution

f(h) = f(h) ÷ 2 =

= f(h) ÷ 2 ÷ 2 = ...

Since f(h) is the number of the leaves, if we divide them by 2, increasing 2^n till we have 0 leaves we established a recursive relation in for f(h), where the complexity should be O(2^n)

Correction

f(h)=2f(h-1) for h >= 1 and f(0) =1.
f(h)=2
f(h-1)=4f(h-2)=8f(h-3)=...=2^hf(h-h)=2^hf(0) =2^h.
Complexity : O(2^h)

I simply do not understand why h-1. Because suppose we have a full binary tree with h=2 . If h=2, then number of leaves = 4 . Applying the correction resolution:
f(2) = 2f(2-1) = 2f(1) = 2, which is different from the number of leaves, which is 4.

I have an exercise in my algorithm's Course for which I have the correction but do not understand it.

1.Exercise .

Let Th be a full binary three of height h(meaning all the levels all completely full).

(1.a) : Let f(h) be the number of leaves of Th(nodes of the last level). Establish a relation for f(h) and solve it recursively. Give the exact expression for f(h) in terms of h, and the asymptote expression (in Big-O notation)

My resolution

f(h) = f(h) ÷ 2 =

= f(h) ÷ 2 ÷ 2 = ...

Since f(h) is the number of the leaves, if we divide them by 2, increasing 2^n till we have 0 leaves we established a recursive relation in for f(h), where the complexity should be O(2^n)

Correction

f(h)=2f(h-1) for h >= 1 and f(0) =1.
f(h)=2
f(h-1)=4f(h-2)=8f(h-3)=...=2^hf(h-h)=2^hf(0) =2^h.
Complexity : O(2^h)

I simply do not understand why h-1. Because suppose we have a full binary tree with h=2 . If h=2, then number of leaves = 4 . Applying the correction resolution:
f(2) = 2f(2-1) = 2f(1) = 2, which is different from the number of leaves, which is 4.

I have an exercise in my algorithm's Course for which I have the correction but do not understand it.

1.Exercise .

Let Th be a full binary three of height h(meaning all the levels all completely full).

(1.a) : Let f(h) be the number of leaves of Th(nodes of the last level). Establish a relation for f(h) and solve it recursively. Give the exact expression for f(h) in terms of h, and the asymptote expression (in Big-O notation)

Correction

f(h)=2f(h-1) for h >= 1 and f(0) =1.
f(h)=2
f(h-1)=4f(h-2)=8f(h-3)=...=2^hf(h-h)=2^hf(0) =2^h.
Complexity : O(2^h)

I simply do not understand why h-1. Because suppose we have a full binary tree with h=2 . If h=2, then number of leaves = 4 . Applying the correction resolution:
f(2) = 2f(2-1) = 2f(1) = 2, which is different from the number of leaves, which is 4.

edited tags
Link
Source Link

Recursive relations in binary trees

I have an exercise in my algorithm's Course for which I have the correction but do not understand it.

1.Exercise .

Let Th be a full binary three of height h(meaning all the levels all completely full).

(1.a) : Let f(h) be the number of leaves of Th(nodes of the last level). Establish a relation for f(h) and solve it recursively. Give the exact expression for f(h) in terms of h, and the asymptote expression (in Big-O notation)

My resolution

f(h) = f(h) ÷ 2 =

= f(h) ÷ 2 ÷ 2 = ...

Since f(h) is the number of the leaves, if we divide them by 2, increasing 2^n till we have 0 leaves we established a recursive relation in for f(h), where the complexity should be O(2^n)

Correction

f(h)=2f(h-1) for h >= 1 and f(0) =1.
f(h)=2
f(h-1)=4f(h-2)=8f(h-3)=...=2^hf(h-h)=2^hf(0) =2^h.
Complexity : O(2^h)

I simply do not understand why h-1. Because suppose we have a full binary tree with h=2 . If h=2, then number of leaves = 4 . Applying the correction resolution:
f(2) = 2f(2-1) = 2f(1) = 2, which is different from the number of leaves, which is 4.