From 1f174755c9304f0c94ed692fb93d44dfe862244d Mon Sep 17 00:00:00 2001 From: bt3gl <138340846+bt3gl-google@users.noreply.github.com> Date: Sun, 30 Jul 2023 12:22:54 -0700 Subject: [PATCH] Update README.md --- arrays_and_strings/README.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arrays_and_strings/README.md b/arrays_and_strings/README.md index dd14e2a..ffda9d7 100644 --- a/arrays_and_strings/README.md +++ b/arrays_and_strings/README.md @@ -23,10 +23,12 @@
+* the difference between a hash set and a hash map is that the set can never have repeated elements. + * to implement a HashSet data structure, you need to implement: - a hash function (to assign an address to store a given value), and - a collision handling (since the nature of a hash function is to map a value from a space A to a corresponding smaller space B). - + * overall, there are several strategies to resolve the collisions: - separate chaining: for value with the same hash key, we keep them in a bucket, and each bucket is independent of each other. @@ -45,7 +47,7 @@
-* a good choice for buckets is linked lists, as their time complexity for insertion and deletion is constant (once the position to be updated is located). +* a good choice for buckets is linked lists, as their time complexity for insertion and deletion is constant (once the position to be updated is located). you just need to be sure you never insert repeated elements. * time complexicity for search is O(N/K) where N is the number of all possible values and K is the number of predefined buckets (the average size of bucket is N/K). * space complexity is O(K+M), where K is the number of predefined buckets, and M is the number of unique values that have been inserted in the HashSet. * lastly, to optimize search, we could maintain the buckets as sorted lists (and obtain O(logN) time complexity for the lookup operation). however, insert and delete are linear time (as elements would need to be shifted). @@ -56,12 +58,24 @@
-* another option for a bucket is a binary search tree, with O(logN) time complexity for search, insert, and delete. +* another option for a bucket is a binary search tree, with O(logN) time complexity for search, insert, and delete. in addition, bst can not hold repeated elements, just like sets. * time complexity for search is O(logN/K), where N is the number of all possible values and K is the number of predefined buckets. * space complexity is O(K+M) where K is the number of predefined buckets, and M is the number of unique values in the HashSet.
+ +#### implementing a hash map + +
+ +* same as before, we need to tackle two main issues: hash funcion design and collision handling. +* a good approach is using a module function with an array or linked list. at this time, there is no constraint for repeated numbers. + + +
+ + --- ### examples