目录

数据结构树

数据结构(树)

数据结构(树)

树的基本概念

样子

树是一种非线性的数据结构,它是由n(n>=0)个有限结点组成一个具有层次关系的集合。把它叫做树是因 为它看起来像一棵倒挂的树,也就是说它是根朝上,而叶朝下的

  • 有一个特殊的结点,称为根结点,根节点没有前驱结点
  • 除根节点外,其余结点被分成M(M>0)个互不相交的集合T1、T2、……、Tm,其中每一个集合Ti(1<= i <= m)又是一棵结构与树类似的子树。每棵子树的根结点有且只有一个前驱,可以有0个或多个后继
  • 因此,树是递归定义的。

https://i-blog.csdnimg.cn/direct/3b37561331674e0d89dc476a38fbc9da.png

树的相关概念

https://i-blog.csdnimg.cn/direct/880be3bc3f6349de8692242f4fcae053.png

https://i-blog.csdnimg.cn/direct/59e1eedd184f42c2bd85a33dfb5dedeb.png

https://i-blog.csdnimg.cn/direct/7188c3a92a9f47189f543884c6e37375.png

树的存储

https://i-blog.csdnimg.cn/direct/da4b597935bc408196f5cd85c5fe56b8.png

https://i-blog.csdnimg.cn/direct/d57738db8d014249ab313606db562354.png

双亲表示法

https://i-blog.csdnimg.cn/direct/361e308800ec4fa0a9c31e935e6594f6.png

  • 双亲表示法好处就是可以快速的找到双亲节点/父节点,缺点也很明显比较难找孩子

二叉树

https://i-blog.csdnimg.cn/direct/c013cc1afcd34eca8306269f67264490.png

特殊的二叉树

https://i-blog.csdnimg.cn/direct/ee1825267c83485a9620e9bad977d5c5.png

https://i-blog.csdnimg.cn/direct/ca20986e5ef04bf488c075087682c945.png

https://i-blog.csdnimg.cn/direct/44b5691c15364aaeb92b10dbede960eb.png

二叉树的存储

https://i-blog.csdnimg.cn/direct/c700b875dc8d42bdb41ef6520556a400.png

堆排序

https://i-blog.csdnimg.cn/direct/51c28cddc2684927ad8d0c5822907ff1.png