• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
August 13, 2024 |94.5K Views

Merge Two Sorted Arrays

  Share   Like
Description
Discussion

Create an array arr3[] of size n1 + n2.
Copy all n1 elements of arr1[] to arr3[]
Traverse arr2[] and one by one insert elements (like insertion sort) of arr3[] to arr1[]. This step take O(n1 * n2) time.
We have discussed implementation of above method in Merge two sorted arrays with O(1) extra space
Method 2 (O(n1 + n2) Time and O(n1 + n2) Extra Space) 
The idea is to use Merge function of Merge sort.

 

Merge Two Sorted Arrays : https://www.geeksforgeeks.org/merge-two-sorted-arrays/