Binary Merge sort & Natural Merge sort

痴心易碎 提交于 2019-12-10 18:55:36

问题


I know that homework questions are not the most popular on here, but I am at a total loss. I am doing an assignment which requires us to make multiple sorting algorithms. One of them however, is driving me insane. I can find no examples of it online anywhere, and he did not go over it fully in class. We have to make a merge sort that looks like this:

void mergeSort(int * a, int s, bool n = false)

Where a is the array, s is the size of said array, and n is false for binary merge sort, and true for natural merge sort. The problem is, I cant find what natural merge sort and binary merge sort are. I just find mergesort. And all of them ask for far more variables.

I am simply asking if anyone knows where I can find a good explanation of those two different types of mergesort.


回答1:


I'm no expert on the topic, but the wikipedia page seems to be a good starting point http://en.wikipedia.org/wiki/Merge_sort

It contains a section on natural merge sort with an example.

About binary merge sort:

A variant named binary merge sort uses a binary insertion sort to sort groups of 32 elements, followed by a final sort using merge sort. It combines the speed of insertion sort on small data sets with the speed of merge sort on large data sets

And insertion sort may be read about here: http://en.wikipedia.org/wiki/Insertion_sort

which contains a selection on binary insertion sorting.

About the variables. The wikipedia example of 'bottom up merge sort' (of which natural merge sort is a variant) has this signature:

void BottomUpSort(A[], B[], n)

where A is the array to be sorted, n its length. B is a work array, and if a read the algoritm right it needs be of length n too. Anyway, it can be created in the beginning of the algoritm and deleted in the end.



来源:https://stackoverflow.com/questions/29460179/binary-merge-sort-natural-merge-sort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!