VOOZH about

URL: https://www.geeksforgeeks.org/dsa/in-place-merge-sort-set-2/

⇱ In-Place Merge Sort | Set 2 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

In-Place Merge Sort | Set 2

Last Updated : 23 Jul, 2025

Given an arrayA[] of size N, the task is to sort the array in increasing order using In-Place Merge Sort.

Examples:

Input: A = {5, 6, 3, 2, 1, 6, 7}
Output: {1, 2, 3, 5, 6, 6, 7}

Input: A = {2, 3, 4, 1}
Output: {1, 2, 3, 4}

Approach: The idea is to use the inplace_merge() function to merge the sorted arrays in O(1) space. Follow the steps below to solve the problem:

Below is the implementation of the above approach:


Output
1 2 3 5 6 6 7

Time Complexity: O(N * log(N))
Auxiliary Space: O(1)

Alternate Approaches: Refer to the previous article for other approaches to solve this problem.


Comment