{"id":171,"date":"2021-11-21T12:54:06","date_gmt":"2021-11-21T12:54:06","guid":{"rendered":"http:\/\/47.103.123.166\/?p=171"},"modified":"2021-11-21T12:54:06","modified_gmt":"2021-11-21T12:54:06","slug":"%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e5%ad%a6%e4%b9%a01-%e5%87%86%e5%a4%87%e6%97%b6%e9%97%b4%e5%a4%8d%e6%9d%82%e5%ba%a6","status":"publish","type":"post","link":"http:\/\/47.103.123.166\/?p=171","title":{"rendered":"\u6570\u636e\u7ed3\u6784\u5b66\u4e601\u2014\u2014\u51c6\u5907&#038;\u65f6\u95f4\u590d\u6742\u5ea6"},"content":{"rendered":"<p>&emsp;&emsp;\u6570\u636e\u7ed3\u6784 + \u7b97\u6cd5 = \u7a0b\u5e8f<\/p>\n<h1>\u51c6\u5907<\/h1>\n<h2>1.1 \u6570\u636e\u7ed3\u6784\u7684\u6982\u5ff5<\/h2>\n<p><img src=\"http:\/\/47.103.123.166\/wp-content\/uploads\/2021\/11\/post-171-619a416e6d938.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>1.2 \u7b97\u6cd5\u5206\u6790<\/h2>\n<p>1\u3001\u7b97\u6cd5\u5206\u6790\u5305\u62ec\u5bf9\u7b97\u6cd5\u7684<strong>\u65f6\u95f4<\/strong>\u548c<strong>\u7a7a\u95f4<\/strong>\u5206\u6790\uff0c\u4e00\u822c\u66f4\u6ce8\u91cd\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u5206\u6790\u3002<\/p>\n<p>2\u3001\u7b97\u6cd5\u5206\u6790\u5305\u62ec\u5bf9\u7b97\u6cd5\u7684<strong>\u4e8b\u524d<\/strong>\u548c<strong>\u4e8b\u540e<\/strong>\u5206\u6790\uff0c\u53d7\u8f6f\u786c\u4ef6\u73af\u5883\u548c\u673a\u5668\u4ee3\u7801\u7b49\u7684\u5f71\u54cd\uff0c\u901a\u8fc7\u8bbe\u8ba1\u7b97\u6cd5\u6765\u8ba1\u7b97\u7684\u51c6\u786e\u65f6\u95f4\u4e00\u822c\u4e0d\u591f\u5ba2\u89c2\uff0c\u56e0\u800c\u901a\u8fc7\u4e8b\u524d<strong>\u4f30\u8ba1<\/strong>\u7684\u65b9\u5f0f\u5f97\u51fa\u65f6\u7a7a\u590d\u6742\u5ea6\u3002<\/p>\n<h3>1.2.1 \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u6982\u5ff5<\/h3>\n<p>1\u3001\u65f6\u95f4\u590d\u6742\u5ea6<br \/>\n&emsp;&emsp;\u91c7\u7528\u4e8b\u524d\u4f30\u8ba1\uff0c<strong>\u7528\u57fa\u672c\u8bed\u53e5\u6267\u884c\u6b21\u6570\u7684\u89c4\u6a21\u6765\u8868\u793a\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4<\/strong>\uff0c\u4ee5 <em>T(n)<\/em> \u8868\u793a\uff0c\u540c\u65f6\uff0c\u66f4\u5173\u6ce8\u968f\u7740\u95ee\u9898\u89c4\u6a21 <em>n<\/em> \u7684\u589e\u957f\uff0c\u7b97\u6cd5\u6d88\u8017\u65f6\u95f4\u7684<strong>\u589e\u957f\u8d8b\u52bf<\/strong>\uff0c\u56e0\u800c\u4e00\u822c\u4f7f\u7528<strong>\u6e10\u8fdb\u65f6\u95f4\u590d\u6742\u5ea6<\/strong>\uff0c\u91c7\u7528<strong>\u5927 <em>O<\/em> \u8868\u793a\u6cd5<\/strong>\u3002<\/p>\n<p>2\u3001\u5927<em>O<\/em>\u8868\u793a\u6cd5<br \/>\n&emsp;&emsp;\u8bbe\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u4e3aT(n) \uff0c\u82e5\u5b58\u5728\u4e24\u4e2a\u6b63\u7684\u5e38\u6570c\u548cn0\uff0c\u5bf9\u4e8e\u4efb\u610f\u7684n\u2265n0\uff0c\u90fd\u6709T(n) \u2264 c\u00d7f(n)\uff0c\u5219\u79f0T(n) = O(f(n))\uff0c\u4e5f\u79f0\u4e3a\u51fd\u6570T(n) \u4ee5 f(n)\u4e3a\u4e0a\u754c\u3002<br \/>\n&emsp;&emsp;\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b9e\u9645\u8fd0\u884c\u65f6\u95f4\u4e0d\u8d85\u8fc7 f(n) \u7684c\u500d\uff0c\u4f7f\u7528f(n)\u8fd1\u4f3c\uff0c\u80fd\u591f\u53cd\u6620\u53d8\u5316\u8d8b\u52bf\u3002<\/p>\n<p>3\u3001\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u8ba1\u7b97<br \/>\n&emsp;&emsp;\u9996\u5148\uff0c\u8ba1\u7b97\u57fa\u672c\u8bed\u53e5\u7684\u6267\u884c\u6b21\u6570\uff0c\u5982\u4e0b\uff0cT(n) = 2n+2\u3002<\/p>\n<pre><code class=\"language-cpp\">int sum = 0;            \/\/  1\nfor(int i=0;i&lt;n;i++)    \/\/  1 + n\n    sun+=i;             \/\/  n<\/code><\/pre>\n<p>&emsp;&emsp;\u7136\u540e\uff0c \u5ffd\u7565\u5e38\u91cf\u3001\u4f4e\u6b21\u5e42\u548c\u6700\u9ad8\u6b21\u5e42\u7684\u7cfb\u6570\uff0c\u5f97\u5230f(n) = n\uff0c\u4f7f\u7528\u5927<em>O<\/em>\u8868\u793a\u6cd5\uff0c\u5219T(n) = O(n)\u3002<\/p>\n<p>4\u3001\u5e38\u89c1\u65f6\u95f4\u590d\u6742\u5ea6<br \/>\n&emsp;&emsp;\u5e38\u89c1\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u6bd4\u8f83\u5982\u4e0b\uff0c<em>O<\/em>(1)\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0e\u89c4\u6a21\u65e0\u5173\uff0c\u8017\u65f6\u6700\u77ed\uff0c2\u7684\u6307\u6570\u5e42\u4ee5\u53ca\u8017\u65f6\u66f4\u957f\u7684\u7b97\u6cd5\u4e00\u822c\u4e0d\u91c7\u7528\u3002<br \/>\n<img src=\"http:\/\/47.103.123.166\/wp-content\/uploads\/2021\/11\/post-171-619a416ea61bf.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><br \/>\n&emsp;&emsp;\u5e38\u89c1\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u4e3e\u4f8b\u5982\u4e0b\uff0c<\/p>\n<pre><code class=\"language-cpp\">\/\/O(1)\uff1a\u4ee5\u4e0b\u8bed\u53e5\u4e0e\u89c4\u6a21n\u65e0\u5173\uff0c\u6267\u884c\u65f6\u95f4\u662f\u4e00\u4e2a\u5e38\u6570\uff0c\u56e0\u800c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a1\n    int i=1;\n    i+=1;\n    int j=1;\n    j+=i;\n\/\/O(log(n))\n    for(int i=1;i&lt;n;i*=2)\n        sum+=i;\n\/\/O(n)\n    for(int i=1;i&lt;n;i++)\n        sum+=i;\n\/\/O(nlog(n))\n    for\uff08int i=1;i&lt;=n;i++\uff09\n        for(int j=1;j&lt;=n;j*=2)\n            sum=sum+i+j;    \n\/\/O(n2)\n    for(int i=1;i&lt;n;i++)\n        for(int j=1;j&lt;n;j++)\n            sum=sum+i+j;    \n\/\/O(n3)\n    for(int i=1;i&lt;n;i++)\n        for(int j=1;j&lt;n;j++)\n            for(int k=1;k&lt;n;k++)\n                sum=sum+i+j+k;<\/code><\/pre>\n<h3>1.2.2 \u5b9e\u6218\u7ec3\u4e60\uff08\u4e0d\u65ad\u8865\u5145&#8230;\uff09<\/h3>\n<p>&emsp;&emsp;\u9012\u5f52\u8ba1\u7b97x\u7684n\u6b21\u65b9\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(log(n))\uff1a<\/p>\n<pre><code class=\"language-cpp\">int func(int x,int n)\n{\n    if(n==0)\n        return 1;\n\n    int t = func(x,n\/2)\n    if(n%2==1)\n        return t*t*x;\n\n    return t*t;\n}<\/code><\/pre>\n<p>&emsp;&emsp;\u8c03\u548c\u7ea7\u6570\uff0c\u65f6\u95f4\u590d\u6742\u5ea6O(nlog(n))<\/p>\n<pre><code class=\"language-cpp\">for\uff08int i=1;i&lt;=n;i++\uff09\n    for(int j=1;j&lt;=n;j+=i)\n        sum=sum+i+j;            \/\/ n + n\/2 + n\/3 + ... + n\/n = n(1+ 1\/2 + 1\/3 + ... + 1\/n) = n(ln(n+1)+r)<\/code><\/pre>\n<h1>\u7cfb\u5217\u53c2\u8003<\/h1>\n<p>1)  <a href=\"https:\/\/blog.csdn.net\/kun1280437633\/article\/details\/80770296\">\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u8ba1\u7b97<\/a><br \/>\n2)  <a href=\"https:\/\/www.zhihu.com\/question\/63075755\">\u9012\u5f52\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1f<\/a><br \/>\n3) \u300a\u6570\u636e\u7ed3\u6784\uff08C++\uff09\u8fb9\u5b66\u8fb9\u505a\u300b\u4efb\u5e73\u7ea2\u7b49\u8457<br \/>\n4) \u300a\u5251\u6307offer\u300b\u4f55\u6d77\u6d9b\u8457<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&emsp;&emsp;\u6570\u636e\u7ed3\u6784 + \u7b97\u6cd5 = \u7a0b\u5e8f \u51c6\u5907 1.1 \u6570\u636e\u7ed3\u6784\u7684\u6982\u5ff5 1.2 \u7b97\u6cd5\u5206\u6790 1\u3001\u7b97\u6cd5\u5206\u6790\u5305\u62ec\u5bf9\u7b97\u6cd5\u7684\u65f6\u95f4\u548c\u7a7a\u95f4\u5206\u6790\uff0c\u4e00\u822c\u66f4\u6ce8\u91cd\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u5206\u6790\u3002 2\u3001\u7b97\u6cd5\u5206\u6790\u5305\u62ec\u5bf9\u7b97\u6cd5\u7684\u4e8b\u524d\u548c\u4e8b\u540e\u5206\u6790\uff0c\u53d7\u8f6f\u786c\u4ef6\u73af\u5883\u548c\u673a\u5668\u4ee3\u7801\u7b49\u7684\u5f71\u54cd\uff0c\u901a\u8fc7\u8bbe\u8ba1\u7b97\u6cd5\u6765\u8ba1\u7b97\u7684\u51c6\u786e\u65f6\u95f4\u4e00\u822c\u4e0d\u591f\u5ba2\u89c2\uff0c\u56e0\u800c\u901a\u8fc7\u4e8b\u524d\u4f30\u8ba1\u7684\u65b9\u5f0f\u5f97\u51fa\u65f6\u7a7a\u590d\u6742\u5ea6\u3002 1.2.1 \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u6982\u5ff5 1\u3001\u65f6\u95f4\u590d\u6742\u5ea6 &emsp;&emsp;\u91c7\u7528\u4e8b\u524d\u4f30\u8ba1\uff0c\u7528\u57fa\u672c\u8bed\u53e5\u6267\u884c\u6b21\u6570\u7684\u89c4\u6a21\u6765\u8868\u793a\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u4ee5 T(n) \u8868\u793a\uff0c\u540c\u65f6\uff0c\u66f4\u5173\u6ce8\u968f\u7740\u95ee\u9898\u89c4\u6a21 n \u7684\u589e\u957f\uff0c\u7b97\u6cd5\u6d88\u8017\u65f6\u95f4\u7684\u589e\u957f\u8d8b\u52bf\uff0c\u56e0\u800c\u4e00\u822c\u4f7f\u7528\u6e10\u8fdb\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u91c7\u7528\u5927 O \u8868\u793a\u6cd5\u3002 2\u3001\u5927O\u8868\u793a\u6cd5 &emsp;&emsp;\u8bbe\u7b97\u6cd5\u8fd0\u884c\u65f6\u95f4\u4e3aT(n) \uff0c\u82e5\u5b58\u5728\u4e24\u4e2a\u6b63\u7684\u5e38\u6570c\u548cn0\uff0c\u5bf9\u4e8e\u4efb\u610f\u7684n\u2265n0\uff0c\u90fd\u6709T(n) \u2264 c\u00d7f(n)\uff0c\u5219\u79f0T(n) = O(f(n))\uff0c\u4e5f\u79f0\u4e3a\u51fd\u6570T(n) \u4ee5 f(n)\u4e3a\u4e0a\u754c\u3002 &emsp;&emsp;\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b9e\u9645\u8fd0\u884c\u65f6\u95f4\u4e0d\u8d85\u8fc7 f(n) \u7684c\u500d\uff0c\u4f7f\u7528f(n)\u8fd1\u4f3c\uff0c\u80fd\u591f\u53cd\u6620\u53d8\u5316\u8d8b\u52bf\u3002 3\u3001\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u8ba1\u7b97 &emsp;&emsp;\u9996\u5148\uff0c\u8ba1\u7b97\u57fa\u672c\u8bed\u53e5\u7684\u6267\u884c\u6b21\u6570\uff0c\u5982\u4e0b\uff0cT(n) = 2n+2\u3002 int sum = 0; \/\/ 1 for(int i=0;i&lt;n;i++) \/\/ 1 + n sun+=i; \/\/ n &emsp;&emsp;\u7136\u540e\uff0c \u5ffd\u7565\u5e38\u91cf\u3001\u4f4e\u6b21\u5e42\u548c\u6700\u9ad8\u6b21\u5e42\u7684\u7cfb\u6570\uff0c\u5f97\u5230f(n) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/posts\/171"}],"collection":[{"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/47.103.123.166\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":1,"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":172,"href":"http:\/\/47.103.123.166\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions\/172"}],"wp:attachment":[{"href":"http:\/\/47.103.123.166\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/47.103.123.166\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/47.103.123.166\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}