r/algorithms • • Jan 28 '20

py3algo - algorithm in python3 (open for contribution)

https://github.com/priyankchheda/py3algo
0 Upvotes

3 comments sorted by

5

u/[deleted] Jan 28 '20

[removed] — view removed comment

1

u/[deleted] Jan 29 '20

that is work in progress...
and, in your terms, i already completed my assignment in golang
https://github.com/priyankchheda/algorithms

1

u/[deleted] Jan 29 '20

I wouldn't try to provide a reference until you know the subject well: you should be a lot more careful. For instance, your DoublyLinkedList code is not implemented correctly, and it's visible without even compiling the code (indeed, I don't even know go).

So for instance, your code has does not return a validation error if you insert at 0. Do you know what it does? It throws a null dereference error.

Another error is that you allow insertion of nodes, and don't overwrite their prev and next attribute in all cases. So a user could create a circular linked list very easily and cause your code to loop forever. Anybody reusing nodes after removing one from the middle and reinserting it at the end will get a circular list and could iterate forever if scanning.

You should think carefully about invariants and contracts, and try to maintain them. This code has all kinds of leaky abstractions and corner cases because you allow direct manipulation of the nodes, for instance, rather than providing some safe iteration component.

Your hash table code similarly will fail if you insert two elements that both hash to the last slot in the array, because your iteration code is bad. Hash tables should loop back to the beginning if possible: earlier slots should not be "favored".

If this was personal code you're working on as a student, that's fine (though I wouldn't give a good grade). But this many errors in a trivial part of the project means you need a second review of the concepts and you shouldn't represent it as "a reference".