What is the average time complexity of in place merge sort when we use the following function for merging?

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

What is the average time complexity of in place merge sort when we use the following function for merging?

Post by answerhappygod »

Take Data Structure II Mock Tests - Chapterwise!Start the Test Now: Chapter 1,
2,
3,
4,
5,
6,
7,
8,
9,
10
advertisement


var adpushup = window.adpushup || {};
adpushup.que = adpushup.que || [];
adpushup.que.push(function () {
if (adpushup.config.platform === "MOBILE") {
adpushup.triggerAd("fdd9bf87-4faf-4493-82b4-e5538b31931a");
} else if ((window.outerWidth <= 768) || (window.outerWidth == 0)) {
adpushup.triggerAd("fdd9bf87-4faf-4493-82b4-e5538b31931a");
}
});
void in_place_merge(int arr[], int l, int middle, int r)
{
int start2 = middle + 1;
if (arr[middle] <= arr[start2])
{
return;
}
while (l <= middle && start2 <= r)
{
if (arr[l] <= arr[start2])
{
l++;
}
else
{
int val = arr[start2];
int index = start2;
while (index != l)
{
arr[index] = arr[index - 1];
index--;
}
arr[l] = val;
l++;
middle++;
start2++;
}
}
}
a) O(n log n)
b) O(n2)
c) O(n2 log n)
d) O(n log n2)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This topic has 1 reply

You must be a registered member and logged in to view the replies in this topic.


Register Login
 
Post Reply