对于大小为n的输入,其中n值的并插入排序击败归并排序?大小

2023-09-11 02:41:52 作者:绝情被狗咬

在这本书算法导论(科尔曼),运动1.2-2询问比较插入排序的实现和合并排序以下问题。对于大小为n的输入,插入排序运行在8N ^ 2步骤,同时合并排序运行在64N LG n步;对于其中n的值并插入排序击败归并排序?

In the book Introduction to Algorithms (Corman), exercise 1.2-2 asks a the following question about comparing implementations of insertion sort and merge sort. For inputs of size n, insertion sort runs in 8n^2 steps while merge sort runs in 64n lg n steps; for which values of n does insertion sort beat merge sort?

虽然我感兴趣的答案,我更感兴趣的是如何找到一步的答案的步骤(这样我就可以重复这一过程,以比较任意两个给定的算法,如果可能的话)。

Although I am interested in the answer, I am more interested in how to find the answer step by step (so that I can repeat the process to compare any two given algorithms if at all possible).

乍一看,这个问题似乎类似于像找到盈亏平衡点在企业微积分,我花了5年前的一类,但我不知道,所以任何帮助将是AP preciated 。

At first glance, this problem seems similar to something like finding the break even point in business-calculus, a class which I took more than 5 years ago, but I am not sure so any help would be appreciated.

感谢您

P / S。如果我的标签是不正确的,这个问题是不正确的分类,或者一些其他公约正在这里滥用,请限制严惩到最低限度,因为这是我第一次张贴问题。

P/S If my tags are incorrect, this question is incorrectly categorized, or some other convention is being abused here please limit the chastising to a minimum, as this is my first time posting a question.

推荐答案

既然你找到的时候插入排序次合并排​​序

Since you are to find when insertion sort beats merge sort

8n^2<=64nlogn
n^2<=8nlogn
n<=8logn

在解决正8logn = 0

n = 43.411

因此​​,对于 N'LT; = 43 插入排序的作品比归并排序好

So for n<=43 insertion sort works better than merge sort.