非线性结构-树
树形结构属于非线性结构,树中结点之间具有明确的层次关系,并且结点之间有分支。例如权限、行政组织、家谱等。树形结构最大的特点是:它是一个递归结构。度、深度、层数、左孩子、右孩子、森林之类的名词,这里不就再解释了。
二叉树
二叉树不仅仅只是在树形结构中非常重要,在实际问题解决过程中,往往也是转换为二叉树的形式解决的。例如像Java中的HashMap,抽象出来的数据结构是红黑树。TreeMap,抽象出来的数据结构是二叉排序树。关于定义,这里就不多说了。其最大的特点就是每个结点最多只有两棵子树。
二叉树的存储方式,分为顺序存储结构跟链式存储结构。顺序存储结构比较浪费空间,基本都是采用链式存储。
顺序存储结构是把二叉树补充成一个完全二叉树,添加一些实际上不存在的虚节点,从根节点开始,一层一层从左往右依次存放到顺序表中。
二叉树的遍历主要有三种。先序遍历、中序遍历、后序遍历。所谓的先、中、后,都是相对于对应树或子树的根节点而言的。
先序遍历:其规律是根、左、右。
中序遍历:其规律是左、根、右。
后序遍历:其规律是左、右、根。
C代码
|
|
Java代码
|
|
|
|
B树、B+树
平衡多路查找树,不是很懂,只知道常用于文件系统。可以参阅《MySQL索引背后的数据结构及算法原理》一文。
树、森林与二叉树的转换
把树或森林转换成成对应的二叉树。其转换成二叉树的核心思想是二叉树的结点,左边挂孩子,右边挂兄弟。把二叉树还原成对应的树或森林,也是用同样的原理去还原即可。
非线性结构-图
图的算法比较复杂,了解了一些概念以及图常用算法的原理。并没有写出代码。
有向图、无向图、强连通图、存储结构的邻接矩阵和邻接表、遍历算法的深度优先和广度优先、最小生成树的普利姆算法及克鲁斯卡尔算法、最短路径的迪杰斯特拉算法、拓扑排序等。了解一下这些概念,并能在纸上能够大致画出过程图。还真总结不出什么。