Learn basic concept of c , c++ and python programming in regularcodes.com

# Merge two sorted array

Write efficient program to merge two sorted array.

**Example**

Consider following test cases of More two sorted array.

1) Given two array are sorted form. In this two array size are equals or there are possible to size are not equal. Example

2) Duplicate array elements are possible in Given array. (merge two sorted arrays with duplicates elements)

**Example**

**Here given all possible solutions**

1) merge two sorted arrays using a temporary array.

2) merge two sorted arrays without using third array.

3) merge two sorted arrays using a dynamic array.

**
1) merge two sorted arrays using a temporary array**

Suppose array contain following elements. Befor Merge.

After Merge

Program for merge two sorted arrays using third array. time complexity O(n).

**Output**

2) merge two sorted arrays without using a temporary array.

Program for merge two sorted arrays with o(1) extra space. Time complexity O(n*m).(m,n size of array).

**Output**

3) merge two sorted arrays using a dynamic array.

Array elements.

View process

**Output**

Submit your solution in comment section.

View comments and participate Discussion