Skip to content

Divide and conquer Algorithms Issue#817 - #938

Merged
Erfaniaa merged 2 commits into
TheAlgorithms:masterfrom
Dharni0607:issue#817
Jul 2, 2019
Merged

Divide and conquer Algorithms Issue#817#938
Erfaniaa merged 2 commits into
TheAlgorithms:masterfrom
Dharni0607:issue#817

Conversation

@Dharni0607

Copy link
Copy Markdown
Contributor

issue #817
created divide_and_conquer folder and added max_sub_array_sum.py

@ErfaniaaErfaniaa self-assigned this Jul 2, 2019
@Erfaniaa
Erfaniaa self-requested a review July 2, 2019 11:10

@ErfaniaaErfaniaa left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove new line.

@ErfaniaaErfaniaa left a comment

Copy link
Copy Markdown
Member

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.

Comment threadstrings/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)

Copy link
Copy Markdown
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.

Comment threadstrings/Boyer_Moore_Search.py Outdated
self.textLen, self.patLen = len(text), len(pattern)

def match_In_Pattern(self, char):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove new line.

Comment threadstrings/Boyer_Moore_Search.py Outdated


def misMatch_In_Text(self, currentPos):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove new line.

Comment threadstrings/Boyer_Moore_Search.py Outdated
return -1

def bad_Character_Heuristic(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove new line.

Comment threadstrings/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):

Copy link
Copy Markdown
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.

Comment threadstrings/Boyer_Moore_Search.py Outdated
return -1


def misMatch_In_Text(self, currentPos):

Copy link
Copy Markdown
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.

Comment threadstrings/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

Copy link
Copy Markdown
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.

@Dharni0607Dharni0607 changed the title Issue#817Divide and conquer Algorithms Issue#817Jul 2, 2019
@Erfaniaa
Erfaniaa merged commit 0f56ab5 into TheAlgorithms:masterJul 2, 2019
Sign up for freeto 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

@Dharni0607@Erfaniaa