chapter_hashing/hash_map/ #78
Replies: 91 comments 105 replies
-
|
大佬,在”哈希表优势“那一小节中,在“有序数组: 将 1. 中的数组按照学号从小到大排序”中,“1.”找不到对照。4种数据结构用有序列表列出会不会更好一些? |
Beta Was this translation helpful? Give feedback.
-
|
文章中对比五种数据结构各操作的时间复杂度中,链表的插入元素应该是O(n)。 |
Beta Was this translation helpful? Give feedback.
-
|
数据结构操作时间复杂度那,链表删除不是O(1)吗? |
Beta Was this translation helpful? Give feedback.
-
|
在初始化哈希表中(JavaScript 代码): |
Beta Was this translation helpful? Give feedback.
-
这一块儿 typescript 代码是不是不对?获取所有键值对,看起来只 push 了键? |
Beta Was this translation helpful? Give feedback.
-
|
哈希表底层实现是数组、链表、二叉树,那为什么效率可以更高呢 |
Beta Was this translation helpful? Give feedback.
-
|
问一下,为什么不使哈希函数f(x) = x 呢。这样就不会有冲突了。 |
Beta Was this translation helpful? Give feedback.
-
|
受教了,才知道哈希表算的是key和数组下标的关系,之前居然还以为是key 和 value的关系,实在是一点不懂啊哈哈 |
Beta Was this translation helpful? Give feedback.
-
|
array_hash_map.java |
Beta Was this translation helpful? Give feedback.
-
|
哈希表是一个神奇的数据结构。但其实需要细较下它的复杂度,我们仅拿查找 key 为例,人人都说是常数时间复杂度,实际上是过于笼统了,因为没有考虑求 key 的哈希值的复杂度。 比如对于key类型为 string 的哈希表,要在其中找到一个 key,首先需要对这个key做一次哈希计算,字符串的话至少要遍历一次这个字符串,也就是哈希计算的复杂度为 O(m),m 指key的长度,总的查询复杂度也是 O(m)。 当然,对于 int 类型的key,哈希计算的复杂度确实是常数级。 综上,如果 key 是 string 或复合类型(元组等)且 key 的平均长度很长,用哈希表效率非常低。 |
Beta Was this translation helpful? Give feedback.
-
|
有个疑惑,hash表 时间复杂度为啥是O(1),不应该是O(n) 吗? |
Beta Was this translation helpful? Give feedback.
-
|
上面数组,链表和哈希表的对比表看蒙了,应该明确一点。数组如果根据下标查询应该是O(1),而插入元素平均复杂度也应该是O(n),怎么就成了O(1)。链表的插入元素的复杂度为啥是O(1),不是应该是O(N)吗? |
Beta Was this translation helpful? Give feedback.
-
|
我感觉哈希冲突示例图那里容易引起误会。哈希冲突是在添加新元素时发生的,新的元素可能顶掉旧元素,而不是查找时发生的。图里面呈现的是查找过程。 |
Beta Was this translation helpful? Give feedback.
-
|
打卡,手敲了一遍哈希表的数组实现,对index和key才真正分清楚 |
Beta Was this translation helpful? Give feedback.
-
|
也就是理解为哈希表比数组链表拥有更小的时间复杂度是用更大的空间复杂度换的吗? |
Beta Was this translation helpful? Give feedback.
-
|
day05 |
Beta Was this translation helpful? Give feedback.
-
|
学习学习 |
Beta Was this translation helpful? Give feedback.
-
|
我问百度什么是哈希,百度是这么说的: |
Beta Was this translation helpful? Give feedback.
-
|
哈希函数:将较大的输入空间映射到较小的输出空间上 |
Beta Was this translation helpful? Give feedback.
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
请教大佬,表6-1与表4-1的部分复杂度是冲突的?个人认为表4-1表述是正确的,也许是表6-1中写错了?? |
Beta Was this translation helpful? Give feedback.
-
|
哈希斌かわいいね🥹 |
Beta Was this translation helpful? Give feedback.
-
|
你C语言哈希表里MapSet的实现都没写就直接用?😅 |
Beta Was this translation helpful? Give feedback.
-
|
这个哈希表,在我理解的来看,是不是相当于键key和值value分别存储为两个数组,对传统的数组而言,假设想获取里面某个值a,无法直接获得a的索引,所以要通过遍历的方法来找到a,而在用户看来,构建了一个哈希表,设定了a的键为k,这里的k就对应传统数组里的索引,用户是想通过k来直接获取a的值,但是计算机不知道,所以引入了哈希函数,将用户理解的键k,通过哈希函数转换为存储a的数组的索引,这样就能实现元素a的直接查找 |
Beta Was this translation helpful? Give feedback.
-
|
C语言的代码是不是没有实现通奸键获取值 |
Beta Was this translation helpful? Give feedback.
-
|
哈希表原来也包括python中的键值对呀 |
Beta Was this translation helpful? Give feedback.
-
|
从读者的角度来看,最后一节用哈希扩容来应对哈希冲突的方案容易引读者的误解。从冲突处理方案和扩容两方面来描述可能更好些。 |
Beta Was this translation helpful? Give feedback.
-
|
您好! 收到————张贤平
|
Beta Was this translation helpful? Give feedback.
-
|
哈希表简单实现的代码中,不是将key和value封装成一个类了嘛,怎么还用结构体struct,而且结构体默认的都是公有public的吧,无需显式声明? |
Beta Was this translation helpful? Give feedback.
-
|
您好! 收到————张贤平
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
chapter_hashing/hash_map/
Your first book to learn Data Structure And Algorithm.
https://www.hello-algo.com/chapter_hashing/hash_map/
Beta Was this translation helpful? Give feedback.
All reactions