树
1 基本概念
1.1 逻辑结构
![image-20210625145114964](https://tva1.sinaimg.cn/large/008i3skNgy1gruikq6ig7j30v40ih4qp.jpg)
![image-20210625145135992](https://tva1.sinaimg.cn/large/008i3skNgy1gruil2p4d5j30v40jv7wh.jpg)
![image-20210625145157677](https://tva1.sinaimg.cn/large/008i3skNgy1gruilg3pcdj30v40dcawq.jpg)
![image-20210625145214834](https://tva1.sinaimg.cn/large/008i3skNgy1gruilr6q8lj30u00utu0x.jpg)
![image-20210625145236809](https://tva1.sinaimg.cn/large/008i3skNgy1gruim588eyj30u00x21ky.jpg)
![image-20210625145255387](https://tva1.sinaimg.cn/large/008i3skNgy1gruimgby4rj30v40dsqqf.jpg)
1.2 存储结构
1.2.1 顺序存储结构-双亲存储结构
![image-20210625145354737](https://tva1.sinaimg.cn/large/008i3skNgy1gruinhnz4uj30v40io4qp.jpg)
1.2.2 链式存储结构-孩子结构
![image-20210625145452817](https://tva1.sinaimg.cn/large/008i3skNgy1gruiohuv08j30v40gae77.jpg)
2 二叉树
2.1 概念 & 逻辑结构
![image-20210625145539535](https://tva1.sinaimg.cn/large/008i3skNgy1gruipb48m6j30v40er1hy.jpg)
![image-20210625145556389](https://tva1.sinaimg.cn/large/008i3skNgy1gruipljisrj30v40eq4m4.jpg)
![image-20210625145610315](https://tva1.sinaimg.cn/large/008i3skNgy1gruipu9vicj30v40s7npd.jpg)
![image-20210625145624238](https://tva1.sinaimg.cn/large/008i3skNgy1gruiq3286qj30v40pckjl.jpg)
![image-20210625145727636](https://tva1.sinaimg.cn/large/008i3skNgy1gruirdp9rgj30u01evq7s.jpg)
![image-20210625145818254](https://tva1.sinaimg.cn/large/008i3skNgy1gruis2gfp3j30u00wt1ky.jpg)
![image-20210625145919544](https://tva1.sinaimg.cn/large/008i3skNgy1gruit4pak1j30v40d9kdj.jpg)
![image-20210625145935708](https://tva1.sinaimg.cn/large/008i3skNgy1gruitec8aej30v40hs1kx.jpg)
2.2 性质
![image-20210625150109072](https://tva1.sinaimg.cn/large/008i3skNgy1gruiv0yyb0j30v40ic4qp.jpg)
![image-20210625150223317](https://tva1.sinaimg.cn/large/008i3skNgy1gruiwbh4umj30u00uju0x.jpg)
![image-20210625150240194](https://tva1.sinaimg.cn/large/008i3skNgy1gruiwlqpn5j30u010kb2a.jpg)
2.3 存储结构
2.3.1 顺序存储结构
![image-20210625150409953](https://tva1.sinaimg.cn/large/008i3skNgy1gruiy5ssmhj30v40e0e34.jpg)
2.3.2 链式存储结构
![image-20210625150455312](https://tva1.sinaimg.cn/large/008i3skNgy1gruiyy1a07j30v40h51kx.jpg)
![image-20210625150510386](https://tva1.sinaimg.cn/large/008i3skNgy1gruiz762m8j30v40fix53.jpg)
2.4 二叉链表存储结构-同辈表亲连一起
![image-20210625150653022](https://tva1.sinaimg.cn/large/008i3skNgy1gruj0zbainj30v40ddh8l.jpg)
![image-20210625150710110](https://tva1.sinaimg.cn/large/008i3skNgy1gruj1a98blj30v40f67uu.jpg)
3 树与二叉树互换
3.1 树与二叉树互换
![image-20210625150816421](https://tva1.sinaimg.cn/large/008i3skNgy1gruj2g5k9kj30u016qnpe.jpg)
![image-20210625150835282](https://tva1.sinaimg.cn/large/008i3skNgy1gruj2rfk9bj30u01cu4qr.jpg)
![image-20210625150857906](https://tva1.sinaimg.cn/large/008i3skNgy1gruj35ug6rj30u01lxnpf.jpg)
![image-20210625150918638](https://tva1.sinaimg.cn/large/008i3skNgy1gruj3i4yu9j30v40t5u0x.jpg)
3.2 森林与二叉树互换
![image-20210625151016080](https://tva1.sinaimg.cn/large/008i3skNgy1gruj4i7askj30v40a97lw.jpg)
![image-20210625151047411](https://tva1.sinaimg.cn/large/008i3skNgy1gruj51euq2j30v40e3x2t.jpg)
![image-20210625151112748](https://tva1.sinaimg.cn/large/008i3skNgy1gruj5hekgnj30u00wm1ky.jpg)
![image-20210625151130786](https://tva1.sinaimg.cn/large/008i3skNgy1gruj5t4yi5j30u00y54qq.jpg)
![image-20210625151155840](https://tva1.sinaimg.cn/large/008i3skNgy1gruj68lwpnj30u00va1ky.jpg)
4 遍历
定义:一个一个扫描过去
4.1 二叉树的遍历
4.1.1 层次遍历-广度优先遍历
![image-20210625151357731](https://tva1.sinaimg.cn/large/008i3skNgy1gruj8ckwr2j30v40hv4qp.jpg)
4.1.2 深度优先遍历-中序、先序、后序
![image-20210625151637022](https://tva1.sinaimg.cn/large/008i3skNgy1grujb417h9j30v40j07wh.jpg)
![image-20210625151714197](https://tva1.sinaimg.cn/large/008i3skNgy1grujbr8zjtj30u00wp4qq.jpg)
4.2 树的遍历
4.2.1 层次遍历-广度优先遍历
![image-20210625151922400](https://tva1.sinaimg.cn/large/008i3skNgy1grujdzbms5j30v40kx7wh.jpg)
4.2.2 深度优先遍历
![image-20210625152006846](https://tva1.sinaimg.cn/large/008i3skNgy1grujer7rvyj30v40fz1kx.jpg)
![image-20210625152111310](https://tva1.sinaimg.cn/large/008i3skNgy1grujfvlyqqj30u00x41ky.jpg)
4.3 森林的遍历
![image-20210625152209747](https://tva1.sinaimg.cn/large/008i3skNgy1grujgxbk8gj30u00x31ky.jpg)
![image-20210625152229682](https://tva1.sinaimg.cn/large/008i3skNgy1grujh8l4luj30v40i34qp.jpg)
5 递归函数初识
![image-20210625152343759](https://tva1.sinaimg.cn/large/008i3skNgy1grujiikbefj30v40danjv.jpg)
![image-20210625152429088](https://tva1.sinaimg.cn/large/008i3skNgy1grujjal23aj30v40d1h7m.jpg)
![image-20210625152526454](https://tva1.sinaimg.cn/large/008i3skNgy1grujkbbv9ij30v40gs1kx.jpg)
6 遍历代码
6.1 二叉树遍历代码
![image-20210625152655102](https://tva1.sinaimg.cn/large/008i3skNgy1grujlu4cdtj30v40pwhdt.jpg)
7 二叉树非递归遍历
7.1 递归函数原理
![image-20210625154908144](https://tva1.sinaimg.cn/large/008i3skNgy1gruk8y69gkj30v40jb4qp.jpg)
7.2 先序遍历非递归化-从上往下,从右往左入栈
![image-20210625155123338](https://tva1.sinaimg.cn/large/008i3skNgy1grukbatz6xj30v40ht1kx.jpg)
![image-20210625155150569](https://tva1.sinaimg.cn/large/008i3skNgy1grukbrlropj30v40nlhdt.jpg)
7.3 后序遍历非递归化
![image-20210625155225284](https://tva1.sinaimg.cn/large/008i3skNgy1grukcde0hxj30v40ehx3l.jpg)
![image-20210625155245995](https://tva1.sinaimg.cn/large/008i3skNgy1grukcq5z42j30v40e8x36.jpg)
7.4 中序遍历非递归化-从上往下从左往右入栈
![image-20210625155426863](https://tva1.sinaimg.cn/large/008i3skNgy1grukegzmvlj30v40f67sk.jpg)
8 二叉树层次遍历代码
8.1 二叉树层次遍历
![image-20210625155625070](https://tva1.sinaimg.cn/large/008i3skNgy1grukgipf5ej30v40eue2s.jpg)
![image-20210625155648885](https://tva1.sinaimg.cn/large/008i3skNgy1grukgxhp97j30v40rmqv5.jpg)
8.2 树的优先遍历
8.2.1 树的先序遍历
![image-20210625155820516](https://tva1.sinaimg.cn/large/008i3skNgy1grukiix3gwj30v40gx1kx.jpg)
![image-20210625155851326](https://tva1.sinaimg.cn/large/008i3skNgy1grukj1t9isj30v40f8haz.jpg)
8.2.2 树的广度优先遍历
![image-20210625155921120](https://tva1.sinaimg.cn/large/008i3skNgy1grukjkpw6nj30v40mfe81.jpg)
9 线索二叉树
9.1 中序线索二叉树
9.1.1 逻辑结构
![image-20210625160023321](https://tva1.sinaimg.cn/large/008i3skNgy1grukknlndwj30v40ntauo.jpg)
9.1.2 存储结构
![image-20210625160101276](https://tva1.sinaimg.cn/large/008i3skNgy1gruklb8zcxj30v40gdatz.jpg)
![image-20210625160132635](https://tva1.sinaimg.cn/large/008i3skNgy1grukluvhttj30v40fp4ix.jpg)
![image-20210625160205434](https://tva1.sinaimg.cn/large/008i3skNgy1grukmfleubj30v40ochdt.jpg)
9.2 前序线索二叉树
9.2.1 逻辑结构
![image-20210625160317313](https://tva1.sinaimg.cn/large/008i3skNgy1gruknoiawsj30v40h6h4f.jpg)
9.2.2 代码
![image-20210625160433992](https://tva1.sinaimg.cn/large/008i3skNgy1grukp0984dj30u00wv4qq.jpg)
![image-20210625160501093](https://tva1.sinaimg.cn/large/008i3skNgy1grukph7y35j30u00v01ky.jpg)
9.3 后序线索二叉树
![image-20210625160548211](https://tva1.sinaimg.cn/large/008i3skNgy1grukqau7r3j30v40ezdxu.jpg)
![image-20210625160602085](https://tva1.sinaimg.cn/large/008i3skNgy1grukqj4fmoj30u00xghdt.jpg)
![image-20210625160640482](https://tva1.sinaimg.cn/large/008i3skNgy1grukr7kv7ej30v40j41kx.jpg)
9.4 比较
![image-20210625160707763](https://tva1.sinaimg.cn/large/008i3skNgy1grukrnv1uzj30v40fkh13.jpg)
10 哈夫曼树
10.1 编码问题
![image-20210625160830919](https://tva1.sinaimg.cn/large/008i3skNgy1grukt428qmj30v40ip4qp.jpg)
![image-20210625160857323](https://tva1.sinaimg.cn/large/008i3skNgy1gruktkkj8dj30v40ie4qp.jpg)
10.2 概念和定义
![image-20210625160916844](https://tva1.sinaimg.cn/large/008i3skNgy1gruktwos3pj30v40h0txj.jpg)
![image-20210625160947765](https://tva1.sinaimg.cn/large/008i3skNgy1grukufx21aj30v409ck3i.jpg)
![image-20210625160958767](https://tva1.sinaimg.cn/large/008i3skNgy1grukumvjmmj30v40a8anb.jpg)
![image-20210625161011260](https://tva1.sinaimg.cn/large/008i3skNgy1grukuuufzmj30v409rnaf.jpg)
![image-20210625161026208](https://tva1.sinaimg.cn/large/008i3skNgy1grukv3v4gaj30v40b2tmw.jpg)
![image-20210625161040440](https://tva1.sinaimg.cn/large/008i3skNgy1grukvcqzk5j30v40avwse.jpg)
![image-20210625161055610](https://tva1.sinaimg.cn/large/008i3skNgy1grukvm0a9xj30v40b0wt3.jpg)
10.3 哈夫曼n叉树
![image-20210625161126959](https://tva1.sinaimg.cn/large/008i3skNgy1grukw5yobcj30v40eeqrg.jpg)
![image-20210625161144228](https://tva1.sinaimg.cn/large/008i3skNgy1grukwgm9trj30v40ebqqy.jpg)
11 二叉树的确定
11.1 根据遍历顺序确定二叉树
11.1.1 先序中序?
![image-20210625161258025](https://tva1.sinaimg.cn/large/008i3skNgy1grukxr6ntvj30v40hi7vm.jpg)
![image-20210625161313291](https://tva1.sinaimg.cn/large/008i3skNgy1gruky0cukbj30v40h41kx.jpg)
11.1.2 后序中序?
![image-20210625161344217](https://tva1.sinaimg.cn/large/008i3skNgy1grukyjvwagj30v40ha1kx.jpg)
![image-20210625161359185](https://tva1.sinaimg.cn/large/008i3skNgy1grukysrwoaj30v40g14q0.jpg)
11.1.3 层次遍历中序?
![image-20210625161418443](https://tva1.sinaimg.cn/large/008i3skNgy1grukz51manj30v40jt7wh.jpg)
![image-20210625161431827](https://tva1.sinaimg.cn/large/008i3skNgy1grukzdezjaj30v40hk1kx.jpg)
![image-20210625161453908](https://tva1.sinaimg.cn/large/008i3skNgy1grukzr3eymj30v40kd7wh.jpg)
12 二叉树的估计
12.1 根据遍历顺序估计二叉树
12.1.1 前序中序
![image-20210625161657534](https://tva1.sinaimg.cn/large/008i3skNgy1grul1wgw51j30v40ip4qp.jpg)
![image-20210625161726252](https://tva1.sinaimg.cn/large/008i3skNgy1grul2e6j3rj30v40ix4qp.jpg)
12.1.2 中序后序
![image-20210625161751866](https://tva1.sinaimg.cn/large/008i3skNgy1grul2u7df5j30u00wz4qq.jpg)
12.1.3 前序后序
![image-20210625161827021](https://tva1.sinaimg.cn/large/008i3skNgy1grul3g5dr8j30u00xl4qq.jpg)
12.1.4 前序中序
![image-20210625161851165](https://tva1.sinaimg.cn/large/008i3skNgy1grul3vb3urj30u00xa4qq.jpg)
12.1.5 中序后序
![image-20210625161915493](https://tva1.sinaimg.cn/large/008i3skNgy1grul4ahmq6j30sc0yhnpd.jpg)
13 二叉树表达式-根据表达式建立二叉树
![image-20210625162016054](https://tva1.sinaimg.cn/large/008i3skNgy1grul5cbhy3j30v40o0e81.jpg)
![image-20210625162047493](https://tva1.sinaimg.cn/large/008i3skNgy1grul5w0i94j30v40hw1kx.jpg)
![image-20210625162101716](https://tva1.sinaimg.cn/large/008i3skNgy1grul653dozj30u00wu1ky.jpg)