diff --git a/computing_sh/Python11_Hash_Table_Search.ipynb b/computing_sh/Python11_Hash_Table_Search.ipynb index 0450863..6b1f01e 100644 --- a/computing_sh/Python11_Hash_Table_Search.ipynb +++ b/computing_sh/Python11_Hash_Table_Search.ipynb @@ -207,4 +207,100 @@ ] } ] -} \ No newline at end of file +} + + +# hash function +def hash(key): + return key % N + +def insert(key, data): + index = hash(key) + if hash_table[index] == -1: # available + hash_table[index] = data + else: # collision + i = index + 1 + while hash_table[i] != -1: + i += 1 + hash_table[i] = data + +def search(key, data): + index = hash(key) + if hash_table[index] == data: # found + return "BINGO!" + elif hash_table[index] == -1: + return "Not found" + else: # collided records + i = index + 1 + if i