Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Unlambder
<br>
Kjetil Johannessen
<br>
Mukundan
<br>
CDsigma
<br>
Gammison
Expand Down Expand Up @@ -61,4 +63,3 @@ Bendik Samseth
Trashtalk
<br>
Cyrus Burt

40 changes: 40 additions & 0 deletions contents/sorting_and_searching/merge/code/python/merge.py
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()
29 changes: 29 additions & 0 deletions contents/sorting_and_searching/merge/merge_sort.md
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}}
$$