Skip to content

add ons in string directory - Boyer_Moore_Search #933

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

Merged
merged 1 commit into from
Jul 2, 2019

Conversation

Dharni0607
Copy link
Contributor

@Dharni0607 Dharni0607 commented Jul 1, 2019

#697, I have added Boyer Moore search function(bad character heuristic). Please review and let me know if any changes are required. Thanks. ;)

@Erfaniaa
Copy link
Member

Erfaniaa commented Jul 2, 2019

I think it's "Boyer" Moore Search. If I'm right, please let me change it.

@Erfaniaa Erfaniaa requested review from Erfaniaa and poyea July 2, 2019 08:27
@Dharni0607
Copy link
Contributor Author

Dharni0607 commented Jul 2, 2019 via email

@Dharni0607 Dharni0607 changed the title add ons in string directory - Bayer_Moore_Search add ons in string directory - Boyer_Moore_Search Jul 2, 2019
@Erfaniaa Erfaniaa removed the request for review from poyea July 2, 2019 08:33
Copy link
Member

@Erfaniaa Erfaniaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the requested changes.

m=length of pattern string
"""

class BayerMooreSearch:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the dictation mistake in the class name.

return currentPos + i
return -1

def badCharacterHeuristic(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use snake_case for all methods.
Like: bad_character_heuristic

def badCharacterHeuristic(self):
positions = []
for i in range(self.textLen - self.patLen + 1):
misMatchIndex = self.misMatchInText(i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use snake_case: mismatch_index
Try to use it in all variable names.

return -1


""" following functions tries to find the mis-matched character's index in text from last,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place docstrings after the "def" line.
Explain the parameters and the return value separately.

Please Google "Python docstrings conventions".
https://www.datacamp.com/community/tutorials/docstrings-python#second-head

pattern = "ABC"
bms = BayerMooreSearch(text, pattern)
positions = bms.badCharacterHeuristic()
if(len(positions) == 0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary parentheses

print("No match found")
else:
print("Pattern found in following positions: ")
print(positions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran your code and the algorithm seems to work fine.

@Dharni0607 Dharni0607 force-pushed the issue#697 branch 4 times, most recently from 3377842 to 62d0413 Compare July 2, 2019 11:59
@Erfaniaa Erfaniaa merged commit 27a8184 into TheAlgorithms:master Jul 2, 2019
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

Successfully merging this pull request may close these issues.

3 participants