Skip to content

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

Merged
merged 2 commits into from
Jul 2, 2019

Conversation

Dharni0607
Copy link
Contributor

issue #817
created divide_and_conquer folder and added max_sub_array_sum.py

@Erfaniaa Erfaniaa self-assigned this Jul 2, 2019
@Erfaniaa Erfaniaa self-requested a review July 2, 2019 11:10
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.

I tested the code and it's correct.



def max_sum_from_start(array):

Copy link
Member

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):

Copy link
Member

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):

Copy link
Member

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:
Copy link
Member

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"""
Copy link
Member

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"""

Copy link
Member

Choose a reason for hiding this comment

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

Remove new line.

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.

I tested this algorithm and it's correct.

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)
Copy link
Member

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.

self.textLen, self.patLen = len(text), len(pattern)

def match_In_Pattern(self, char):

Copy link
Member

Choose a reason for hiding this comment

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

Remove new line.



def misMatch_In_Text(self, currentPos):

Copy link
Member

Choose a reason for hiding this comment

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

Remove new line.

return -1

def bad_Character_Heuristic(self):

Copy link
Member

Choose a reason for hiding this comment

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

Remove new line.

self.text, self.pattern = text, pattern
self.textLen, self.patLen = len(text), len(pattern)

def match_In_Pattern(self, char):
Copy link
Member

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.

return -1


def misMatch_In_Text(self, currentPos):
Copy link
Member

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.

@@ -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
Copy link
Member

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.

@Dharni0607 Dharni0607 changed the title Issue#817 Divide and conquer Algorithms Issue#817 Jul 2, 2019
@Erfaniaa Erfaniaa merged commit 0f56ab5 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.

2 participants