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 1016077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:29:46+00:00 2026-05-16T10:29:46+00:00

I started reading ‘Introduction to Algorithms’ today, but I’ve gotten a bit confused over

  • 0

I started reading ‘Introduction to Algorithms’ today, but I’ve gotten a bit confused over one of the exercises.

Exercise 1.2.2 asks the reader

Suppose we are comparing implementations of Merge sort and Insertion Sort on the same
machine. For inputs of size n, insertion sort runs in 8n^2 steps,
while merge sort runs in 64n log n steps.

For which values of n does insertion sort beat merge sort?

I first tried opening up Wolfram Alpha and using it to draw graphs of the equations, but I couldn’t accurately compare the two graphs.

I then tried choosing a random value for n (200), working out the equations on paper, and then modifying the value of n based on my results.
But that took too long.

What is the correct way to solve this exercise?

  • 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-05-16T10:29:47+00:00Added an answer on May 16, 2026 at 10:29 am

    See here: 8n2 = 64n log2 n. Just put both things in a single equation.

    I.e., roughly n = 43 is the limit of insertion sort’s usefulness here.

    Usually you would solve this by solving above equation f(n) = g(n) by solving f(n) − g(n) = 0, however, the analytical result in this case isn’t pretty as you’re mixing a polynomial with a logarithm function. I’d just try out a few values and see where the result flips from positive to negative. Once you have one positive and one negative point you can use bisection to narrow it down.

    The brute-force way would be to simply try out all n up to a certain point. You already know that O(n2) algorithms aren’t suitable for large datasets, so the n has to be quite small. For my testing it looked like this:

    PS Home:\> function lb($n){[math]::Log($n)/[math]::Log(2)}  # binary logarithm
    PS Home:\> 1..80 | %{,($_,(8*$_*$_),(64*$_*(lb $_)))} | %{"{0}: delta={3}, I={1}, M={2}" -f $_[0],$_[1],$_[2],($_[2]-$_[1])}
    ...
    38: delta=1210,9597126948, I=11552, M=12762,9597126948
    39: delta=1024,36393828017, I=12168, M=13192,3639382802
    40: delta=824,135922911648, I=12800, M=13624,1359229116
    41: delta=610,216460117852, I=13448, M=14058,2164601179
    42: delta=382,549232429308, I=14112, M=14494,5492324293
    43: delta=141,080604940173, I=14792, M=14933,0806049402
    44: delta=−114,240561917371, I=15488, M=15373,7594380826
    45: delta=−383,463082570537, I=16200, M=15816,5369174295
    46: delta=−666,633601368154, I=16928, M=16261,3663986318
    47: delta=−963,796734153668, I=17672, M=16708,2032658463
    48: delta=−1274,99519778461, I=18432, M=17157,0048022154
    ...
    

    (Excuse the horrible code; this was just a very quick doodle.)

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

Sidebar

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.