`

how many different binary trees you can build with N nodes?

阅读更多

how many different binary trees you can build with N nodes?

一棵二叉树可以看成根节点,左子树,右子树。因此N个节点,左子树如果有 j (<= N-1)个节点, 右子树有(N-1-j)个节点,故:

N个节点二叉树数目:

f(n) = f(n-1) + f(1)* f(n-2) +...+f(n-2)*f(1) + f(n-1) = sum( f(j) * f(n-j-1)) ( 0<=j<=n-1)

f(0) = 1, f(1) = 1, f(2) = f(1) + f(1) = 2

 

========================================

f(n) = f(n-1) + f(1)* f(n-2) +...+f(n-2)*f(1) + f(n-1)

第一项是1个根节点,0个左节点,(n-1)右节点的情况:1*f(n-1)

第二项是1个根节点,1个左节点,(n-2)右节点的情况:1*f(1)*f(n-2)

......

.....

..

最后一项是1个根节点,(n-1)个左节点,0个右节点的情况:1*f(n-1)

 

整个这个方程是一个递归的表示方法。这个递归的结果是h(n)=C(2n,n)/(n+1) (n=1,2,3,...)

C是选择符号。

这就是有名的卡特兰数。可以百科一下。

分享到:
评论

相关推荐

    java-leetcode题解之Binary Trees With Factors.java

    java java_leetcode题解之Binary Trees With Factors.java

    Multidimensional Binary Search Trees Used for Associative Searching

    1975年,来自斯坦福大学的Jon Louis Bentley在ACM杂志上发表的一篇论文:Multidimensional Binary Search Trees Used for Associative Searching 中正式提出和阐述的了把空间划分为多个部分的k-d树。

    Java Methods-Binary Trees.ppt

    Java Methods-Binary Trees Binary Trees 是一种特殊的树形数据结构,它广泛应用于数据检索、优先级队列、决策系统、层次结构和游戏等领域。 Java Methods-Binary Trees.ppt 介绍了二叉树的基本概念、表示和操作...

    java-leetcode题解之Flip Equivalent Binary Trees.java

    java java_leetcode题解之Flip Equivalent Binary Trees.java

    java-leetcode题解之All Possible Full Binary Trees.java

    java基础 java_leetcode题解之All Possible Full Binary Trees.java

    Java Binary Trees and Solutions

    这篇博客"Java Binary Trees and Solutions"可能深入探讨了如何在Java中实现二叉树以及与之相关的解决策略。以下是关于二叉树的一些核心知识点: 1. **定义**:二叉树是每个节点最多有两个子节点的树结构,通常称为...

    Learning.Linux.Binary.Analysis.1782

    You will learn about process tracing, and will explore the different types of Linux and UNIX viruses, and how you can make use of ELF Virus Technology to deal with them. The latter half of the book ...

    binary_trees-源码

    二元树(Binary Trees)是计算机科学中一种重要的数据结构,它们在许多算法和程序设计问题中发挥着关键作用。二元树的每个节点最多有两个子节点,通常称为左子节点和右子节点。这种数据结构允许快速查找、插入和删除...

    Self-Adjusting Binary Search Trees (1985)-计算机科学

    Self-Adjusting Binary Search TreesDANIEL DOMINIC SLEATOR A N D ROBERT ENDRE TARJANA T&T Bell Laboratories, Murray Hill, NJAbstract. The splay tree, a self-adjusting form of binary search tree, is ...

    Zemax使用Binary-2面型设计案例,How-to-use-Binary-2.zip

    提供的两个文件:"How to use Binary 2.SES"和"How to use Binary 2.zmx"分别是Zemax的系统设置文件和设计文件。SES文件包含了光学系统的几何布局和材料属性等信息,而ZMX文件则是具体的优化和分析结果,包括面型...

    Learning Linux Binary Analysis(PACKT,2016)

    You will learn about process tracing, and will explore the different types of Linux and UNIX viruses, and how you can make use of ELF Virus Technology to deal with them. The latter half of the book ...

    cisco_ios_access_lists.pdf

    Protocol (IP), though you could probably use many of the same techniques with other network protocols as well. While all the examples involve Cisco IOS access lists, many of the concepts are generic...

    tensorflow1.12支持cuda10

    Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note ...

    Advanced Topics in C.pdf

    You will increase the range of problems you can solve when you learn how to manipulate versatile and popular data structures such as binary trees and hash tables. This book assumes you have a ...

    tensorflow-1.12支持cuda10.0

    Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note ...

    陈越、何钦铭-数据结构作业16:Complete Binary Search Tree完全二叉搜索树

    Both the left and right subtrees must also be binary search trees. A Complete Binary Tree (CBT) is a tree that is completely filled, with the possible exception of the bottom level, which is filled ...

    学习linux二进制分析英文版

    You will learn about process tracing, and will explore the different types of Linux and UNIX viruses, and how you can make use of ELF Virus Technology to deal with them., The latter half of the book ...

    Xcode build时报错: Cannot link directly with dylib/framewor

    解决[IOS自动化]Xcode build时报错: Cannot link directly with dylib/framework XcodeDriverAgent文件包,用于替换 /usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent....

    Git Recipes

    With recipes to cover any task you can think of, including working with GitHub and git on BitBucket, Git Recipes shows you how to work with large repositories, new repositories, forks, clones, ...

Global site tag (gtag.js) - Google Analytics