diff --git a/03-hashing/README.md b/03-hashing/README.md index 0db7bd7..1ccc963 100644 --- a/03-hashing/README.md +++ b/03-hashing/README.md @@ -16,7 +16,7 @@ The hash function we choose should: We'll make use of a generic string hashing function, expressed below in pseudocode. -``` +```c function hash(string, a, num_buckets): hash = 0 string_len = length(string) @@ -41,7 +41,7 @@ character. We'll use ASCII character codes for this. Let's try the hash function out: -``` +```c hash("cat", 151, 53) hash = (151**2 * 99 + 151**1 * 97 + 151**0 * 116) % 53 @@ -52,7 +52,7 @@ hash = 5 Changing the value of `a` give us a different hash function. -``` +```c hash("cat", 163, 53) = 3 ``` diff --git a/04-collisions/README.md b/04-collisions/README.md index 8228d47..47ae768 100644 --- a/04-collisions/README.md +++ b/04-collisions/README.md @@ -16,7 +16,7 @@ For an overview of other types of collision resolution, see the The index that should be used after `i` collisions is given by: -``` +```c index = hash_a(string) + i * hash_b(string) % num_buckets ``` @@ -29,7 +29,7 @@ will cause the hash table to try to insert the item into the same bucket over and over. We can mitigate this by adding 1 to the result of the second hash, making sure it's never 0. -``` +```c index = (hash_a(string) + i * (hash_b(string) + 1)) % num_buckets ```