{"id":199465,"date":"2024-05-10T01:04:39","date_gmt":"2024-05-09T17:04:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/199465.html"},"modified":"2024-05-10T01:04:45","modified_gmt":"2024-05-09T17:04:45","slug":"%e4%bb%80%e4%b9%88%e5%8f%ab%e7%ae%97%e6%b3%95%e5%a4%8d%e6%9d%82%e5%ba%a6%e7%9a%84%e6%b8%90%e8%bf%9b%e6%80%a7%e6%80%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/199465.html","title":{"rendered":"\u4ec0\u4e48\u53eb\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24140746\/a0a2a32a-f5f3-4838-9bf2-1052812056c4.webp\" alt=\"\u4ec0\u4e48\u53eb\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001\" \/><\/p>\n<p><p>\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001\u662f\u6307\u5f53\u8f93\u5165\u89c4\u6a21\u65e0\u9650\u589e\u957f\u65f6\uff0c\u7528\u4ee5\u8868\u5f81\u7b97\u6cd5\u590d\u6742\u5ea6\u589e\u957f\u8d8b\u52bf\u7684\u4e00\u7ec4\u6570\u5b66\u6982\u5ff5\u548c\u7b26\u53f7\u3002<strong>\u5b83\u5305\u62ec\uff1a\u6700\u574f\u60c5\u51b5\u590d\u6742\u5ea6\u3001\u5e73\u5747\u60c5\u51b5\u590d\u6742\u5ea6\u3001\u6700\u597d\u60c5\u51b5\u590d\u6742\u5ea6\u3001\u5927O\u8bb0\u6cd5\u3001\u5927\u03a9\u8bb0\u6cd5\u3001\u5927\u0398\u8bb0\u6cd5<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u5927O\u8bb0\u6cd5<\/strong> \u662f\u6700\u5e38\u7528\u7684\u6e10\u8fdb\u6027\u6001\u8868\u793a\u65b9\u5f0f\uff0c\u5b83\u63cf\u8ff0\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u4e0a\u9650\uff0c\u4f53\u73b0\u4e86\u7b97\u6cd5\u5728\u6700\u574f\u60c5\u51b5\u4e0b\u7684\u65f6\u95f4\u6216\u7a7a\u95f4\u590d\u6742\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u5927O\u8bb0\u6cd5\uff0c\u901a\u8fc7\u7701\u7565\u5e38\u6570\u548c\u4f4e\u9636\u9879\uff0c\u7a81\u51fa\u663e\u793a\u6700\u5360\u7edf\u6cbb\u5730\u4f4d\u7684\u6210\u5206\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u7b97\u5f0f <code>O(n^2)<\/code> \u8868\u793a\u7b97\u6cd5\u7684\u65f6\u95f4\u6216\u7a7a\u95f4\u590d\u6742\u5ea6\u4e0e\u8f93\u5165\u6570\u636e\u7684\u5e73\u65b9\u6210\u6bd4\u4f8b\u589e\u957f\u3002\u8fd9\u4e2a\u6982\u5ff5\u6709\u52a9\u4e8e\u6211\u4eec\u4f30\u8ba1\u7b97\u6cd5\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\u7684\u8868\u73b0\uff0c\u5e76\u76f8\u4e92\u6bd4\u8f83\u4e0d\u540c\u7b97\u6cd5\u7684\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6<\/h3>\n<\/p>\n<p><p>\u5728\u8fdb\u4e00\u6b65\u8bb2\u89e3\u6e10\u8fdb\u6027\u6001\u4e4b\u524d\uff0c\u4e86\u89e3\u4e24\u4e2a\u57fa\u672c\u6982\u5ff5\u662f\u5f88\u91cd\u8981\u7684\uff1a\u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u3002<\/p>\n<\/p>\n<p><p><strong>\u65f6\u95f4\u590d\u6742\u5ea6<\/strong> \u8868\u793a\u7b97\u6cd5\u6267\u884c\u65f6\u95f4\u4e0e\u8f93\u5165\u6570\u636e\u91cf\u7684\u5173\u7cfb\u3002\u5b83\u5e2e\u52a9\u6211\u4eec\u8bc4\u4f30\u5728\u6700\u574f\u60c5\u51b5\u4e0b\u7b97\u6cd5\u6267\u884c\u6240\u9700\u7684\u65f6\u95f4\u91cf\u3002\u800c<strong>\u7a7a\u95f4\u590d\u6742\u5ea6<\/strong> \u63cf\u8ff0\u7684\u662f\u7b97\u6cd5\u6267\u884c\u8fc7\u7a0b\u4e2d\u6d88\u8017\u7684\u5b58\u50a8\u8d44\u6e90\u91cf\u4e0e\u8f93\u5165\u6570\u636e\u91cf\u7684\u5173\u7cfb\uff0c\u53cd\u6620\u7b97\u6cd5\u8fd0\u884c\u6240\u5360\u7528\u7684\u4e34\u65f6\u5b58\u50a8\u7a7a\u95f4\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u6700\u574f\u3001\u5e73\u5747\u548c\u6700\u597d\u60c5\u51b5\u590d\u6742\u5ea6<\/h3>\n<\/p>\n<p><p>\u638c\u63e1\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u4e09\u79cd\u60c5\u51b5<strong>\u5bf9\u4e8e\u5168\u9762\u7406\u89e3\u7b97\u6cd5\u6027\u80fd\u81f3\u5173\u91cd\u8981<\/strong>\u3002<\/p>\n<\/p>\n<p><p><strong>\u6700\u574f\u60c5\u51b5\u590d\u6742\u5ea6<\/strong> \u8003\u8651\u4e86\u7b97\u6cd5\u8fd0\u884c\u65f6\u6240\u6709\u53ef\u80fd\u60c5\u51b5\u4e2d\u6700\u8017\u65f6\u7684\u4e00\u79cd\u3002\u5b83\u4fdd\u8bc1\u7b97\u6cd5\u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\u7684\u6027\u80fd\u90fd\u4e0d\u4f1a\u4f4e\u4e8e\u6b64\u6807\u51c6\u3002<strong>\u5e73\u5747\u60c5\u51b5\u590d\u6742\u5ea6<\/strong> \u5047\u8bbe\u6240\u6709\u8f93\u5165\u6570\u636e\u7684\u53ef\u80fd\u6027\u5747\u7b49\uff0c\u8868\u793a\u7b97\u6cd5\u9884\u671f\u7684\u6027\u80fd\u3002\u5e73\u5747\u60c5\u51b5\u590d\u6742\u5ea6\u6d4b\u91cf\u4e5f\u79f0\u4f5c\u671f\u671b\u8fd0\u884c\u65f6\u95f4\u3002<strong>\u6700\u597d\u60c5\u51b5\u590d\u6742\u5ea6<\/strong> \u63cf\u8ff0\u4e86\u5728\u6700\u7406\u60f3\u7684\u60c5\u51b5\u4e0b\uff0c\u7b97\u6cd5\u7684\u8fd0\u884c\u901f\u5ea6\u6216\u5360\u7528\u7684\u7a7a\u95f4\u6570\u91cf\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5927O\u8bb0\u6cd5<\/h3>\n<\/p>\n<p><p><strong>\u5927O\u8bb0\u6cd5<\/strong> \u662f\u6e10\u8fdb\u590d\u6742\u5ea6\u5206\u6790\u4e2d\u6700\u4e3a\u5e38\u89c1\u7684\u8868\u8ff0\u65b9\u5f0f\u3002\u5b83\u7528\u4e8e\u8868\u8fbe\u7b97\u6cd5\u65f6\u95f4\u6216\u7a7a\u95f4\u590d\u6742\u5ea6\u7684\u4e0a\u9650\uff0c\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\u6700\u7cdf\u7cd5\u60c5\u51b5\u4e0b\u7b97\u6cd5\u53ef\u80fd\u7684\u589e\u957f\u7387\u3002\u5927O\u8bb0\u6cd5\u5ffd\u7565\u4e86\u5e38\u6570\u56e0\u5b50\u548c\u4f4e\u6b21\u9879\uff0c\u53ea\u5173\u6ce8\u8f93\u5165\u89c4\u6a21\u6700\u9ad8\u6b21\u9879\u5bf9\u590d\u6742\u5ea6\u7684\u5f71\u54cd\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u82e5\u4e00\u4e2a\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a <code>O(n^2)<\/code>\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u9884\u8ba1\u5176\u8fd0\u884c\u65f6\u95f4\u5c06\u968f\u7740\u8f93\u5165\u89c4\u6a21\u7684\u589e\u957f\u800c\u6309\u5e73\u65b9\u7ea7\u589e\u957f\u3002\u540c\u7406\uff0c\u82e5\u4e00\u4e2a\u7b97\u6cd5\u5177\u6709\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6 <code>O(n)<\/code>\uff0c\u90a3\u4e48\u5b83\u7684\u8fd0\u884c\u65f6\u95f4\u5c06\u968f\u8f93\u5165\u89c4\u6a21\u7684\u589e\u52a0\u800c\u7ebf\u6027\u589e\u957f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5927\u03a9\u8bb0\u6cd5\u548c\u5927\u0398\u8bb0\u6cd5<\/h3>\n<\/p>\n<p><p><strong>\u5927\u03a9\u8bb0\u6cd5\uff08Omega notation\uff09<\/strong> \u4e0e\u5927O\u8bb0\u6cd5\u76f8\u5bf9\uff0c\u7528\u6765\u8868\u793a\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u4e0b\u9650\u3002\u5b83\u53cd\u6620\u4e86\u7b97\u6cd5\u5728\u6700\u597d\u60c5\u51b5\u4e0b\u7684\u6027\u80fd\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u4e00\u4e2a\u7b97\u6cd5\u5982\u679c\u6709\u4e0b\u9650 <code>\u03a9(n)<\/code>\uff0c\u610f\u5473\u7740\u65e0\u8bba\u7b97\u6cd5\u6027\u80fd\u591a\u597d\uff0c\u5176\u8fd0\u884c\u65f6\u95f4\u4e0d\u4f1a\u4f4e\u4e8e\u8f93\u5165\u89c4\u6a21\u7684\u7ebf\u6027\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p><strong>\u5927\u0398\u8bb0\u6cd5\uff08Theta notation\uff09<\/strong> \u7cbe\u786e\u63cf\u8ff0\u4e86\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u786e\u5207\u589e\u957f\u8d8b\u52bf\uff0c\u5728\u6700\u597d\u548c\u6700\u574f\u60c5\u51b5\u590d\u6742\u5ea6\u76f8\u5f53\u65f6\u4f7f\u7528\u3002\u5982\u679c\u4e00\u4e2a\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a <code>\u0398(n log n)<\/code>\uff0c\u90a3\u4e48\u65e0\u8bba\u662f\u6700\u574f\u60c5\u51b5\u8fd8\u662f\u6700\u597d\u60c5\u51b5\uff0c\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u662f <code>n log n<\/code> \u7684\u786e\u5207\u8868\u793a\u3002<\/p>\n<\/p>\n<p><p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001\u7279\u6027\u5141\u8bb8\u6211\u4eec\u6839\u636e\u8f93\u5165\u89c4\u6a21\u7684\u589e\u957f\u53bb\u8bc4\u4f30\u3001\u6bd4\u8f83\u7b97\u6cd5\u7684\u6027\u80fd\uff0c\u5b83\u662f\u7406\u89e3\u548c\u5206\u6790\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>\u4ec0\u4e48\u662f\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001\uff1f<\/strong><br \/>\n\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001\u6307\u7684\u662f\u5728\u95ee\u9898\u89c4\u6a21\u65e0\u9650\u589e\u5927\u65f6\uff0c\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4\u6216\u7a7a\u95f4\u6d88\u8017\u7684\u589e\u957f\u8d8b\u52bf\u3002\u5b83\u53ef\u4ee5\u91cf\u5316\u7b97\u6cd5\u7684\u6548\u7387\u548c\u6027\u80fd\uff0c\u5e76\u4e14\u53ef\u4ee5\u7528\u6765\u6bd4\u8f83\u4e0d\u540c\u7b97\u6cd5\u4e4b\u95f4\u7684\u4f18\u52a3\u3002\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001\u5e38\u7528\u5927O\u8bb0\u6cd5\u6765\u8868\u793a\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u8981\u5206\u6790\u7b97\u6cd5\u7684\u6e10\u8fdb\u6027\u6001\uff1f<\/strong><br \/>\n\u5206\u6790\u7b97\u6cd5\u7684\u6e10\u8fdb\u6027\u6001\u80fd\u5e2e\u52a9\u6211\u4eec\u4f30\u8ba1\u7b97\u6cd5\u7684\u8fd0\u884c\u65f6\u95f4\u548c\u6d88\u8017\u7684\u7a7a\u95f4\uff0c\u4ee5\u9009\u62e9\u6700\u4f18\u7684\u7b97\u6cd5\u6765\u89e3\u51b3\u95ee\u9898\u3002\u901a\u8fc7\u4e86\u89e3\u7b97\u6cd5\u5728\u4e0d\u540c\u89c4\u6a21\u4e0b\u7684\u6027\u80fd\u8868\u73b0\uff0c\u6211\u4eec\u80fd\u591f\u4f18\u5316\u7b97\u6cd5\uff0c\u51cf\u5c11\u8d44\u6e90\u6d88\u8017\uff0c\u63d0\u9ad8\u8fd0\u884c\u6548\u7387\u3002<\/p>\n<p><strong>\u6709\u54ea\u4e9b\u5e38\u89c1\u7684\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001\uff1f<\/strong><br \/>\n\u5e38\u89c1\u7684\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001\u6709O(1)\u3001O(log n)\u3001O(n)\u3001O(n log n)\u3001O(n^2)\uff0c\u4ee5\u53caO(2^n)\u7b49\u3002\u5176\u4e2d\uff0cO(1)\u8868\u793a\u5e38\u6570\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u4e0d\u968f\u95ee\u9898\u89c4\u6a21\u53d8\u5316\uff1bO(log n)\u8868\u793a\u5bf9\u6570\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u968f\u95ee\u9898\u89c4\u6a21\u4ee5\u5bf9\u6570\u65b9\u5f0f\u589e\u957f\uff1bO(n)\u8868\u793a\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u968f\u95ee\u9898\u89c4\u6a21\u6210\u7b49\u6bd4\u4f8b\u589e\u957f\uff1bO(n^2)\u8868\u793a\u5e73\u65b9\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u968f\u95ee\u9898\u89c4\u6a21\u7684\u5e73\u65b9\u589e\u957f\uff1bO(n log n)\u8868\u793a\u7ebf\u6027\u5bf9\u6570\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u4ecb\u4e8e\u7ebf\u6027\u548c\u5e73\u65b9\u4e4b\u95f4\uff1b\u800cO(2^n)\u8868\u793a\u6307\u6570\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u968f\u95ee\u9898\u89c4\u6a21\u5448\u6307\u6570\u7ea7\u589e\u957f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7b97\u6cd5\u590d\u6742\u5ea6\u7684\u6e10\u8fdb\u6027\u6001\u662f\u6307\u5f53\u8f93\u5165\u89c4\u6a21\u65e0\u9650\u589e\u957f\u65f6\uff0c\u7528\u4ee5\u8868\u5f81\u7b97\u6cd5\u590d\u6742\u5ea6\u589e\u957f\u8d8b\u52bf\u7684\u4e00\u7ec4\u6570\u5b66\u6982\u5ff5\u548c\u7b26\u53f7\u3002\u5b83\u5305\u62ec\uff1a\u6700\u574f\u60c5\u51b5 [&hellip;]","protected":false},"author":3,"featured_media":199471,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/199465"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=199465"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/199465\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/199471"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=199465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=199465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=199465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}