From 17dcbc77bf1ca3f986daba5115fee0cf01915858 Mon Sep 17 00:00:00 2001 From: mukundan314 Date: Fri, 29 Jun 2018 10:07:28 +0530 Subject: [PATCH 1/5] create merge_sort.py --- .../merge/code/python/merge.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 chapters/sorting_searching/merge/code/python/merge.py diff --git a/chapters/sorting_searching/merge/code/python/merge.py b/chapters/sorting_searching/merge/code/python/merge.py new file mode 100644 index 000000000..1c19df7ba --- /dev/null +++ b/chapters/sorting_searching/merge/code/python/merge.py @@ -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() From 879b3fc615a36e13dc586672f076b75c951921d9 Mon Sep 17 00:00:00 2001 From: mukundan314 Date: Fri, 29 Jun 2018 10:07:59 +0530 Subject: [PATCH 2/5] Add mukundan to CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 57640d2d6..ddc64fce3 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -8,3 +8,4 @@ Hitesh C Maxime Dherbécourt Jess 3Jane Pen Pal +Mukundan From fa0a670e810f78fb1dcb7f631840b12c52924396 Mon Sep 17 00:00:00 2001 From: mukundan314 Date: Fri, 29 Jun 2018 15:37:44 +0530 Subject: [PATCH 3/5] Create merge_sort.md --- .../sorting_searching/merge/merge_sort.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 chapters/sorting_searching/merge/merge_sort.md diff --git a/chapters/sorting_searching/merge/merge_sort.md b/chapters/sorting_searching/merge/merge_sort.md new file mode 100644 index 000000000..6924f404a --- /dev/null +++ b/chapters/sorting_searching/merge/merge_sort.md @@ -0,0 +1,40 @@ +# Merge Sort + +In computer science, merge sort (also commonly spelled mergesort) is an efficient, general-purpose, comparison-based sorting algorithm. +Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output. +Merge sort is a divide and conquer algorithm that was invented by John von Neumann in 1945. +A detailed description and analysis of bottom-up mergesort appeared in a report by Goldstine and von Neumann as early as 1948. + +Conceptually, a merge sort works as follows: + 1. Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted). + 2. Repeatedly merge sublists to produce new sorted sublists until there is only 1 sublist remaining. This will be the sorted list. + +{% method %} +{% sample lang="py" %} +[import:1-40, lang:"python"](code/python/merge.py) +{% endmethod %} + +This algorithim can be made faster by doing the merge operations in parallel. + + +$$ +\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}} +$$ From f46d0c89f3d7357f872c6d49daa036757c99feda Mon Sep 17 00:00:00 2001 From: mukundan314 Date: Fri, 29 Jun 2018 17:39:17 +0530 Subject: [PATCH 4/5] Change merg_sort.md into a stub file --- chapters/sorting_searching/merge/merge_sort.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/chapters/sorting_searching/merge/merge_sort.md b/chapters/sorting_searching/merge/merge_sort.md index 6924f404a..48d4a89f1 100644 --- a/chapters/sorting_searching/merge/merge_sort.md +++ b/chapters/sorting_searching/merge/merge_sort.md @@ -1,21 +1,10 @@ -# Merge Sort - -In computer science, merge sort (also commonly spelled mergesort) is an efficient, general-purpose, comparison-based sorting algorithm. -Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output. -Merge sort is a divide and conquer algorithm that was invented by John von Neumann in 1945. -A detailed description and analysis of bottom-up mergesort appeared in a report by Goldstine and von Neumann as early as 1948. - -Conceptually, a merge sort works as follows: - 1. Divide the unsorted list into n sublists, each containing 1 element (a list of 1 element is considered sorted). - 2. Repeatedly merge sublists to produce new sorted sublists until there is only 1 sublist remaining. This will be the sorted list. +# This Chapter is comming soon {% method %} {% sample lang="py" %} [import:1-40, lang:"python"](code/python/merge.py) {% endmethod %} -This algorithim can be made faster by doing the merge operations in parallel. - From 30a5ab255e91e1e53d9433d0082d14cae83ea332 Mon Sep 17 00:00:00 2001 From: Mukundan <30190448+Mukundan314@users.noreply.github.com> Date: Fri, 27 Jul 2018 11:28:27 +0530 Subject: [PATCH 5/5] Update multiplication.md --- contents/multiplication/multiplication.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contents/multiplication/multiplication.md b/contents/multiplication/multiplication.md index d6b1abeec..2d3314b65 100644 --- a/contents/multiplication/multiplication.md +++ b/contents/multiplication/multiplication.md @@ -6,8 +6,8 @@ Even so, there are plenty of incredibly complicated algorithms out there to perf In some sense, this is what I love about computer science research! It takes operations that everyone knows and loves, abstracts them, and transforms them into fast and efficient methods for the computer to implement. Sometimes these algorithms are completely baffling. -I remember laughing for ten minutes after I heard that fft convolutions could be used to calculate a simple integer multiplicationing the Schönhage–Strassen algorithm. -I thought, "Why would you ever want to use an fft to do something to trivial? This has to be a joke!" +I remember laughing for ten minutes after I heard that FFT(Fast Fourier Transform) convolutions could be used to calculate a simple integer multiplicationing the Schönhage–Strassen algorithm. +I thought, "Why would you ever want to use an FFT to do something to trivial? This has to be a joke!" Oh boy was I wrong. The Schönhage–Strassen algorithm was actually the most efficient method to multiply two numbers until around 2007 when it was dethroned by the Fürer's algorithm.