Skip to content

HashCollisionLinearProbing will be unable to retrieve values after initial collision element is removed #23

@macnube

Description

@macnube

In Chapter 7 it seems like there is a serious issue with the way that LinearProbing has been implemented but it could be my lack of knowledge as I'm learning about these things for the first time with your book! In the example code from the book we get:

19 - Gandalf
29 - John
16 - Tyrion
16 - Aaron
13 - Donnie
13 - Ana
5 - Jonathan
5 - Jamie
5 - Sue
32 - Mindy
32 - Paul
10 - Nathan
**** Printing Hash ****
5 -> [Jonathan - jonathan@email.com]
6 -> [Jamie - jamie@email.com]
7 -> [Sue - sue@email.com]
10 -> [Nathan - nathan@email.com]
13 -> [Donnie - donnie@email.com]
14 -> [Ana - ana@email.com]
16 -> [Tyrion - tyrion@email.com]
17 -> [Aaron - aaron@email.com]
19 -> [Gandalf - gandalf@email.com]
29 -> [John - johnsnow@email.com]
32 -> [Mindy - mindy@email.com]
33 -> [Paul - paul@email.com]

If at this point we do the following:

hash.remove('Jonathan')
Now index 5 is assigned to undefined

console.log(hash.get('Jamie'))

we will get undefined because of line 44 which doesn't continue searching because the original table[position] returns undefined.

So it seems like any later entries that we created from a collision cannot be retrieved after the original key is removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions