C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Confusion about the combine step in Merge Sort Code

By : user2949374
Date : November 17 2020, 01:00 AM
I wish this help you When the two recursive sort routines return, you can safely assume that they have sorted their parts. The merge step combines these two sorted sub arrays. If the input is 3 5 1 8 2, the first recursive call sorts the first half and yields 3 5, the second recursive call sorts the second half and yields 1 2 8.
The merge step, which you asked about, combines these two sorted halves into one by repeatedly choosing the minimum of the two first elements of the two sub arrays and adding it to the result, as in this animation:
code :

Share :

## What are sentinel in C language? I was learning Merge sort and came across using sentinel as infinity in the merge step

By : user3714997
Date : March 29 2020, 07:55 AM
I hope this helps you . A sentinel is a dummy value, used to distinguish between values that are supposed to be there (e.g. user input) and control values (values that need to be handled specially). A simple example of one would be using null to null to mark the end of a list.
In this specific case, the use of infinity simplifies the comparison logic when the two halves of the list are being merged back together (e.g. when merging anything compared to infinity is going to be less, so the handling of the end of the merge is simplified).

## Merge Sort Step by Step

By : David Dickinson
Date : March 29 2020, 07:55 AM
this will help How would a merge sort step by step iteration look? I'm trying to grasp what happens in the merge sort. Ex. How would a list of values such as 25, 64, 22, 46, 20, 65, 90, 66, 48, 98 look step by step in a merge sort? , bottom-up merge sort:
code :
``````25, 64, 22, 46, 20, 65, 90, 66, 48, 98   -> merge groups-of-1 ->
25, 64, 22, 46, 20, 65, 66, 90, 48, 98   -> merge groups-of-2 ->
22, 25, 46, 64, 20, 65, 66, 90, 48, 98   -> merge groups-of-4 ->
20, 22, 25, 46, 64, 65, 66, 90, 48, 98   -> merge groups-of-8 ->
20, 22, 25, 46, 48, 64, 65, 66, 90, 98   result
``````

## I need an illustration about merge sort algorithm ? (recursive invocation step by step please)

By : Fang Liu
Date : March 29 2020, 07:55 AM
hop of those help? Top down merge sort is left first, depth first. Using | to indicate splitting of array, using youtube video sequence
code :
``````|4 2 8 6 0 5 1 7 3 9|
|4 2 8 6 0|5 1 7 3 9|
|4 2|8 6 0|
|4|2|
|2 4|
|8|6 0|
|6|0|
|0 6|
|0 6 8|
|0 2 4 6 8|
|5 1|7 3 9|
|5|1|
|1 5|
|7|3 9|
|3|9|
|3 9|
|3 7 9|
|1 3 5 7 9|
|0 1 2 3 4 5 6 7 8 9|
``````
``````|4 2 8 6 0 5 1 7 3 9|
|4|2|8|6|0|5|1|7|3|9|
|2 4|6 8|0 5|1 7|3 9|
|2 4 6 8|0 1 5 7|3 9|
|0 1 2 4 5 6 7 8|3 9|
|0 1 2 3 4 5 6 7 8 9|
``````

## Merge Sort Complexity Confusion

By : Xavier
Date : March 29 2020, 07:55 AM
this will help The levels of function calls are considered like this(in the book [introduction to algorithms](https://mitpress.mit.edu/books/introduction-algorithms Chapter 2.3.2):

## Type Of Merge Sort Confusion

By : Ivy Fan
Date : March 29 2020, 07:55 AM
it helps some times A binary merge sort has a very simple recursive definition: split the input array into two halves, sort the two halves using binary merge sort, merge the two halves into a sorted sequence. This is what you implemented.
A different version is a bottom-up merge sort. This first splits a sequence up into subsequences of length 1, and then starts merging them.
code :
``````0 1 4 2 3 9 8 7 5 2 1 3 4 2 4 3 4
``````
``````0 1 4 | 2 3 9 | 8 | 7 | 5 | 2 | 1 3 4 | 2 4 | 3 4
``````