Algorithm 插入排序节拍合并排序n<=8logn,n的值

Algorithm 插入排序节拍合并排序n<=8logn,n的值,algorithm,sorting,logarithm,Algorithm,Sorting,Logarithm,我数学不好 n我们必须找出,n、8n^2和64nlogn的哪个值具有相同的值。所以 8n^2 = 64nlogn => n = 8logn => n = log (n^8) => 2^n = n^8 现在,借助for循环,我们可以从n=2迭代到2^n=n^8的数字 // language cpp #include <iostream> #include <math.h> using namespace std; int main() { d

我数学不好


n我们必须找出,
n
8n^2
64nlogn
的哪个值具有相同的值。所以

8n^2 = 64nlogn
=> n = 8logn
=> n = log (n^8)
=> 2^n = n^8
现在,借助for循环,我们可以从
n=2
迭代到
2^n=n^8
的数字

// language cpp
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    double n = 2;

    while(pow(2, n) < pow(n, 8)){
        cout << "n = " << n << endl;
        cout << "2^n = " << (long long) pow(2,n) << endl;
        cout << "n^8 = " << (long long) pow(n,8) << endl;
        cout << endl;
        n++;
    }

    cout << "n = " << n << endl;
    cout << "2^n = " << (long long) pow(2,n) << endl;
    cout << "n^8 = " << (long long) pow(n,8) << endl;

    return 0;
}
//语言cpp
#包括
#包括
使用名称空间std;
int main()
{
双n=2;
while(pow(2,n)无法计算
n
8n^2
64nlogn
的哪个值具有相同的值:

8n2 < 64nlogn
8n.n < 8n.8.logn
n < 8.logn
n/8 < logn
算法分析以2为基础,
a=2
。 要在Python中解决此问题,请执行以下操作:

n = 2
while 2 ** (n / 8.0) < n:
   n +=1
print("Maximum value of n for which insertion sort beats merge sort is", n - 1)
n=2
而2**(n/8.0)
有关此测验和其他测验的帮助参考:


  • 我投票结束这个问题,因为它是关于数学的,不是关于编程的。你能解释最后两行=>n=log(n^8)吗=>2^n=n^8,这是怎么做到的?最后两行遵循对数的基本规则。请阅读汗学院的基本对数概念教程。在代码中,我从2开始,因为对于值
    n=1
    2^n>n^8
    ,但这不是我们要找的。所以我从2开始。
    2^n/8 < n
    
    n = 2
    while 2 ** (n / 8.0) < n:
       n +=1
    print("Maximum value of n for which insertion sort beats merge sort is", n - 1)