-
-
Notifications
You must be signed in to change notification settings - Fork 359
Add Merge Sort algo chapter and Python example #163
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
17dcbc7
create merge_sort.py
Mukundan314 879b3fc
Add mukundan to CONTRIBUTORS.md
Mukundan314 fa0a670
Create merge_sort.md
Mukundan314 7d01395
Merge branch 'master' into master
Mukundan314 f46d0c8
Change merg_sort.md into a stub file
Mukundan314 c0e5c79
Merge branch 'master' into master
Mukundan314 495cd91
Merge branch 'master' into master
Mukundan314 42c72b1
Merge
Mukundan314 30a5ab2
Update multiplication.md
Mukundan314 da746c6
Merge branch 'master' into master
Mukundan314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ Hitesh C | |
Maxime Dherbécourt | ||
Jess 3Jane | ||
Pen Pal | ||
Chinmaya Mahesh | ||
Mukundan | ||
Chinmaya Mahesh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import random | ||
|
||
|
||
def merge(l1, l2): | ||
i = j = 0 | ||
l = [] | ||
|
||
while (i < len(l1)) and (j < len(l2)): | ||
if l1[i] < l2[j]: | ||
l.append(l1[i]) | ||
i += 1 | ||
else: | ||
l.append(l2[j]) | ||
j += 1 | ||
|
||
l.extend(l1[i:len(l1)]) | ||
l.extend(l2[j:len(l2)]) | ||
|
||
return l | ||
|
||
|
||
def merge_sort(l): | ||
if len(l) == 1: | ||
return l | ||
|
||
l1 = merge_sort(l[0:len(l)//2]) | ||
l2 = merge_sort(l[len(l)//2:len(l)]) | ||
|
||
return merge(l1, l2) | ||
|
||
|
||
def main(): | ||
number = [random.randint(0, 10000) for _ in range(10)] | ||
print("Before Sorting {}".format(number)) | ||
number = merge_sort(number) | ||
print("After Sorting {}".format(number)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This Chapter is comming soon | ||
|
||
{% method %} | ||
{% sample lang="py" %} | ||
[import:1-40, lang:"python"](code/python/merge.py) | ||
{% endmethod %} | ||
|
||
<script> | ||
MathJax.Hub.Queue(["Typeset",MathJax.Hub]); | ||
</script> | ||
$$ | ||
\newcommand{\d}{\mathrm{d}} | ||
\newcommand{\bff}{\boldsymbol{f}} | ||
\newcommand{\bfg}{\boldsymbol{g}} | ||
\newcommand{\bfp}{\boldsymbol{p}} | ||
\newcommand{\bfq}{\boldsymbol{q}} | ||
\newcommand{\bfx}{\boldsymbol{x}} | ||
\newcommand{\bfu}{\boldsymbol{u}} | ||
\newcommand{\bfv}{\boldsymbol{v}} | ||
\newcommand{\bfA}{\boldsymbol{A}} | ||
\newcommand{\bfB}{\boldsymbol{B}} | ||
\newcommand{\bfC}{\boldsymbol{C}} | ||
\newcommand{\bfM}{\boldsymbol{M}} | ||
\newcommand{\bfJ}{\boldsymbol{J}} | ||
\newcommand{\bfR}{\boldsymbol{R}} | ||
\newcommand{\bfT}{\boldsymbol{T}} | ||
\newcommand{\bfomega}{\boldsymbol{\omega}} | ||
\newcommand{\bftau}{\boldsymbol{\tau}} | ||
$$ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"coming" is spelled with only one "m".