{"id":3845,"date":"2019-02-11T18:17:23","date_gmt":"2019-02-11T10:17:23","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3845"},"modified":"2019-06-17T18:57:54","modified_gmt":"2019-06-17T10:57:54","slug":"%e5%85%b3%e4%ba%8e%e5%b8%b8%e8%a7%81%e7%ae%97%e6%b3%95%e7%9a%84%e6%97%b6%e9%97%b4%e5%a4%8d%e6%9d%82%e5%ba%a6-%ce%9f1%ef%bc%9c%ce%9flog2n%ef%bc%9c%ce%9fn%ef%bc%9c%ce%9fnlog2n%ef%bc%9c%ce%9fn2","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3845","title":{"rendered":"\u5173\u4e8e\u5e38\u89c1\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6 \u039f(1)\uff1c\u039f(log2n)\uff1c\u039f(n)\uff1c\u039f(nlog2n)\uff1c\u039f(n2)\uff1c\u039f(n3)\uff1c\u2026\uff1c\u039f(2n)\uff1c\u039f(n!)"},"content":{"rendered":"<p>\u8bf4\u5b9e\u8bdd\uff0c\u6211\u662f\u771f\u7684\u4e0d\u61c2\u7b97\u6cd5\u3002\u4f46\u662f\uff0c\u6211\u77e5\u9053\u4e00\u4e2a\u7b97\u6cd5\u7684\u597d\u574f\uff0c\u901a\u5e38\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u4e00\u4e2a\u8bc4\u4ef7\u7684\u6307\u6807\u4e4b\u4e00\u3002<\/p>\n<p>\u53c8\u5230\u4e86\u4e00\u5e74\u7684\u9762\u8bd5\u5b63\uff0c\u6709\u4e9b\u540c\u5b66\u5728\u7fa4\u91cc\u53cd\u9988\u7b97\u6cd5\u95ee\u9898\u3002\u5173\u4e8e\u8fd9\u7c7b\u95ee\u9898\uff0c\u6211\u5efa\u8bae\u5927\u5bb6\u591a\u53bb LeetCode \u5237\u9898\uff0c\u591a\u53bb\u770b\u770b\u7ec3\u4e60\u7ec3\u4e60\u3002\u56e0\u4e3a\u6211\u5bf9\u7b97\u6cd5\u95ee\u9898\u771f\u7684\u662f\u4e0d\u592a\u61c2\uff01\u6ca1\u6709\u4e13\u95e8\u7814\u7a76\u8fc7\uff01<\/p>\n<p>\u867d\u7136\u6211\u4e0d\u61c2\u7b97\u6cd5\uff0c\u4f46\u662f\u6211\u77e5\u9053\u5173\u4e8e\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u6bd4\u5982\uff1a\u039f(1)\u3001\u039f(log2n)\u3001\u039f(n)\u3001\u039f(nlog2n)\u3001\u039f(n2)\u3001\u039f(n3)\u2026\u039f(2n)\u3001\u039f(n!)\u7b49\u6240\u4ee3\u8868\u7684\u610f\u601d\uff01<\/p>\n<p>\u6211\u5728\u9762\u8bd5\u7684\u65f6\u5019\uff0c\u5c31\u53d1\u73b0\u6709\u4eba\u8fde O(1) \u4ee3\u8868\u4ec0\u4e48\u610f\u601d\u90fd\u641e\u4e0d\u6e05\u695a\uff01<\/p>\n<p>\u5173\u4e8e\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u6709\u4e00\u4e2a\u516c\u5f0f\uff1aT (n) = \u039f(f (n))\u3002\u600e\u4e48\u89e3\u91ca\u8fd9\u4e2a\u516c\u5f0f\u5462\uff1f\u7279\u522b\u9ebb\u70e6\uff0c\u6211\u76ee\u524d\u8fd8\u6ca1\u6709\u60f3\u5230\u6bd4\u8f83\u7b80\u5355\u7684\u4ecb\u7ecd\u65b9\u5f0f\u3002\u6240\u4ee5\uff0c\u6211\u5c31\u5148\u4e0d\u89e3\u91ca\u5b83\u4e86\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u6211\u4eec\u5c31\u5148\u6765\u770b\u770b O(1) \u662f\u4ec0\u4e48\u610f\u601d\uff1f<\/p>\n<h2>O(1)<\/h2>\n<p>O(1) \u4e5f\u5c31\u662f\u6700\u4f4e\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u4ee3\u8868\u7684\u662f\u4e00\u4e2a\u5e38\u91cf\u503c\u3002\u4e5f\u5c31\u662f\u8bf4\u8017\u65f6\uff0c\u8017\u7a7a\u95f4\u4e0e\u8f93\u5165\u6570\u636e\u7684\u5927\u5c0f\u65e0\u5173\u3002\u65e0\u8bba\u8f93\u5165\u6570\u636e\u589e\u5927\u591a\u5c11\u500d\uff0c\u8017\u65f6\u662f\u4e0d\u53d8\u7684\u3002<\/p>\n<p>\u76f8\u5173\u7b97\u6cd5\u4e3e\u4f8b\uff1a\u54c8\u5e0c\u7b97\u6cd5\uff08\u4e0d\u8003\u8651\u51b2\u7a81\u7684\u60c5\u51b5\uff09\uff0c\u65e0\u8bba\u5728\u6570\u636e\u91cf\u591a\u4e48\u5927\uff0c\u90fd\u662f O(1)\u3002<\/p>\n<h2>O(n)<\/h2>\n<p>O(n) \u7406\u89e3\u8d77\u6765\u4e5f\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u968f\u7740\u6570\u636e\u91cf\u7684\u589e\u5927\u51e0\u500d\uff0c\u8017\u65f6\u4e5f\u589e\u5927\u51e0\u500d\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u7b97\u6cd5\u4e3e\u4f8b\uff1a\u904d\u5386\u7b97\u6cd5\u3002<\/p>\n<h2>O(n^2)<\/h2>\n<p>\u5c31\u4ee3\u8868\u6570\u636e\u91cf\u589e\u5927 n \u500d\u65f6\uff0c\u8017\u65f6\u589e\u5927 n \u7684\u5e73\u65b9\u500d\uff0c\u8fd9\u662f\u6bd4\u7ebf\u6027\u66f4\u9ad8\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u6bd4\u5982\u5192\u6ce1\u6392\u5e8f\uff0c\u5c31\u662f\u5178\u578b\u7684 O(n^2) \u7684\u7b97\u6cd5\uff0c\u5bf9 n \u4e2a\u6570\u6392\u5e8f\uff0c\u9700\u8981\u626b\u63cf n \u00d7 n \u6b21\u3002<\/p>\n<p>O(n^2) \u4e5f\u6709\u4eba\u7528 O(n\u00b2) \u8868\u793a\u3002\u8fd9\u4e24\u4e2a\u8868\u793a\u662f\u4e00\u6837\u7684\u3002<\/p>\n<h2>O(logn)<\/h2>\n<p>\u5f53\u6570\u636e\u589e\u5927 n \u500d\u65f6\uff0c\u8017\u65f6\u589e\u5927 logn \u500d\uff08\u8fd9\u91cc\u7684 log \u662f\u4ee5 2 \u4e3a\u5e95\u7684\uff0c\u6bd4\u5982\uff0c\u5f53\u6570\u636e\u589e\u5927 256 \u500d\u65f6\uff0c\u8017\u65f6\u53ea\u589e\u5927 8 \u500d\uff0c\u662f\u6bd4\u7ebf\u6027\u8fd8\u8981\u4f4e\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff09\u3002\u4e8c\u5206\u67e5\u627e\u5c31\u662f O(logn)\u7684\u7b97\u6cd5\uff0c\u6bcf\u627e\u4e00\u6b21\u6392\u9664\u4e00\u534a\u7684\u53ef\u80fd\uff0c256 \u4e2a\u6570\u636e\u4e2d\u67e5\u627e\u53ea\u8981\u627e 8 \u6b21\u5c31\u53ef\u4ee5\u627e\u5230\u76ee\u6807\u3002<\/p>\n<h2>O(nlogn)<\/h2>\n<p>O(nlogn) \u5c31\u662f n \u4e58\u4ee5 logn\uff0c\u5f53\u6570\u636e\u589e\u5927 256 \u500d\u65f6\uff0c\u8017\u65f6\u589e\u5927 256*8=2048 \u500d\u3002\u8fd9\u4e2a\u590d\u6742\u5ea6\u9ad8\u4e8e\u7ebf\u6027\u4f4e\u4e8e\u5e73\u65b9\u3002\u5f52\u5e76\u6392\u5e8f\u5c31\u662f O(nlogn) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u6709\uff1a\u5e38\u6570\u9636 O(1)\uff0c\u5bf9\u6570\u9636 O(log2n)\uff0c\u7ebf\u6027\u9636 O(n)\uff0c\u7ebf\u6027\u5bf9\u6570\u9636 O(nlog2n)\uff0c\u5e73\u65b9\u9636 O(n2)\uff0c\u7acb\u65b9\u9636 O(n3)\uff0c&#8230;\uff0ck \u6b21\u65b9\u9636 O(nk)\uff0c\u6307\u6570\u9636 O(2n) \u7b49\u3002\u6211\u5c31\u4e0d\u4e00\u4e00\u5217\u4e3e\u8bf4\u660e\u4e86\u3002<\/p>\n<p><img decoding=\"async\" style=\"width: 576px;height: 257px\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g02mbt5ellj20g0075q3o.jpg\" alt=\"\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\"><\/p>\n<p>\u4ece\u4e0a\u56fe\u4e2d\u53ef\u89c1\uff0c\u6211\u4eec\u5e94\u8be5\u5c3d\u53ef\u80fd\u9009\u7528\u591a\u9879\u5f0f\u9636 O(nk) \u7684\u7b97\u6cd5\uff0c\u800c\u4e0d\u5e0c\u671b\u7528\u6307\u6570\u9636\u7684\u7b97\u6cd5\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u7531\u5c0f\u5230\u5927\u4f9d\u6b21\u4e3a\uff1a\u039f(1)\uff1c\u039f(log2n)\uff1c\u039f(n)\uff1c\u039f(nlog2n)\uff1c\u039f(n2)\uff1c\u039f(n3)\uff1c\u2026\uff1c\u039f(2n)\uff1c\u039f(n!)\u3002<\/p>\n<p><img decoding=\"async\" style=\"width: 441px;height: 372px\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g02mexzc0lj20c90ac75y.jpg\" alt=\"\u5e38\u89c1\u7684\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u4e3e\u4f8b\"><\/p>\n<p>\u4e0a\u56fe\u662f\u5e38\u89c1\u7684\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u4e3e\u4f8b\u3002<\/p>\n<p>\u5176\u5b9e\u6211\u4e0d\u641e\u7b97\u6cd5\uff0c\u8bb0\u4f4f\u4e0a\u9762\u5e38\u7528\u7684\u51e0\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u80fd\u89e3\u91ca\u5b83\u4eec\u7684\u610f\u601d\u5c31\u884c\u4e86\u3002\u60f3\u8f93\u5165\u5b66\u4e60\u7b97\u6cd5\u7684\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u91cc\u56de\u590d\u201c\u7b97\u6cd5\u201d\u5173\u952e\u5b57\uff0c\u83b7\u5f97\u4e00\u5957\u514d\u8d39\u7684\u89c6\u9891\u6559\u7a0b\uff01<\/p>\n<p>\u5176\u5b9e\u751f\u6d3b\u5f88\u7f8e\u597d\uff0c\u60f3\u7684\u592a\u591a\u4e5f\u4e0d\u884c\u3002\u6240\u4ee5\uff0c\u4e0d\u4f1a\uff0c\u6709\u5dee\u8ddd\u5f88\u6b63\u5e38\u3002\u5173\u952e\u662f\u4f60\u8981\u6b63\u89c6\u4f60\u548c\u522b\u4eba\u7684\u5dee\u8ddd\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3845\">\u5173\u4e8e\u5e38\u89c1\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6 \u039f(1)\uff1c\u039f(log2n)\uff1c\u039f(n)\uff1c\u039f(nlog2n)\uff1c\u039f(n2)\uff1c\u039f(n3)\uff1c\u2026\uff1c\u039f(2n)\uff1c\u039f(n!)<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u8bf4\u5b9e\u8bdd\uff0c\u6211\u662f\u771f\u7684\u4e0d\u61c2\u7b97\u6cd5\u3002\u4f46\u662f\uff0c\u6211\u77e5\u9053\u4e00\u4e2a\u7b97\u6cd5\u7684\u597d\u574f\uff0c\u901a\u5e38\u65f6\u95f4\u590d\u6742\u5ea6\u662f\u4e00\u4e2a\u8bc4\u4ef7\u7684\u6307\u6807\u4e4b\u4e00\u3002 \u53c8\u5230\u4e86\u4e00\u5e74\u7684\u9762\u8bd5\u5b63 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[871,1610,685,872,172],"class_list":["post-3845","post","type-post","status-publish","format-standard","hentry","category-yyzt","tag-idea","tag-rete","tag-685","tag-872","tag-172"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3845"}],"version-history":[{"count":2,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3845\/revisions"}],"predecessor-version":[{"id":4347,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3845\/revisions\/4347"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}