-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Divide and conquer Algorithms Issue#817 #938
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the code and it's correct.
|
||
|
||
def max_sum_from_start(array): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove new line.
|
||
|
||
def max_cross_array_sum(array, left, mid, right): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove new line.
|
||
|
||
def max_sub_array_sum(array, left, right): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove new line.
|
||
""" | ||
|
||
""" base case: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One line comment with # suffice.
if left == right: | ||
return array[right] | ||
|
||
""" Recursion""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One line comment with # suffice.
return array[right] | ||
|
||
""" Recursion""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this algorithm and it's correct.
strings/Boyer_Moore_Search.py
Outdated
This algorithm tries to find the pattern in given text using Bad Character Heuristic method. | ||
The bad-character rule considers the character in Text at which there is a mis-match. The next occurrence of that character to the left in Pattern is found, and a shift which brings that occurrence in line with the mismatched occurrence in Text is proposed. If the mismatched character does not occur to the left in Pattern, a shift is proposed that moves the entirety of Pattern past the point of mismatch | ||
|
||
Complexity : O(n/m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Time " complexity. Add this word.
strings/Boyer_Moore_Search.py
Outdated
self.textLen, self.patLen = len(text), len(pattern) | ||
|
||
def match_In_Pattern(self, char): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove new line.
strings/Boyer_Moore_Search.py
Outdated
|
||
|
||
def misMatch_In_Text(self, currentPos): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove new line.
strings/Boyer_Moore_Search.py
Outdated
return -1 | ||
|
||
def bad_Character_Heuristic(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove new line.
strings/Boyer_Moore_Search.py
Outdated
self.text, self.pattern = text, pattern | ||
self.textLen, self.patLen = len(text), len(pattern) | ||
|
||
def match_In_Pattern(self, char): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make all methods, functions and variable names lower-case.
strings/Boyer_Moore_Search.py
Outdated
return -1 | ||
|
||
|
||
def misMatch_In_Text(self, currentPos): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make all methods, functions and variable names lower-case.
strings/Boyer_Moore_Search.py
Outdated
@@ -0,0 +1,74 @@ | |||
""" | |||
This algorithm tries to find the pattern in given text using Bad Character Heuristic method. | |||
The bad-character rule considers the character in Text at which there is a mis-match. The next occurrence of that character to the left in Pattern is found, and a shift which brings that occurrence in line with the mismatched occurrence in Text is proposed. If the mismatched character does not occur to the left in Pattern, a shift is proposed that moves the entirety of Pattern past the point of mismatch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a period at the end of the line.
Also, follow PEP8 rules. Makes your lines contain 70 characters or less.
https://www.python.org/dev/peps/pep-0008/
Don't have any long lines.
issue #817
created divide_and_conquer folder and added max_sub_array_sum.py