Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in 8.10 Java solution #75

Open
primshnick opened this issue Nov 20, 2014 · 0 comments
Open

Bug in 8.10 Java solution #75

primshnick opened this issue Nov 20, 2014 · 0 comments

Comments

@primshnick
Copy link

In the Java solution for 8.10, if there is a collision in the bucket where the new element is to be placed, the current code uses collided.remove(c) where collided is the LinkedList object and c is the node in the bucket's list. But calling remove(...) on the LinkedList object itself, and not the iterator, will remove the element by starting at the beginning of the list and traversing until it finds the element. This has 2 problems 1) If the item removed is the second to last element in the list, the loop will never visit the last element (In my opinion the LinkedList iterator should actually throw a ConcurrentModificiationException here, but the check is in next(), and not hasNext() ). 2) This eliminates the benefit of using a LinkedList. The for loop should explicitly use the List's iterator, and then the remove should be done using the remove method of the iterator. This will take O(1) time instead of O(n), where n is the number of items in the bucket.

@primshnick primshnick changed the title Minor issue with 8.10 Java solution Bug in 8.10 Java solution Nov 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant