散列表的空间复杂度是多少?

编程入门 行业动态 更新时间:2024-10-27 16:28:10
本文介绍了散列表的空间复杂度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

32位密钥和32位指针分别存储在哈希表中的大小是多少?

是2 ^ 32时隙* 4字节(key)* 4字节(指向值的指针) = 4 * 10 ^ 6 * 4 * 4 = 64MB?

散列表。

解决方案

散列表与散列函数值和插槽不匹配。散列函数是以比散列函数范围小得多的参考矢量的大小来计算的。因为这个值是固定的,所以在空间复杂度计算中不考虑它。

因此,每个合理散列表的空间复杂度为O(n)。

一般来说,这可以很好地解决。虽然关键空间可能很大,但要存储的值的数量通常很容易预测。当然,数据结构开销在功能上可接受的内存数量通常很明显。

这就是哈希表如此无处不在的原因。它们通常为给定任务提供最好的数据结构,将严格限制的内存开销与log时间复杂度相比较。我喜欢二叉树,但他们通常不会打哈希表。

What is size of a hash table with 32 bit key and 32 bit pointers to values stored separately?

Is it going to be 2^32 slots * 4 Bytes (key) * 4 Bytes (pointers to values) = 4 * 10^6 * 4 * 4 = 64MB ?

I am trying to understand space complexity of hash tables.

解决方案

Hash tables don't match hash function values and slots. The hash function is computed modulo the size of a reference vector that is much smaller than the hash function range. Because this value is fixed, it is not considered in the space complexity computation.

Consequently, the space complexity of every reasonable hash table is O(n).

In general, this works out quite well. While the key space may be large, the number of values to store is usually quite easily predictable. Certainly, the amount of memory that is functionally acceptable for data structure overhead is typically obvious.

This is why hash tables are so ubiquitous. They often provide the best data structure for a given task, mixing strictly bounded memory overhead with better than log2 n time complexity. I love binary trees but they don't usually beat hash tables.

更多推荐

散列表的空间复杂度是多少?

本文发布于:2023-11-30 05:11:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648839.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复杂度   列表   空间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!