mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-26 04:56:06 +00:00
Sort the coding languages by applications. (#721)
This commit is contained in:
@@ -31,9 +31,9 @@
|
||||
- 使用列表(动态数组)代替链表,从而简化代码。在这种设定下,哈希表(数组)包含多个桶,每个桶都是一个列表。
|
||||
- 以下实现包含哈希表扩容方法。当负载因子超过 $0.75$ 时,我们将哈希表扩容至 $2$ 倍。
|
||||
|
||||
=== "Java"
|
||||
=== "Python"
|
||||
|
||||
```java title="hash_map_chaining.java"
|
||||
```python title="hash_map_chaining.py"
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
@@ -43,9 +43,15 @@
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
=== "Java"
|
||||
|
||||
```python title="hash_map_chaining.py"
|
||||
```java title="hash_map_chaining.java"
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="hash_map_chaining.cs"
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
@@ -55,6 +61,12 @@
|
||||
[class]{hashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="hash_map_chaining.swift"
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "JS"
|
||||
|
||||
```javascript title="hash_map_chaining.js"
|
||||
@@ -67,30 +79,6 @@
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="hash_map_chaining.c"
|
||||
[class]{hashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="hash_map_chaining.cs"
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="hash_map_chaining.swift"
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="hash_map_chaining.zig"
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "Dart"
|
||||
|
||||
```dart title="hash_map_chaining.dart"
|
||||
@@ -103,6 +91,18 @@
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="hash_map_chaining.c"
|
||||
[class]{hashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="hash_map_chaining.zig"
|
||||
[class]{HashMapChaining}-[func]{}
|
||||
```
|
||||
|
||||
值得注意的是,当链表很长时,查询效率 $O(n)$ 很差。**此时可以将链表转换为“AVL 树”或“红黑树”**,从而将查询操作的时间复杂度优化至 $O(\log n)$ 。
|
||||
|
||||
## 开放寻址
|
||||
@@ -130,9 +130,9 @@
|
||||
- 我们使用一个固定的键值对实例 `removed` 来标记已删除元素。也就是说,当一个桶内的元素为 $\text{None}$ 或 `removed` 时,说明这个桶是空的,可用于放置键值对。
|
||||
- 在线性探测时,我们从当前索引 `index` 向后遍历;而当越过数组尾部时,需要回到头部继续遍历。
|
||||
|
||||
=== "Java"
|
||||
=== "Python"
|
||||
|
||||
```java title="hash_map_open_addressing.java"
|
||||
```python title="hash_map_open_addressing.py"
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
@@ -142,9 +142,15 @@
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
=== "Java"
|
||||
|
||||
```python title="hash_map_open_addressing.py"
|
||||
```java title="hash_map_open_addressing.java"
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="hash_map_open_addressing.cs"
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
@@ -154,6 +160,12 @@
|
||||
[class]{hashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="hash_map_open_addressing.swift"
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "JS"
|
||||
|
||||
```javascript title="hash_map_open_addressing.js"
|
||||
@@ -166,30 +178,6 @@
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="hash_map_open_addressing.c"
|
||||
[class]{hashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="hash_map_open_addressing.cs"
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="hash_map_open_addressing.swift"
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="hash_map_open_addressing.zig"
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "Dart"
|
||||
|
||||
```dart title="hash_map_open_addressing.dart"
|
||||
@@ -202,6 +190,18 @@
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="hash_map_open_addressing.c"
|
||||
[class]{hashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="hash_map_open_addressing.zig"
|
||||
[class]{HashMapOpenAddressing}-[func]{}
|
||||
```
|
||||
|
||||
### 多次哈希
|
||||
|
||||
顾名思义,多次哈希方法是使用多个哈希函数 $f_1(x)$、$f_2(x)$、$f_3(x)$、$\dots$ 进行探测。
|
||||
|
||||
Reference in New Issue
Block a user