Jump to content

99 Elm Problems/Problem 60

From Wikibooks, open books for an open world

60.a) Construct a height-­balanced binary trees with a given number of nodes.

Consider a height­-balanced binary tree of height H. What is the maximum number of nodes it can contain? Clearly, MaxN = 2**H ­ 1. However, what is the minimum number MinN? This question is more difficult.

60.b) Find the minimum number of nodes in a height-­balanced binary tree of height H.

60.c) Find the maximum height H a height­-balanced binary tree with N nodes can have. Find out how many height-­balanced trees exist for N = 15.

# # # THIS IS A STUB # # #

Example in Elm:
import Html exposing (text)
import List

f : Int -> Int
-- your implementation goes here

main = text (toString (f 0))

Result:

4

Solutions