-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# dict(map)实现算法 | ||
|
||
----- | ||
## 哈希表 | ||
|
||
这是比较常见的实现方式,时间复杂度O(n),但是在需要解决哈希冲突的问题 | ||
|
||
常见的哈希冲突解决方法如下 | ||
|
||
|
||
### 拉链法 | ||
|
||
使用链表串联冲突项,遇到冲突顺着链表一个个判断 | ||
|
||
代表实现: | ||
|
||
- Java的HashMap | ||
|
||
### 公共缓冲区 | ||
|
||
|
||
|
||
### 开放寻址法 | ||
|
||
----- | ||
## 二叉树/多叉树 | ||
|
||
二叉树也是常见的表实现方案,时间复杂度为log(n),比hashmap性能差一点 | ||
|
||
但是相比于hashmap而言,二叉树不用构造hash算法,搜索时间非常稳定,不会有hash冲突的情况发生。 | ||
|
||
### 二叉(平衡)树 | ||
|
||
### 红黑树 | ||
|
||
代表实现: | ||
|
||
- C++的stl中的map |