summaryrefslogtreecommitdiff
path: root/H60.hs
diff options
context:
space:
mode:
Diffstat (limited to 'H60.hs')
-rw-r--r--H60.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/H60.hs b/H60.hs
new file mode 100644
index 0000000..6f3f1b0
--- /dev/null
+++ b/H60.hs
@@ -0,0 +1,18 @@
+import Tree
+import H59
+
+import Data.Maybe
+import Data.List
+
+hbalTreeNodes :: Int -> [Tree Char]
+hbalTreeNodes 0 = [Empty]
+hbalTreeNodes n = concatMap (filter ((==n).countNodes).hbalTree') [minH..maxH]
+ where
+ -- Shenle
+ minNodesSeq = 0:1:zipWith ((+).(1+)) minNodesSeq (tail minNodesSeq)
+
+ minH = ceiling $ logBase 2 $ fromIntegral (n+1)
+ maxH = (fromJust $ findIndex (>n) minNodesSeq) - 1
+ countNodes Empty = 0
+ countNodes (Branch _ t1 t2) = 1 + (countNodes t1) + (countNodes t2)
+