Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:13:52+00:00 2026-06-12T20:13:52+00:00

Possible Duplicate: Why Merge Operation in Merge Sort is O(n)? why each iteration takes

  • 0

Possible Duplicate:
Why Merge Operation in Merge Sort is O(n)?

why each iteration takes exactly O(n) regarding to the merge sort
could some one explain it for me in detail?
and why the C_merge(n)= O(n)? does it mean the time of merge two sorted array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:13:53+00:00Added an answer on June 12, 2026 at 8:13 pm

    The idea is we have two sorted array, and not two array with one of them having it’s smallest element larger than that the other’s highest. What I meant to say is, it’s not [1, 3, 9, 12] and [13, 17, 19]. But it’s more like [3, 12, 13, 17] and [1, 9, 19].

    You see, in later case you can’t append them. So, how do you combine? You follow the following algorithm:

    1. Lets say first has m elements, and the second has n. You make an auxiliary array of size m+n. This will store the final combined and sorted array.
    2. Assign two cursors — i and j, pointing to the heads of the arrays.
    3. Compare the elements at i and j; choose the smaller one. Copy the value auxiliary array, and move the cursor at smaller cursor ahead.
    4. Repeat #3, till one of the arrays exhausts; and then copy the rest of the elements from unexhausted array to the auxiliary array.

    So, in our case, you compare (3, [1]); ([3], 9); (12, [9]); ([12], 19); ([13], 19); ([17], 19); (--, [19]) . You see? How may comparisons? (m+n). Assuming each operation O(1). The merge process for an array of length (m+n) is O(m+n).

    In best case, you will have sorted array as input. In such as, both the subarrays to be merged will just require joining. But we will apply the generic algorithm mentioned above. In that case, you will have to compare and copy min(m,n) elements; and then copy max(m,n) elements to the auxiliary array. In any case, you are going to have total (m+n) operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I merge a specific commit from one branch into another
Possible Duplicate: MySQL: FULL OUTER JOIN - How do I merge one column? Real
Possible Duplicate: How to sort in-place using the merge sort algorithm? Usually we take
Possible Duplicate: merge two files by key if exists in the first file /
Possible Duplicate: Merge Two Video files in iPhone Application I have download 40mb video
Possible Duplicate: What is the best method to merge two PHP objects? I have
Possible Duplicate: How do I sort a multidimensional array in php i need to
Possible Duplicate: Combine Multiple child rows into one row MYSQL I have following table,
Possible Duplicate: How can I merge 3 images into 1 image via PHP? How
Possible Duplicate: Merge two lists in python? How can I prepend list elements into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.