Added hamming and levenshtein distance and counting sort #11

Closed
wants to merge 11 commits into
from

Conversation

2 participants
@smithandrewl

Hi,

I added two string metric algorithms(the hamming and levenshtein distance functions) and another sort(counting sort) with tests.

Thanks,
Andrew

@nryoung

View changes

algorithms/string/metrics/hamming_distance.py
+def distance(str1, str2):
+ assert len(str1) == len(str2)
+
+ dist = 0

This comment has been minimized.

Show comment Hide comment
@nryoung

nryoung Sep 25, 2012

Owner

Is the variable dist necessary? would it not be better to do:

return sum(char1 != char2 for char1, char2 in zip(str1, str2))
@nryoung

nryoung Sep 25, 2012

Owner

Is the variable dist necessary? would it not be better to do:

return sum(char1 != char2 for char1, char2 in zip(str1, str2))
@nryoung

This comment has been minimized.

Show comment Hide comment
@nryoung

nryoung Sep 25, 2012

Owner

It also looks like you need to update your checkouts. Also it looks as if counting_sort is failing the unit tests intermittently. I think it has something to do with the ranges you have set up but I have not looked to deeply in to it yet.

Thanks for your additions though! If you can update your checkout and we can get the unit tests passing I will merge the changes.

Owner

nryoung commented Sep 25, 2012

It also looks like you need to update your checkouts. Also it looks as if counting_sort is failing the unit tests intermittently. I think it has something to do with the ranges you have set up but I have not looked to deeply in to it yet.

Thanks for your additions though! If you can update your checkout and we can get the unit tests passing I will merge the changes.

@smithandrewl

This comment has been minimized.

Show comment Hide comment
@smithandrewl

smithandrewl Oct 2, 2012

I updated the hamming distance as suggested. I also rewrote the counting sort algorithm. I tested the counting sort using the existing test(repeatedly) and added a test from the book.

I updated the hamming distance as suggested. I also rewrote the counting sort algorithm. I tested the counting sort using the existing test(repeatedly) and added a test from the book.

@smithandrewl

This comment has been minimized.

Show comment Hide comment
@smithandrewl

smithandrewl Oct 2, 2012

Oh, and I updated my repo.

Oh, and I updated my repo.

@smithandrewl

This comment has been minimized.

Show comment Hide comment
@smithandrewl

smithandrewl Oct 10, 2012

I cleaned up the code some more. thanks for the suggestions hughdbrown!

I cleaned up the code some more. thanks for the suggestions hughdbrown!

@nryoung nryoung closed this Mar 10, 2013

rhyw pushed a commit to rhyw/algorithms that referenced this pull request Jul 13, 2016

Merge pull request #11 from Xuefeng-Zhu/patch-4
change hard coded default wright in add_edge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment