📜  布隆过滤器和哈希表的区别

📅  最后修改于: 2021-09-13 02:52:18             🧑  作者: Mango

哈希表:
Hashtable 旨在使用称为 Hash函数的特殊函数,该函数用于将给定值与特定键映射,以便更快地访问元素。它用于需要快速查找的地方。(在合理的假设下,哈希表中元素查找的平均时间为 O(1) )。 Python的字典是使用 HashTables 实现的。 Java还实现了 HashTable 类。
可以在此处找到散列的一些应用。

布隆过滤器:
布隆过滤器是一种节省空间的概率数据结构,用于测试元素是否是集合的成员。它用于我们只需要知道元素是否属于对象的地方。布隆过滤器使用 k 个散列函数和 n 位数组,其中数组位设置为 0,表示元素不存在,1 表示元素存在。布隆过滤器的一些应用是:

  • Google Bigtable、Apache HBase 和 Apache Cassandra 和 PostgreSQL 使用 Bloom 过滤器来减少对不存在的行或列的磁盘查找。避免昂贵的磁盘查找可显着提高数据库查询操作的性能。
  • Google Chrome 网络浏览器曾经使用 Bloom 过滤器来识别恶意 URL。首先根据本地 Bloom 过滤器检查任何 URL,并且只有当 Bloom 过滤器返回正面结果时,才会对执行的 URL 进行全面检查(并且用户警告,如果也返回正面结果)。

让我们看看哈希表和布隆过滤器之间的区别:

S No. Hash Tables Bloom Filters
1 In hash table the object gets stored to the bucket(index position in the hashtable) the hash function maps to. Bloom filters doesn’t store the associated object. It just tells whether it is there in the bloom filter or not.
2 Hash tables are less space efficient. Bloom filters are more space efficient. it’s size is even the less than the associated object which it is mapping.
3 Supports deletions. It is not possible to delete elements from bloom filters.
4 Hashtables give accurate results.  Bloom filters have small false positive probability. ( False positive means it might be in bloom filter but actually it is not.)
5 In a hashtable either we should implement multiple hash functions or have a strong hash function to minimize collisions. A bloom filter uses many hash functions. There is no need to handle collisions.
6 Hashtables are used in compiler operations, programming languages(hash table based data structures),password verification, etc. Bloom filters find application in network routers, in web browsers(to detect the malicious urls), in password checkers(to not a set a weak or guessable or list of forbidden passwords), etc.

HashTable 和布隆过滤器彼此密切相关,因此,比较这两种数据结构并根据您的应用程序/需求明智地使用它们是明智的。

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程