Skip to content

Commit

Permalink
feature:数据结构-队列+树
Browse files Browse the repository at this point in the history
  • Loading branch information
newbeess committed Mar 2, 2021
1 parent b2f1629 commit 4a731c0
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## 数据结构
### 数组(Array)
### 链表(Linked List)
### 堆栈(Stack)
### (Stack)
### 队列(Queue)
### 树(Tree)
### 图(Graph)
Expand Down
129 changes: 128 additions & 1 deletion document/datastructure/数据结构.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,131 @@

### 队列

-
- 队列是一个有序列表,可以用数组或是链表来实现
- 队列只允许在后端(称为*rear*)进行插入操作,在前端(称为*front*)进行删除操作



<img src="../../media/picture/queue.png">

---

###

- 由n(n>0)个有限节点组成一个具有层次关系的集合
- 每一个非根节点有且只有一个父节点
- 树里面没有环路
- 每个节点都只有有限个子节点或无子节点

###### 常用术语

> 1. **节点的度**:一个节点含有的子树的个数称为该节点的度;
> 2. **树的度**:一棵树中,最大的节点度称为树的度;
> 3. **叶节点****终端节点**:度为零的节点;
> 4. **非终端节点****分支节点**:度不为零的节点;
> 5. **父亲节点****父节点**:若一个节点含有子节点,则这个节点称为其子节点的父节点;
> 6. **孩子节点****子节点**:一个节点含有的子树的根节点称为该节点的子节点;
> 7. **兄弟节点**:具有相同父节点的节点互称为兄弟节点;
> 8. 节点的**层次**:从根开始定义起,根为第1层,根的子节点为第2层,以此类推;
> 9. **深度**:对于任意节点n,n的深度为从根到n的唯一路径边的个数,根的深度为0;
> 10. **高度**:对于任意节点n,n的高度为从n到一片树叶的最长路径的边的个数,所有树叶的高度为0;
> 11. **堂兄弟节点**:父节点在同一层的节点互为堂兄弟;
> 12. **节点的祖先**:从根到该节点所经分支上的所有节点;
> 13. **子孙**:以某节点为根的子树中任一节点都称为该节点的子孙。
> 14. **森林**:由m(m>=0)棵互不相交的树的集合称为森林;
###### 树的种类

> - 无序树
>
> > 树中任意节点的子节点之间没有顺序关系,由多个节点都可以当作根节点构成一棵树
>
> - 有序树
>
> > - 二叉树
> >
> > > 每个节点最多含有两个子树的树称为二叉树
> > >
> > > - 二叉树的第i层至多有2<sup>i-1</sup>个结点
> > > - 深度为k的二叉树至多有2<sup>k</sup>-1个结点
> > > - 对任何一棵二叉树T,度为0的结点数为n<sub>0</sub>,度为2的结点数为n<sub>2</sub>,则n<sub>0</sub>=n<sub>2</sub>+1
> >
> > - 完全二叉树
> >
> > > 对于一棵二叉树,假设其深度为d(d>1)。除了第d层外,其它各层的节点数目均已达最大值,且第d层所有节点从左向右连续地紧密排列,这样的二叉树被称为完全二叉树
> >
> > - 满二叉树
> >
> > > 对于一棵二叉树,假设其深度为d(d>1)。除了第d层外,其它各层的节点数目均已达最大值,且第d层所有节点从左向右连续地紧密排列,这样的二叉树被称为完全二叉树
> >
> > - 平衡二叉树|AVL树
> >
> > > 两棵子树的高度差不大于1的二叉树
> >
> > - 二叉查找树|排序二叉树|二叉搜索树|有序二叉树|Binary Search Tree
> >
> > > - 1) 若左子树不空,则左子树上所有结点的值均小于它的根结点的值;
> > > - 2) 若右子树不空,则右子树上所有结点的值均大于或等于它的根结点的值;
> > > - 3) 左、右子树也分别为二叉排序树;
> > > - 4) 没有键值相等的节点
> >
> > - 平衡查找树
> >
> > > 自平衡的查找树
> >
> > -
> >
> > - 霍夫曼树|最优二叉树
> >
> > > 带权路径最短的二叉树称为哈夫曼树
> >
> > - B树(MogoDB索引使用)
> >
> > > 一种对读写操作进行优化的自平衡的多叉查找树,能够保持数据有序,拥有多于两个子树
> > >
> > > B树是对二叉查找树的改进
> > >
> > > 它的设计思想是,将相关数据尽量集中在一起,以便一次读取多个数据,减少硬盘操作次数
> > >
> > > <img src ="../../media/picture/BTree.png">
> >
> > - B+树(Mysql索引使用)
> >
> > >- B-Tree的改进版本,可以查找连续的数据。
> > >
> > >- 数据都在叶子节点上,增加了顺序访问指针,每个叶子节点都指向相邻的叶子节点的地址
> > >
> > >- 相比B-Tree来说,进行范围查找时只需要查找两个节点,进行遍历即可
> > >
> > >
> > >
> > ><img src="../../media/picture/B+Tree.png">
> >
> > - 红黑树(IO多路复用epoll的实现采用红黑树组织管理sockfd,java中TreeMap,jdk1.8的hashmap的实现)
> >
> > > 带有颜色属性的二叉查找树,颜色为红色或黑色
> > >
> > > - 节点是红色或黑色。
> > >
> > > - 根是黑色。
> > >
> > > - 所有叶子都是黑色(叶子是NIL节点)。
> > >
> > > - 每个红色节点必须有两个黑色的子节点。(从每个叶子到根的所有路径上不能有两个连续的红色节点。)
> > >
> > > - 从任一节点到其每个叶子的所有简单路径都包含相同数目的黑色节点。
> > >
> > > <img src ="../../media/picture/redBlackTree.png">
> >
> > - trie 树|字典树(前缀匹配)
> >
> > > 一个节点的所有子孙都有相同的前缀,也就是这个节点对应的字符串,而根节点对应空字符串。一般情况下,不是所有的节点都有对应的值,只有叶子节点和部分内部节点所对应的键才有相关的值
> > >
> > > <img src="../../media/picture/TireTree.png">
>
>
---

###

Binary file added media/picture/B+Tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/picture/BTree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/picture/TireTree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/picture/queue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/picture/redBlackTree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4a731c0

Please sign in to comment.