---
layout: post
title:  "Algorithm Note 02: Merge Sort"
date: 2016-08-16
categories: Algorithm
tags:  Algorithm
---

* content
{:toc}

TODO: 

- [ ] Add descriptions of merge sort algorithm
- [ ] Add C++ implementation


## Merge Sort

![Illustration of merge sort]({{baseurl}}/images/Merge-sort-example-300px.gif)

---
layout: post
title:  "Algorithm Note 02: Merge Sort"
date: 2016-08-16
categories: Algorithm
tags:  Algorithm
---

* content
{:toc}

TODO: 

- [ ] Add descriptions of merge sort algorithm
- [ ] Add C++ implementation


## Merge Sort

![Illustration of merge sort]({{baseurl}}/images/Merge-sort-example-300px.gif)

```cpp
// merge two sorted array
void mergearray(int a[], int n, int b[], int m, int c[])
{
    int i = 0;
    int j = 0;
    int k = 0;

    while (i < n && j < m)
    {
        if (a[i] < b[j])
            c[k++] = a[i++];
        else
        	c[k++] = b[j++];
    }
    while (i < n)
    	c[k++] = a[i++];
    while (j < m)
    	c[k++] = b[j++];
}
```

The space complexity is O(N), and the time complexity is also O(N).
Add cpp of merge algorithm
Add cpp of merge algorithm

Signed-off-by: Wensheng Chen <cb91dd1f8c491c93147d8d4a4d596b48ad428818@ovt.com>
