{"id":15353,"date":"2024-11-17T20:35:29","date_gmt":"2024-11-17T12:35:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=15353"},"modified":"2024-11-17T20:35:29","modified_gmt":"2024-11-17T12:35:29","slug":"%e5%b8%b8%e8%a7%81%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%b8%8e%e7%ae%97%e6%b3%95%e6%95%b4%e7%90%86%e6%80%bb%e7%bb%93%ef%bc%88%e4%b8%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/15353\/","title":{"rendered":"\u5e38\u89c1\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6574\u7406\u603b\u7ed3\uff08\u4e0b\uff09"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u662f\u5e38\u89c1\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6574\u7406\u603b\u7ed3\u7684\u4e0b\u7bc7\uff0c\u4e0a\u4e00\u7bc7\u4e3b\u8981\u662f\u5bf9\u5e38\u89c1\u7684\u6570\u636e\u7ed3\u6784\u8fdb\u884c\u96c6\u4e2d\u603b\u7ed3\uff0c\u8fd9\u7bc7\u4e3b\u8981\u662f\u603b\u7ed3\u4e00\u4e9b\u5e38\u89c1\u7684\u7b97\u6cd5\u76f8\u5173\u5185\u5bb9\uff0c\u6587\u7ae0\u4e2d\u5982\u6709\u9519\u8bef\uff0c\u6b22\u8fce\u6307\u51fa\u3002<\/p>\n<pre>\u4e00\u3001\u6982\u8ff0\r\n\u4e8c\u3001\u67e5\u627e\u7b97\u6cd5\r\n\u4e09\u3001\u6392\u5e8f\u7b97\u6cd5\r\n\u56db\u3001\u5176\u5b83\u7b97\u6cd5\r\n\u4e94\u3001\u5e38\u89c1\u7b97\u6cd5\u9898\r\n\u516d\u3001\u603b\u7ed3<\/pre>\n<p>&nbsp;<\/p>\n<h1>\u4e00\u3001\u6982\u8ff0<\/h1>\n<p>\u4ee5\u524d\u770b\u5230\u8fd9\u6837\u4e00\u53e5\u8bdd\uff0c\u8bed\u8a00\u53ea\u662f\u5de5\u5177\uff0c\u7b97\u6cd5\u624d\u662f\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u7075\u9b42\u3002\u7684\u786e\uff0c\u7b97\u6cd5\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\u7684\u5730\u4f4d\u771f\u7684\u5f88\u91cd\u8981\uff0c\u5728\u5f88\u591a\u5927\u516c\u53f8\u7684\u7b14\u8bd5\u9762\u8bd5\u4e2d\uff0c\u7b97\u6cd5\u638c\u63e1\u7a0b\u5ea6\u7684\u8003\u5bdf\u90fd\u5360\u636e\u4e86\u5f88\u5927\u4e00\u90e8\u5206\u3002\u4e0d\u7ba1\u662f\u4e3a\u4e86\u9762\u8bd5\u8fd8\u662f\u81ea\u8eab\u7f16\u7a0b\u80fd\u529b\u7684\u63d0\u5347\uff0c\u82b1\u65f6\u95f4\u53bb\u7814\u7a76\u5e38\u89c1\u7684\u7b97\u6cd5\u8fd8\u662f\u5f88\u6709\u5fc5\u8981\u7684\u3002\u4e0b\u9762\u662f\u81ea\u5df1\u5bf9\u4e8e\u7b97\u6cd5\u8fd9\u90e8\u5206\u7684\u5b66\u4e60\u603b\u7ed3\u3002<\/p>\n<p><a href=\"http:\/\/fwq.ai\/wp-content\/uploads\/2018\/01\/2243690-cb7328c87985f4a2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15355\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-cb7328c87985f4a2.png\" width=\"600\" height=\"337\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-cb7328c87985f4a2.png 600w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-cb7328c87985f4a2-300x169.png 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-cb7328c87985f4a2-520x293.png 520w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" title=\"\u5e38\u89c1\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6574\u7406\u603b\u7ed3\uff08\u4e0b\uff09\u63d2\u56fe\" alt=\"\u5e38\u89c1\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6574\u7406\u603b\u7ed3\uff08\u4e0b\uff09\u63d2\u56fe\" \/><\/a><\/p>\n<h3>\u7b97\u6cd5\u7b80\u4ecb<\/h3>\n<p>\u7b97\u6cd5\u662f\u6307\u89e3\u9898\u65b9\u6848\u7684\u51c6\u786e\u800c\u5b8c\u6574\u7684\u63cf\u8ff0\uff0c\u662f\u4e00\u7cfb\u5217\u89e3\u51b3\u95ee\u9898\u7684\u6e05\u6670\u6307\u4ee4\uff0c\u7b97\u6cd5\u4ee3\u8868\u7740\u7528\u7cfb\u7edf\u7684\u65b9\u6cd5\u63cf\u8ff0\u89e3\u51b3\u95ee\u9898\u7684\u7b56\u7565\u673a\u5236\u3002\u5bf9\u4e8e\u540c\u4e00\u4e2a\u95ee\u9898\u7684\u89e3\u51b3\uff0c\u53ef\u80fd\u4f1a\u5b58\u5728\u7740\u4e0d\u540c\u7684\u7b97\u6cd5\uff0c\u4e3a\u4e86\u8861\u91cf\u4e00\u4e2a\u7b97\u6cd5\u7684\u4f18\u52a3\uff0c\u63d0\u51fa\u4e86\u7a7a\u95f4\u590d\u6742\u5ea6\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6\u8fd9\u4e24\u4e2a\u6982\u5ff5\u3002<\/p>\n<h3>\u65f6\u95f4\u590d\u6742\u5ea6<\/h3>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u7b97\u6cd5\u4e2d\u57fa\u672c\u64cd\u4f5c\u91cd\u590d\u6267\u884c\u7684\u6b21\u6570\u662f\u95ee\u9898\u89c4\u6a21n\u7684\u67d0\u4e2a\u51fd\u6570f(n)\uff0c\u7b97\u6cd5\u7684\u65f6\u95f4\u5ea6\u91cf\u8bb0\u4e3a<\/p>\n<pre>T(n) = O(f(n))<\/pre>\n<p>\u5b83\u8868\u793a\u968f\u95ee\u9898\u89c4\u6a21n\u7684\u589e\u5927\uff0c\u7b97\u6cd5\u6267\u884c\u65f6\u95f4\u7684\u589e\u957f\u7387\u548cf(n)\u7684\u589e\u957f\u7387\u76f8\u540c\uff0c\u79f0\u4f5c\u7b97\u6cd5\u7684\u6e10\u8fd1\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u7b80\u79f0\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u8fd9\u91cc\u9700\u8981\u91cd\u70b9\u7406\u89e3\u8fd9\u4e2a\u589e\u957f\u7387\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u770b\u4e0b\u97623\u4e2a\u4ee3\u7801\uff1a<\/p>\n<pre>1\u3001{++x;}\r\n2\u3001for(i = 1; i &lt;= n; i++) { ++x; }\r\n3\u3001for(j = 1; j &lt;= n; j++)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for(j = 1; j &lt;= n; j++)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { ++x; }\r\n\r\n\u4e0a\u8ff0\u542b\u6709 ++x \u64cd\u4f5c\u7684\u8bed\u53e5\u7684\u9891\u5ea6\u5206\u522b\u4e3a1 \u3001n \u3001n^2\uff0c\r\n\r\n\u5047\u8bbe\u95ee\u9898\u7684\u89c4\u6a21\u6269\u5927\u4e86n\u500d\uff0c3\u4e2a\u4ee3\u7801\u7684\u589e\u957f\u7387\u5206\u522b\u662f1 \u3001n \u3001n^2\r\n\r\n\u5b83\u4eec\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u522b\u4e3aO(1)\u3001O(n)\u3001O(n^2)<\/pre>\n<h3>\u7a7a\u95f4\u590d\u6742\u5ea6<\/h3>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6\u662f\u5bf9\u4e00\u4e2a\u7b97\u6cd5\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4e34\u65f6\u5360\u7528\u5b58\u50a8\u7a7a\u95f4\u5927\u5c0f\u7684\u91cf\u5ea6\uff0c\u8bb0\u505aS(n)=O(f(n))\u3002\u4e00\u4e2a\u7b97\u6cd5\u7684\u4f18\u52a3\u4e3b\u8981\u4ece\u7b97\u6cd5\u7684\u6267\u884c\u65f6\u95f4\u548c\u6240\u9700\u8981\u5360\u7528\u7684\u5b58\u50a8\u7a7a\u95f4\u4e24\u4e2a\u65b9\u9762\u8861\u91cf\u3002<\/p>\n<h1>\u4e8c\u3001\u67e5\u627e\u7b97\u6cd5<\/h1>\n<p>\u67e5\u627e\u548c\u6392\u5e8f\u662f\u6700\u57fa\u7840\u4e5f\u662f\u6700\u91cd\u8981\u7684\u4e24\u7c7b\u7b97\u6cd5\uff0c\u719f\u7ec3\u5730\u638c\u63e1\u8fd9\u4e24\u7c7b\u7b97\u6cd5\uff0c\u5e76\u80fd\u5bf9\u8fd9\u4e9b\u7b97\u6cd5\u7684\u6027\u80fd\u8fdb\u884c\u5206\u6790\u5f88\u91cd\u8981\uff0c\u8fd9\u4e24\u7c7b\u7b97\u6cd5\u4e2d\u4e3b\u8981\u5305\u62ec\u4e8c\u5206\u67e5\u627e\u3001\u5feb\u901f\u6392\u5e8f\u3001\u5f52\u5e76\u6392\u5e8f\u7b49\u7b49\u3002<\/p>\n<h3>\u987a\u5e8f\u67e5\u627e<\/h3>\n<p>\u987a\u5e8f\u67e5\u627e\u53c8\u79f0\u7ebf\u6027\u67e5\u627e\u3002\u5b83\u7684\u8fc7\u7a0b\u4e3a\uff1a\u4ece\u67e5\u627e\u8868\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\u9010\u4e2a\u4e0e\u7ed9\u5b9a\u5173\u952e\u5b57\u6bd4\u8f83\uff0c\u82e5\u67d0\u4e2a\u8bb0\u5f55\u7684\u5173\u952e\u5b57\u548c\u7ed9\u5b9a\u503c\u6bd4\u8f83\u76f8\u7b49\uff0c\u5219\u67e5\u627e\u6210\u529f\uff0c\u5426\u5219\uff0c\u82e5\u76f4\u81f3\u7b2c\u4e00\u4e2a\u8bb0\u5f55\uff0c\u5176\u5173\u952e\u5b57\u548c\u7ed9\u5b9a\u503c\u6bd4\u8f83\u90fd\u4e0d\u7b49\uff0c\u5219\u8868\u660e\u8868\u4e2d\u6ca1\u6709\u6240\u67e5\u8bb0\u5f55\u67e5\u627e\u4e0d\u6210\u529f\uff0c\u5b83\u7684\u7f3a\u70b9\u662f\u6548\u7387\u4f4e\u4e0b\u3002<\/p>\n<h3>\u4e8c\u5206\u67e5\u627e<\/h3>\n<ul>\n<li><strong>\u7b80\u4ecb<\/strong><\/li>\n<\/ul>\n<p>\u4e8c\u5206\u67e5\u627e\u53c8\u79f0\u6298\u534a\u67e5\u627e\uff0c\u5bf9\u4e8e\u6709\u5e8f\u8868\u6765\u8bf4\uff0c\u5b83\u7684\u4f18\u70b9\u662f\u6bd4\u8f83\u6b21\u6570\u5c11\uff0c\u67e5\u627e\u901f\u5ea6\u5feb\uff0c\u5e73\u5747\u6027\u80fd\u597d\u3002<\/p>\n<p>\u4e8c\u5206\u67e5\u627e\u7684\u57fa\u672c\u601d\u60f3\u662f\u5c06n\u4e2a\u5143\u7d20\u5206\u6210\u5927\u81f4\u76f8\u7b49\u7684\u4e24\u90e8\u5206\uff0c\u53d6a[n\/2]\u4e0ex\u505a\u6bd4\u8f83\uff0c\u5982\u679cx=a[n\/2],\u5219\u627e\u5230x\uff0c\u7b97\u6cd5\u4e2d\u6b62\uff1b\u5982\u679cx&lt;a[n\/2]\uff0c\u5219\u53ea\u8981\u5728\u6570\u7ec4a\u7684\u5de6\u534a\u90e8\u5206\u7ee7\u7eed\u641c\u7d22x\uff0c\u5982\u679cx&gt;a[n\/2]\uff0c\u5219\u53ea\u8981\u5728\u6570\u7ec4a\u7684\u53f3\u534a\u90e8\u641c\u7d22x\u3002<\/p>\n<p>\u4e8c\u5206\u67e5\u627e\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(logn)<\/p>\n<ul>\n<li><strong>\u5b9e\u73b0<\/strong><\/li>\n<\/ul>\n<pre>\/\/\u7ed9\u5b9a\u6709\u5e8f\u67e5\u627e\u8868array \u4e8c\u5206\u67e5\u627e\u7ed9\u5b9a\u7684\u503cdata\r\n\/\/\u67e5\u627e\u6210\u529f\u8fd4\u56de\u4e0b\u6807 \u67e5\u627e\u5931\u8d25\u8fd4\u56de-1\r\nfunc funBinSearch(array []int, data int) int {\r\n   low , high := 0, len(array) - 1\r\n   for (low &lt;= high) {\r\n      mid := (low + high) \/ 2\r\n      if data == array[mid] {\r\n         return mid\r\n      } else if data &lt; array[mid] {\r\n         high = mid - 1;\r\n      } else {\r\n         low = mid + 1;\r\n      }\r\n   }\r\n   return -1;\r\n}<\/pre>\n<h1>\u4e09\u3001\u6392\u5e8f\u7b97\u6cd5<\/h1>\n<p>\u6392\u5e8f\u662f\u8ba1\u7b97\u673a\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\u7684\u4e00\u79cd\u91cd\u8981\u64cd\u4f5c\uff0c\u5b83\u7684\u529f\u80fd\u662f\u5c06\u4e00\u4e2a\u6570\u636e\u5143\u7d20\uff08\u6216\u8bb0\u5f55\uff09\u7684\u4efb\u610f\u5e8f\u5217\uff0c\u91cd\u65b0\u6392\u5217\u6210\u4e00\u4e2a\u6309\u5173\u952e\u5b57\u6709\u5e8f\u7684\u5e8f\u5217\u3002\u4e0b\u9762\u4e3b\u8981\u5bf9\u4e00\u4e9b\u5e38\u89c1\u7684\u6392\u5e8f\u7b97\u6cd5\u505a\u4ecb\u7ecd\uff0c\u5e76\u5206\u6790\u5b83\u4eec\u7684\u65f6\u7a7a\u590d\u6742\u5ea6\u3002<\/p>\n<ul>\n<li><strong>\u5e38\u89c1\u6392\u5e8f\u7b97\u6cd5<\/strong><\/li>\n<\/ul>\n<p><a href=\"http:\/\/fwq.ai\/wp-content\/uploads\/2018\/01\/2243690-900e465a97d21d76.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15354\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-900e465a97d21d76.png\" width=\"467\" height=\"278\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-900e465a97d21d76.png 467w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-900e465a97d21d76-300x179.png 300w\" sizes=\"auto, (max-width: 467px) 100vw, 467px\" title=\"\u5e38\u89c1\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6574\u7406\u603b\u7ed3\uff08\u4e0b\uff09\u63d2\u56fe1\" alt=\"\u5e38\u89c1\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6574\u7406\u603b\u7ed3\uff08\u4e0b\uff09\u63d2\u56fe1\" \/><\/a><\/p>\n<ul>\n<li><strong>\u5e38\u89c1\u6392\u5e8f\u7b97\u6cd5\u6027\u80fd\u6bd4\u8f83\uff1a<\/strong><\/li>\n<\/ul>\n<p><a href=\"http:\/\/fwq.ai\/wp-content\/uploads\/2018\/01\/2243690-da1c8b997a16c17c.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15356\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-da1c8b997a16c17c.png\" width=\"630\" height=\"365\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-da1c8b997a16c17c.png 630w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/2243690-da1c8b997a16c17c-300x174.png 300w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" title=\"\u5e38\u89c1\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6574\u7406\u603b\u7ed3\uff08\u4e0b\uff09\u63d2\u56fe2\" alt=\"\u5e38\u89c1\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6574\u7406\u603b\u7ed3\uff08\u4e0b\uff09\u63d2\u56fe2\" \/><\/a><\/p>\n<p>\u4e0a\u9762\u8fd9\u5f20\u8868\u4e2d\u6709\u7a33\u5b9a\u6027\u8fd9\u4e00\u9879\uff0c\u6392\u5e8f\u7684\u7a33\u5b9a\u6027\u662f\u6307\u5982\u679c\u5728\u6392\u5e8f\u7684\u5e8f\u5217\u4e2d\uff0c\u5b58\u5728\u524d\u540e\u76f8\u540c\u7684\u4e24\u4e2a\u5143\u7d20\u7684\u8bdd\uff0c\u6392\u5e8f\u524d\u548c\u6392\u5e8f\u540e\u4ed6\u4eec\u7684\u76f8\u5bf9\u4f4d\u7f6e\u4e0d\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<p>\u4e0b\u9762\u4ece\u5192\u6ce1\u6392\u5e8f\u5f00\u59cb\u9010\u4e00\u4ecb\u7ecd\u3002<\/p>\n<h3>\u5192\u6ce1\u6392\u5e8f<\/h3>\n<ul>\n<li><strong>\u7b80\u4ecb<\/strong><\/li>\n<\/ul>\n<p>\u5192\u6ce1\u6392\u5e8f\u7684\u57fa\u672c\u601d\u60f3\u662f\uff1a\u8bbe\u6392\u5e8f\u5e8f\u5217\u7684\u8bb0\u5f55\u4e2a\u6570\u4e3an\uff0c\u8fdb\u884cn-1\u6b21\u904d\u5386\uff0c\u6bcf\u6b21\u904d\u5386\u4ece\u5f00\u59cb\u4f4d\u7f6e\u4f9d\u6b21\u5f80\u540e\u6bd4\u8f83\u524d\u540e\u76f8\u90bb\u5143\u7d20\uff0c\u8fd9\u6837\u8f83\u5927\u7684\u5143\u7d20\u5f80\u540e\u79fb\uff0cn-1\u6b21\u904d\u5386\u7ed3\u675f\u540e\uff0c\u5e8f\u5217\u6709\u5e8f\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5bf9\u5e8f\u5217(3,2,1,5)\u8fdb\u884c\u6392\u5e8f\u7684\u8fc7\u7a0b\u662f\uff1a\u5171\u8fdb\u884c3\u6b21\u904d\u5386\uff0c\u7b2c1\u6b21\u904d\u5386\u65f6\u5148\u6bd4\u8f833\u548c2\uff0c\u4ea4\u6362\uff0c\u7ee7\u7eed\u6bd4\u8f833\u548c1,\u4ea4\u6362\uff0c\u518d\u6bd4\u8f833\u548c5\uff0c\u4e0d\u4ea4\u6362\uff0c\u8fd9\u6837\u7b2c1\u6b21\u904d\u5386\u7ed3\u675f\uff0c\u6700\u5927\u503c5\u5728\u6700\u540e\u7684\u4f4d\u7f6e\uff0c\u5f97\u5230\u5e8f\u5217(2,1,3,5)\u3002\u7b2c2\u6b21\u904d\u5386\u65f6\u5148\u6bd4\u8f832\u548c1\uff0c\u4ea4\u6362\uff0c\u7ee7\u7eed\u6bd4\u8f832\u548c3\uff0c\u4e0d\u4ea4\u6362\uff0c\u7b2c2\u6b21\u904d\u5386\u7ed3\u675f\u65f6\u6b21\u5927\u503c3\u5728\u5012\u6570\u7b2c2\u7684\u4f4d\u7f6e\uff0c\u5f97\u5230\u5e8f\u5217(1,2,3,5)\uff0c\u7b2c3\u6b21\u904d\u5386\u65f6\uff0c\u5148\u6bd4\u8f831\u548c2\uff0c\u4e0d\u4ea4\u6362\uff0c\u5f97\u5230\u6700\u7ec8\u6709\u5e8f\u5e8f\u5217(1,2,3,5)\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u5728\u67d0\u6b21\u904d\u5386\u4e2d\u6ca1\u6709\u53d1\u751f\u4ea4\u6362\uff0c\u90a3\u4e48\u5c31\u4e0d\u5fc5\u8fdb\u884c\u4e0b\u6b21\u904d\u5386\uff0c\u56e0\u4e3a\u5e8f\u5217\u5df2\u7ecf\u6709\u5e8f\u3002<\/p>\n<ul>\n<li><strong>\u5b9e\u73b0<\/strong><\/li>\n<\/ul>\n<pre>\/\/ \u5192\u6ce1\u6392\u5e8f \u6ce8\u610f flag \u7684\u4f5c\u7528\r\nfunc funBubbleSort(array []int) []int {\r\n   flag := true\r\n   for i := 0; i &lt; len(array) - 1 &amp;&amp; flag; i++ {\r\n      flag = false\r\n      for j := 0; j &lt; len(array) - 1 - i; j++ {\r\n         if array[j] &gt; array[j + 1] {\r\n            temp := array[j]\r\n            array[j] = array[j + 1]\r\n            array[j+1] = temp\r\n            flag = true\r\n         }\r\n      }\r\n   }\r\n   return array;\r\n}<\/pre>\n<ul>\n<li><strong>\u5206\u6790<\/strong><\/li>\n<\/ul>\n<p>\u6700\u4f73\u60c5\u51b5\u4e0b\u5192\u6ce1\u6392\u5e8f\u53ea\u9700\u4e00\u6b21\u904d\u5386\u5c31\u80fd\u786e\u5b9a\u6570\u7ec4\u5df2\u7ecf\u6392\u597d\u5e8f\uff0c\u4e0d\u9700\u8981\u8fdb\u884c\u4e0b\u4e00\u6b21\u904d\u5386\uff0c\u6240\u4ee5\u6700\u4f73\u60c5\u51b5\u4e0b\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a** O(n) **\u3002<\/p>\n<p>\u6700\u574f\u60c5\u51b5\u4e0b\u5192\u6ce1\u6392\u5e8f\u9700\u8981n-1\u6b21\u904d\u5386\uff0c\u7b2c\u4e00\u6b21\u904d\u5386\u9700\u8981\u6bd4\u8f83n-1\u6b21\uff0c\u7b2c\u4e8c\u6b21\u904d\u5386\u9700\u8981n-2\u6b21\uff0c\u2026\uff0c\u6700\u540e\u4e00\u6b21\u9700\u8981\u6bd4\u8f831\u6b21\uff0c\u6700\u5dee\u60c5\u51b5\u4e0b\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a** O(n^2) **\u3002<\/p>\n<h3>\u7b80\u5355\u9009\u62e9\u6392\u5e8f<\/h3>\n<ul>\n<li><strong>\u7b80\u4ecb<\/strong><\/li>\n<\/ul>\n<p>\u7b80\u5355\u9009\u62e9\u6392\u5e8f\u7684\u601d\u60f3\u662f\uff1a\u8bbe\u6392\u5e8f\u5e8f\u5217\u7684\u8bb0\u5f55\u4e2a\u6570\u4e3an\uff0c\u8fdb\u884cn-1\u6b21\u9009\u62e9\uff0c\u6bcf\u6b21\u5728n-i+1(i = 1,2,\u2026,n-1)\u4e2a\u8bb0\u5f55\u4e2d\u9009\u62e9\u5173\u952e\u5b57\u6700\u5c0f\u7684\u8bb0\u5f55\u4f5c\u4e3a\u6709\u6548\u5e8f\u5217\u4e2d\u7684\u7b2ci\u4e2a\u8bb0\u5f55\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6392\u5e8f\u5e8f\u5217(3,2,1,5)\u7684\u8fc7\u7a0b\u662f\uff0c\u8fdb\u884c3\u6b21\u9009\u62e9\uff0c\u7b2c1\u6b21\u9009\u62e9\u57284\u4e2a\u8bb0\u5f55\u4e2d\u9009\u62e9\u6700\u5c0f\u7684\u503c\u4e3a1\uff0c\u653e\u5728\u7b2c1\u4e2a\u4f4d\u7f6e\uff0c\u5f97\u5230\u5e8f\u5217(1,3,2,5)\uff0c\u7b2c2\u6b21\u9009\u62e9\u4ece\u4f4d\u7f6e1\u5f00\u59cb\u76843\u4e2a\u5143\u7d20\u4e2d\u9009\u62e9\u6700\u5c0f\u7684\u503c2\u653e\u5728\u7b2c2\u4e2a\u4f4d\u7f6e\uff0c\u5f97\u5230\u6709\u5e8f\u5e8f\u5217(1,2,3,5)\uff0c\u7b2c3\u6b21\u9009\u62e9\u56e0\u4e3a\u6700\u5c0f\u7684\u503c3\u5df2\u7ecf\u5728\u7b2c3\u4e2a\u4f4d\u7f6e\u4e0d\u9700\u8981\u64cd\u4f5c\uff0c\u6700\u540e\u5f97\u5230\u6709\u5e8f\u5e8f\u5217\uff081,2,3,5\uff09\u3002<\/p>\n<ul>\n<li><strong>\u5b9e\u73b0<\/strong><\/li>\n<\/ul>\n<pre>func funSelectionSort(array []int) []int {\r\n   for i := 0; i &lt; len(array); i ++ {\r\n      minKey := i\r\n      \/\/ \u6bcf\u6b21\u4ece\u672a\u6392\u5e8f\u6570\u7ec4\u4e2d\u627e\u5230\u6700\u5c0f\u503c\u7684\u5750\u6807\r\n      for j := i + 1; j &lt; len(array); j ++ {\r\n         if array[j] &lt; array[minKey] {\r\n            minKey = j;\r\n         }\r\n      }\r\n      \/\/ \u5c06\u6700\u5c0f\u503c\u653e\u5728\u6700\u524d\u9762\r\n      if minKey != i {\r\n         temp := array[minKey]\r\n         array[minKey] = array[i];\r\n         array[i] = temp;\r\n      }\r\n   }\r\n   return array;\r\n}<\/pre>\n<ul>\n<li><strong>\u5206\u6790<\/strong><\/li>\n<\/ul>\n<p>\u7b80\u5355\u9009\u62e9\u6392\u5e8f\u8fc7\u7a0b\u4e2d\u9700\u8981\u8fdb\u884c\u7684\u6bd4\u8f83\u6b21\u6570\u4e0e\u521d\u59cb\u72b6\u6001\u4e0b\u5f85\u6392\u5e8f\u7684\u8bb0\u5f55\u5e8f\u5217\u7684\u6392\u5217\u60c5\u51b5** \u65e0\u5173\u3002\u5f53i=1\u65f6\uff0c\u9700\u8fdb\u884cn-1\u6b21\u6bd4\u8f83\uff1b\u5f53i=2\u65f6\uff0c\u9700\u8fdb\u884cn-2\u6b21\u6bd4\u8f83\uff1b\u4f9d\u6b21\u7c7b\u63a8\uff0c\u5171\u9700\u8981\u8fdb\u884c\u7684\u6bd4\u8f83\u6b21\u6570\u662f(n-1)+(n-2)+\u2026+2+1=n(n-1)\/2\uff0c\u5373\u8fdb\u884c\u6bd4\u8f83\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2) \uff0c\u8fdb\u884c\u79fb\u52a8\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n) \u3002\u603b\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2) **\u3002<\/p>\n<p>\u6700\u597d\u60c5\u51b5\u4e0b\uff0c\u5373\u5f85\u6392\u5e8f\u8bb0\u5f55\u521d\u59cb\u72b6\u6001\u5c31\u5df2\u7ecf\u662f\u6b63\u5e8f\u6392\u5217\u4e86\uff0c\u5219\u4e0d\u9700\u8981\u79fb\u52a8\u8bb0\u5f55\u3002\u6700\u574f\u60c5\u51b5\u4e0b\uff0c\u5373\u5f85\u6392\u5e8f\u8bb0\u5f55\u521d\u59cb\u72b6\u6001\u662f\u6309\u7b2c\u4e00\u6761\u8bb0\u5f55\u6700\u5927\uff0c\u4e4b\u540e\u7684\u8bb0\u5f55\u4ece\u5c0f\u5230\u5927\u987a\u5e8f\u6392\u5217\uff0c\u5219\u9700\u8981\u79fb\u52a8\u8bb0\u5f55\u7684\u6b21\u6570\u6700\u591a\u4e3a3\uff08n-1\uff09\u3002<\/p>\n<p><strong>\u7b80\u5355\u9009\u62e9\u6392\u5e8f\u662f\u4e0d\u7a33\u5b9a\u6392\u5e8f\u3002<\/strong><\/p>\n<h3>\u76f4\u63a5\u63d2\u5165\u6392\u5e8f<\/h3>\n<ul>\n<li><strong>\u7b80\u4ecb<\/strong><\/li>\n<\/ul>\n<p>\u76f4\u63a5\u63d2\u5165\u7684\u601d\u60f3\u662f\uff1a\u662f\u5c06\u4e00\u4e2a\u8bb0\u5f55\u63d2\u5165\u5230\u5df2\u6392\u597d\u5e8f\u7684\u6709\u5e8f\u8868\u4e2d\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u3001\u8bb0\u5f55\u6570\u589e1\u7684\u6709\u5e8f\u8868\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6392\u5e8f\u5e8f\u5217(3,2,1,5)\u7684\u8fc7\u7a0b\u662f\uff0c\u521d\u59cb\u65f6\u6709\u5e8f\u5e8f\u5217\u4e3a(3)\uff0c\u7136\u540e\u4ece\u4f4d\u7f6e1\u5f00\u59cb\uff0c\u5148\u8bbf\u95ee\u52302\uff0c\u5c062\u63d2\u5165\u52303\u524d\u9762\uff0c\u5f97\u5230\u6709\u5e8f\u5e8f\u5217(2,3)\uff0c\u4e4b\u540e\u8bbf\u95ee1,\u627e\u5230\u5408\u9002\u7684\u63d2\u5165\u4f4d\u7f6e\u540e\u5f97\u5230\u6709\u5e8f\u5e8f\u5217(1,2,3)\uff0c\u6700\u540e\u8bbf\u95ee5\uff0c\u5f97\u5230\u6700\u7ec8\u6709\u5e8f\u5e8f\u5217(1,2,3,5).<\/p>\n<ul>\n<li><strong>\u5b9e\u73b0<\/strong><\/li>\n<\/ul>\n<pre>func funDInsertSort(array []int) []int {\r\n   var j int\r\n   for i := 1; i &lt; len(array); i ++ {\r\n      temp := array[i]\r\n      j = i - 1\r\n      for j &gt; -1 &amp;&amp; temp &lt; array[j] {\r\n         array[j + 1] = array[j]\r\n         j--;\r\n      }\r\n      array[j+1] = temp;\r\n   }\r\n   return array;\r\n}<\/pre>\n<ul>\n<li><strong>\u5206\u6790<\/strong><\/li>\n<\/ul>\n<p>\u6700\u597d\u60c5\u51b5\u4e0b\uff0c\u5f53\u5f85\u6392\u5e8f\u5e8f\u5217\u4e2d\u8bb0\u5f55\u5df2\u7ecf\u6709\u5e8f\u65f6\uff0c\u5219\u9700\u8981n-1\u6b21\u6bd4\u8f83\uff0c\u4e0d\u9700\u8981\u79fb\u52a8\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a** O(n) \u3002\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u5f53\u5f85\u6392\u5e8f\u5e8f\u5217\u4e2d\u6240\u6709\u8bb0\u5f55\u6b63\u597d\u9006\u5e8f\u65f6\uff0c\u5219\u6bd4\u8f83\u6b21\u6570\u548c\u79fb\u52a8\u6b21\u6570\u90fd\u8fbe\u5230\u6700\u5927\u503c\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2) \u3002\u5e73\u5747\u60c5\u51b5\u4e0b\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2) **\u3002<\/p>\n<h3>\u5e0c\u5c14\u6392\u5e8f<\/h3>\n<p>\u5e0c\u5c14\u6392\u5e8f\u53c8\u79f0\u201c\u7f29\u5c0f\u589e\u91cf\u6392\u5e8f\u201d\uff0c\u5b83\u662f\u57fa\u4e8e\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u7684\u4ee5\u4e0b\u4e24\u70b9\u6027\u8d28\u800c\u63d0\u51fa\u7684\u4e00\u79cd\u6539\u8fdb\uff1a(1) \u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u5728\u5bf9\u51e0\u4e4e\u5df2\u7ecf\u6392\u597d\u5e8f\u7684\u6570\u636e\u64cd\u4f5c\u65f6\uff0c\u6548\u7387\u9ad8\uff0c\u5373\u53ef\u4ee5\u8fbe\u5230\u7ebf\u6027\u6392\u5e8f\u7684\u6548\u7387\u3002(2) \u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u4e00\u822c\u6765\u8bf4\u662f\u4f4e\u6548\u7684\uff0c\u56e0\u4e3a\u63d2\u5165\u6392\u5e8f\u6bcf\u6b21\u53ea\u80fd\u5c06\u6570\u636e\u79fb\u52a8\u4e00\u4f4d\u3002\u70b9\u51fb\u67e5\u770b\u66f4\u591a\u5173\u4e8e\u5e0c\u5c14\u6392\u5e8f\u7684\u5185\u5bb9<\/p>\n<h3>\u5f52\u5e76\u6392\u5e8f<\/h3>\n<ul>\n<li><strong>\u7b80\u4ecb<\/strong><\/li>\n<\/ul>\n<p>\u5f52\u5e76\u6392\u5e8f\u662f\u5206\u6cbb\u6cd5\u7684\u4e00\u4e2a\u5178\u578b\u5e94\u7528\uff0c\u5b83\u7684\u4e3b\u8981\u601d\u60f3\u662f\uff1a\u5c06\u5f85\u6392\u5e8f\u5e8f\u5217\u5206\u4e3a\u4e24\u90e8\u5206\uff0c\u5bf9\u6bcf\u90e8\u5206\u9012\u5f52\u5730\u5e94\u7528\u5f52\u5e76\u6392\u5e8f\uff0c\u5728\u4e24\u90e8\u5206\u90fd\u6392\u597d\u5e8f\u540e\u8fdb\u884c\u5408\u5e76\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6392\u5e8f\u5e8f\u5217(3,2,8,6,7,9,1,5)\u7684\u8fc7\u7a0b\u662f\uff0c\u5148\u5c06\u5e8f\u5217\u5206\u4e3a\u4e24\u90e8\u5206\uff0c(3,2,8,6)\u548c(7,9,1,5)\uff0c\u7136\u540e\u5bf9\u4e24\u90e8\u5206\u5206\u522b\u5e94\u7528\u5f52\u5e76\u6392\u5e8f\uff0c\u7b2c1\u90e8\u5206(3,2,8,6)\uff0c\u7b2c2\u90e8\u5206(7,9,1,5)\uff0c\u5bf9\u4e24\u4e2a\u90e8\u5206\u5206\u522b\u8fdb\u884c\u5f52\u5e76\u6392\u5e8f\uff0c\u7b2c1\u90e8\u5206\u7ee7\u7eed\u5206\u4e3a(3,2)\u548c(8,6)\uff0c(3,2)\u7ee7\u7eed\u5206\u4e3a(3)\u548c(2)\uff0c(8,6)\u7ee7\u7eed\u5206\u4e3a(8)\u548c(6)\uff0c\u4e4b\u540e\u8fdb\u884c\u5408\u5e76\u5f97\u5230(2,3)\uff0c(6,8)\uff0c\u518d\u5408\u5e76\u5f97\u5230(2,3,6,8)\uff0c\u7b2c2\u90e8\u5206\u8fdb\u884c\u5f52\u5e76\u6392\u5e8f\u5f97\u5230(1,5,7,9)\uff0c\u6700\u540e\u5408\u5e76\u4e24\u90e8\u5206\u5f97\u5230(1,2,3,5,6,7,8,9)\u3002<\/p>\n<ul>\n<li><strong>\u5b9e\u73b0<\/strong><\/li>\n<\/ul>\n<pre>\/\/\u5f52\u5e76\u6392\u5e8f\r\nstatic void funMergeSort(int[] array) {\r\n   if (array.length &gt; 1) {\r\n      int length1 = array.length \/ 2;\r\n      int[] array1 = new int[length1];\r\n      System.arraycopy(array, 0, array1, 0, length1);\r\n      funMergeSort(array1);\r\n\r\n      int length2 = array.length - length1;\r\n      int[] array2 = new int[length2];\r\n      System.arraycopy(array, length1, array2, 0, length2);\r\n      funMergeSort(array2);\r\n\r\n      int[] datas = merge(array1, array2);\r\n      System.arraycopy(datas, 0, array, 0, array.length);\r\n   }\r\n\r\n}\r\n\r\n\/\/\u5408\u5e76\u4e24\u4e2a\u6570\u7ec4\r\nstatic int[] merge(int[] list1, int[] list2) {\r\n   int[] list3 = new int[list1.length + list2.length];\r\n\r\n   int count1 = 0;\r\n   int count2 = 0;\r\n   int count3 = 0;\r\n\r\n   while (count1 &lt; list1.length &amp;&amp; count2 &lt; list2.length) {\r\n      if (list1[count1] &lt; list2[count2]) {\r\n         list3[count3++] = list1[count1++];\r\n      } else {\r\n         list3[count3++] = list2[count2++];\r\n      }\r\n   }\r\n\r\n   while (count1 &lt; list1.length) {\r\n      list3[count3++] = list1[count1++];\r\n   }\r\n\r\n   while (count2 &lt; list2.length) {\r\n      list3[count3++] = list2[count2++];\r\n   }\r\n   return list3;\r\n}<\/pre>\n<ul>\n<li><strong>\u5206\u6790<\/strong><\/li>\n<\/ul>\n<p>\u5f52\u5e76\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(nlogn)\uff0c\u5b83\u662f\u4e00\u79cd\u7a33\u5b9a\u7684\u6392\u5e8f\uff0cjava.util.Arrays\u7c7b\u4e2d\u7684sort\u65b9\u6cd5\u5c31\u662f\u4f7f\u7528\u5f52\u5e76\u6392\u5e8f\u7684\u53d8\u4f53\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n<h3>\u5feb\u901f\u6392\u5e8f<\/h3>\n<ul>\n<li><strong>\u7b80\u4ecb<\/strong><\/li>\n<\/ul>\n<p>\u5feb\u901f\u6392\u5e8f\u7684\u4e3b\u8981\u601d\u60f3\u662f\uff1a\u5728\u5f85\u6392\u5e8f\u7684\u5e8f\u5217\u4e2d\u9009\u62e9\u4e00\u4e2a\u79f0\u4e3a\u4e3b\u5143\u7684\u5143\u7d20\uff0c\u5c06\u6570\u7ec4\u5206\u4e3a\u4e24\u90e8\u5206\uff0c\u4f7f\u5f97\u7b2c\u4e00\u90e8\u5206\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u5c0f\u4e8e\u6216\u7b49\u4e8e\u4e3b\u5143\uff0c\u800c\u7b2c\u4e8c\u90e8\u5206\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u5927\u4e8e\u4e3b\u5143\uff0c\u7136\u540e\u5bf9\u4e24\u90e8\u5206\u9012\u5f52\u5730\u5e94\u7528\u5feb\u901f\u6392\u5e8f\u7b97\u6cd5\u3002<\/p>\n<ul>\n<li><strong>\u5b9e\u73b0<\/strong><\/li>\n<\/ul>\n<pre>\/\/ \u5feb\u901f\u6392\u5e8f\r\nstatic void funQuickSort(int[] mdata, int start, int end) {\r\n   if (end &gt; start) {\r\n      int pivotIndex = quickSortPartition(mdata, start, end);\r\n      funQuickSort(mdata, start, pivotIndex - 1);\r\n      funQuickSort(mdata, pivotIndex + 1, end);\r\n   }\r\n}\r\n\r\n\/\/ \u5feb\u901f\u6392\u5e8f\u524d\u7684\u5212\u5206\r\nstatic int quickSortPartition(int[] list, int first, int last) {\r\n   int pivot = list[first];\r\n   int low = first + 1;\r\n   int high = last;\r\n\r\n   while (high &gt; low) {\r\n      while (low &lt;= high &amp;&amp; list[low] &lt;= pivot) {\r\n         low++;\r\n      }\r\n\r\n      while (low &lt;= high &amp;&amp; list[high] &gt; pivot) {\r\n         high--;\r\n      }\r\n\r\n      if (high &gt; low) {\r\n         int temp = list[high];\r\n         list[high] = list[low];\r\n         list[low] = temp;\r\n      }\r\n   }\r\n\r\n   while (high &gt; first &amp;&amp; list[high] &gt;= pivot) {\r\n      high--;\r\n   }\r\n\r\n   if (pivot &gt; list[high]) {\r\n      list[first] = list[high];\r\n      list[high] = pivot;\r\n      return high;\r\n   } else {\r\n      return first;\r\n   }\r\n}<\/pre>\n<ul>\n<li><strong>\u5206\u6790<\/strong><\/li>\n<\/ul>\n<p>\u5728\u5feb\u901f\u6392\u5e8f\u7b97\u6cd5\u4e2d\uff0c\u6bd4\u8f83\u5173\u952e\u7684\u4e00\u4e2a\u90e8\u5206\u662f\u4e3b\u5143\u7684\u9009\u62e9\u3002\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u5212\u5206\u7531n\u4e2a\u5143\u7d20\u6784\u6210\u7684\u6570\u7ec4\u9700\u8981\u8fdb\u884cn\u6b21\u6bd4\u8f83\u548cn\u6b21\u79fb\u52a8\uff0c\u56e0\u6b64\u5212\u5206\u9700\u8981\u7684\u65f6\u95f4\u662fO(n)\u3002\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\uff0c\u6bcf\u6b21\u4e3b\u5143\u4f1a\u5c06\u6570\u7ec4\u5212\u5206\u4e3a\u4e00\u4e2a\u5927\u7684\u5b50\u6570\u7ec4\u548c\u4e00\u4e2a\u7a7a\u6570\u7ec4\uff0c\u8fd9\u4e2a\u5927\u7684\u5b50\u6570\u7ec4\u7684\u89c4\u6a21\u662f\u5728\u4e0a\u6b21\u5212\u5206\u7684\u5b50\u6570\u7ec4\u7684\u89c4\u6a21\u4e0a\u51cf1\uff0c\u8fd9\u6837\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\u7b97\u6cd5\u9700\u8981(n-1)+(n-2)+\u2026+1= ** O(n^2) **\u65f6\u95f4\u3002<\/p>\n<p>\u6700\u4f73\u60c5\u51b5\u4e0b\uff0c\u6bcf\u6b21\u4e3b\u5143\u5c06\u6570\u7ec4\u5212\u5206\u4e3a\u89c4\u6a21\u5927\u81f4\u76f8\u7b49\u7684\u4e24\u90e8\u5206\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a** O(nlogn) **\u3002<\/p>\n<h3>\u5806\u6392\u5e8f<\/h3>\n<ul>\n<li><strong>\u7b80\u4ecb<\/strong><\/li>\n<\/ul>\n<p>\u5728\u4ecb\u7ecd\u5806\u6392\u5e8f\u4e4b\u524d\u9996\u5148\u9700\u8981\u4e86\u89e3\u5806\u7684\u5b9a\u4e49\uff0cn\u4e2a\u5173\u952e\u5b57\u5e8f\u5217K1\uff0cK2\uff0c\u2026\uff0cKn\u79f0\u4e3a\u5806\uff0c\u5f53\u4e14\u4ec5\u5f53\u8be5\u5e8f\u5217\u6ee1\u8db3\u5982\u4e0b\u6027\u8d28\uff08\u7b80\u79f0\u4e3a\u5806\u6027\u8d28\uff09\uff1a(1) ki &lt;= k(2i\uff09\u4e14 ki &lt;= k(2i+1) (1 \u2264 i\u2264 n\/2\uff09\uff0c\u5f53\u7136\uff0c\u8fd9\u662f\u5c0f\u6839\u5806\uff0c\u5927\u6839\u5806\u5219\u6362\u6210&gt;=\u53f7\u3002<\/p>\n<p>\u5982\u679c\u5c06\u4e0a\u9762\u6ee1\u8db3\u5806\u6027\u8d28\u7684\u5e8f\u5217\u770b\u6210\u662f\u4e00\u4e2a\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u5219\u5806\u7684\u542b\u4e49\u8868\u660e\uff0c\u5b8c\u5168\u4e8c\u53c9\u6811\u4e2d\u6240\u6709\u7684\u975e\u7ec8\u7aef\u8282\u70b9\u7684\u503c\u5747\u4e0d\u5927\u4e8e\uff08\u6216\u4e0d\u5c0f\u4e8e\uff09\u5176\u5de6\u53f3\u5b69\u5b50\u8282\u70b9\u7684\u503c\u3002<\/p>\n<p>\u5806\u6392\u5e8f\u7684\u4e3b\u8981\u601d\u60f3\u662f\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u5f85\u6392\u5e8f\u5e8f\u5217\uff0c\u9996\u5148\u7ecf\u8fc7\u4e00\u6b21\u8c03\u6574\uff0c\u5c06\u5e8f\u5217\u6784\u5efa\u6210\u4e00\u4e2a\u5927\u9876\u5806\uff0c\u6b64\u65f6\u7b2c\u4e00\u4e2a\u5143\u7d20\u662f\u6700\u5927\u7684\u5143\u7d20\uff0c\u5c06\u5176\u548c\u5e8f\u5217\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u4ea4\u6362\uff0c\u7136\u540e\u5bf9\u524dn-1\u4e2a\u5143\u7d20\u8c03\u6574\u4e3a\u5927\u9876\u5806\uff0c\u518d\u5c06\u5176\u7b2c\u4e00\u4e2a\u5143\u7d20\u548c\u672b\u5c3e\u5143\u7d20\u4ea4\u6362\uff0c\u8fd9\u6837\u6700\u540e\u5373\u53ef\u5f97\u5230\u6709\u5e8f\u5e8f\u5217\u3002<\/p>\n<ul>\n<li><strong>\u5b9e\u73b0<\/strong><\/li>\n<\/ul>\n<pre>\/\/\u5806\u6392\u5e8f\r\npublic class TestHeapSort {\r\n   public static void main(String[] args) {\r\n      int arr[] = { 5, 6, 1, 0, 2, 9 };\r\n      heapsort(arr, 6);\r\n      System.out.println(Arrays.toString(arr));\r\n   }\r\n\r\n   static void heapsort(int arr[], int n) {\r\n      \/\/ \u5148\u5efa\u5927\u9876\u5806\r\n      for (int i = n \/ 2 - 1; i &gt;= 0; i--) {\r\n         heapAdjust(arr, i, n);\r\n      }\r\n      for (int i = 0; i &lt; n - 1; i++) {\r\n         swap(arr, 0, n - i - 1);\r\n         heapAdjust(arr, 0, n - i - 1);\r\n      }\r\n   }\r\n\r\n   \/\/ \u4ea4\u6362\u4e24\u4e2a\u6570\r\n   static void swap(int arr[], int low, int high) {\r\n      int temp = arr[low];\r\n      arr[low] = arr[high];\r\n      arr[high] = temp;\r\n   }\r\n\r\n   \/\/ \u8c03\u6574\u5806\r\n   static void heapAdjust(int arr[], int index, int n) {\r\n      int temp = arr[index];\r\n      int child = 0;\r\n   \r\n      while (index * 2 + 1 &lt; n) {\r\n         child = index * 2 + 1;\r\n   \r\n         \/\/ child\u4e3a\u5de6\u53f3\u5b69\u5b50\u4e2d\u8f83\u5927\u7684\u90a3\u4e2a\r\n         if (child != n - 1 &amp;&amp; arr[child] &lt; arr[child + 1]) {\r\n            child++;\r\n         }\r\n         \/\/ \u5982\u679c\u6307\u5b9a\u8282\u70b9\u5927\u4e8e\u8f83\u5927\u7684\u5b69\u5b50 \u4e0d\u9700\u8981\u8c03\u6574\r\n         if (temp &gt; arr[child]) {\r\n            break;\r\n         } else {\r\n            \/\/ \u5426\u5219\u7ee7\u7eed\u5f80\u4e0b\u5224\u65ad\u5b69\u5b50\u7684\u5b69\u5b50 \u76f4\u5230\u627e\u5230\u5408\u9002\u7684\u4f4d\u7f6e\r\n            arr[index] = arr[child];\r\n            index = child;\r\n         }\r\n      }\r\n      arr[index] = temp;\r\n   }\r\n}<\/pre>\n<ul>\n<li><strong>\u5206\u6790<\/strong><\/li>\n<\/ul>\n<p>\u7531\u4e8e\u5efa\u521d\u59cb\u5806\u6240\u9700\u7684\u6bd4\u8f83\u6b21\u6570\u8f83\u591a\uff0c\u6240\u4ee5\u5806\u6392\u5e8f\u4e0d\u9002\u5b9c\u4e8e\u8bb0\u5f55\u6570\u8f83\u5c11\u7684\u6587\u4ef6\u3002\u5806\u6392\u5e8f\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u4e3aO(nlogn)\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3aO(1)\u3002\u5b83\u662f\u4e0d\u7a33\u5b9a\u7684\u6392\u5e8f\u65b9\u6cd5\u3002\u4e0e\u5feb\u6392\u548c\u5f52\u5e76\u6392\u5e8f\u76f8\u6bd4\uff0c\u5806\u6392\u5e8f\u5728\u6700\u5dee\u60c5\u51b5\u4e0b\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u4e8e\u5feb\u6392\uff0c\u7a7a\u95f4\u6548\u7387\u9ad8\u4e8e\u5f52\u5e76\u6392\u5e8f\u3002<\/p>\n<h1>\u56db\u3001\u5176\u5b83\u7b97\u6cd5<\/h1>\n<p>\u5728\u4e0a\u9762\u7684\u7bc7\u5e45\u4e2d\uff0c\u4e3b\u8981\u662f\u5bf9\u67e5\u627e\u548c\u5e38\u89c1\u7684\u51e0\u79cd\u6392\u5e8f\u7b97\u6cd5\u4f5c\u4e86\u4ecb\u7ecd\uff0c\u8fd9\u4e9b\u5185\u5bb9\u90fd\u662f\u57fa\u7840\u7684\u4f46\u662f\u5fc5\u987b\u638c\u63e1\u7684\u5185\u5bb9\uff0c\u5c24\u5176\u662f\u4e8c\u5206\u67e5\u627e\u3001\u5feb\u6392\u3001\u5806\u6392\u3001\u5f52\u5e76\u6392\u5e8f\u8fd9\u51e0\u4e2a\u66f4\u662f\u9762\u8bd5\u9ad8\u9891\u8003\u5bdf\u70b9\u3002\uff08\u8fd9\u91cc\u4e0d\u7981\u60f3\u8d77\u767e\u5ea6\u4e00\u9762\u7684\u65f6\u5019\u8ba9\u6211\u5199\u4e8c\u5206\u67e5\u627e\u548c\u5806\u6392\u5e8f\uff0c\u4e8c\u5206\u67e5\u627e\u8fd8\u884c\uff0c\u7136\u800c\u5806\u6392\u5e8f\u5f53\u65f6\u4e00\u8138\u61f5\u903c\u2026\uff09\u4e0b\u9762\u4e3b\u8981\u662f\u4ecb\u7ecd\u4e00\u4e9b\u5e38\u89c1\u7684\u5176\u5b83\u7b97\u6cd5\u3002<\/p>\n<h3>\u9012\u5f52<\/h3>\n<ul>\n<li><strong>\u7b80\u4ecb<\/strong><\/li>\n<\/ul>\n<p>\u5728\u5e73\u5e38\u89e3\u51b3\u4e00\u4e9b\u7f16\u7a0b\u6216\u8005\u505a\u4e00\u4e9b\u7b97\u6cd5\u9898\u7684\u65f6\u5019\uff0c\u7ecf\u5e38\u4f1a\u7528\u5230\u9012\u5f52\u3002\u7a0b\u5e8f\u8c03\u7528\u81ea\u8eab\u7684\u7f16\u7a0b\u6280\u5de7\u79f0\u4e3a\u9012\u5f52\u3002\u5b83\u901a\u5e38\u628a\u4e00\u4e2a\u5927\u578b\u590d\u6742\u7684\u95ee\u9898\u5c42\u5c42\u8f6c\u5316\u4e3a\u4e00\u4e2a\u4e0e\u539f\u95ee\u9898\u76f8\u4f3c\u7684\u89c4\u6a21\u8f83\u5c0f\u7684\u95ee\u9898\u6765\u6c42\u89e3\u3002\u4e0a\u9762\u4ecb\u7ecd\u7684\u5feb\u901f\u6392\u5e8f\u548c\u5f52\u5e76\u6392\u5e8f\u90fd\u7528\u5230\u4e86\u9012\u5f52\u7684\u601d\u60f3\u3002<\/p>\n<ul>\n<li><strong>\u7ecf\u5178\u4f8b\u5b50<\/strong><\/li>\n<\/ul>\n<p>\u6590\u6ce2\u90a3\u5951\u6570\u5217\uff0c\u53c8\u79f0\u9ec4\u91d1\u5206\u5272\u6570\u5217\u3001\u56e0\u6570\u5b66\u5bb6\u5217\u6602\u7eb3\u591a\u00b7\u6590\u6ce2\u90a3\u5951\u4ee5\u5154\u5b50\u7e41\u6b96\u4e3a\u4f8b\u5b50\u800c\u5f15\u5165\uff0c\u6545\u53c8\u79f0\u4e3a\u201c\u5154\u5b50\u6570\u5217\u201d\uff0c\u6307\u7684\u662f\u8fd9\u6837\u4e00\u4e2a\u6570\u5217\uff1a0\u30011\u30011\u30012\u30013\u30015\u30018\u300113\u300121\u300134\u3001\u2026\u2026\u5728\u6570\u5b66\u4e0a\uff0c\u6590\u6ce2\u7eb3\u5951\u6570\u5217\u4ee5\u5982\u4e0b\u88ab\u4ee5\u9012\u5f52\u7684\u65b9\u6cd5\u5b9a\u4e49\uff1aF\uff080\uff09=0\uff0cF\uff081\uff09=1\uff0cF\uff08n\uff09=F(n-1)+F(n-2)\uff08n\u22652\uff0cn\u2208N*\uff09\u3002<\/p>\n<pre>\/\/\u6590\u6ce2\u90a3\u5951\u6570\u5217 \u9012\u5f52\u5b9e\u73b0\r\nstatic long funFib(long index) {\r\n   if (index == 0) {\r\n      return 0;\r\n   } else if (index == 1) {\r\n      return 1;\r\n   } else {\r\n      return funFib(index - 1) + funFib(index - 2);\r\n   }\r\n}<\/pre>\n<p>\u4e0a\u9762\u4ee3\u7801\u662f\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u9012\u5f52\u5b9e\u73b0\uff0c\u7136\u800c\u6211\u4eec\u4e0d\u96be\u5f97\u5230\u5b83\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(2^n)\uff0c\u9012\u5f52\u6709\u65f6\u5019\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u89e3\u51b3\u4e00\u4e9b\u95ee\u9898\uff0c\u4f46\u662f\u5b83\u4e5f\u4f1a\u5e26\u6765\u4e00\u4e9b\u6548\u7387\u4e0a\u7684\u95ee\u9898\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u662f\u6c42\u6590\u6ce2\u90a3\u5951\u6570\u5217\u7684\u53e6\u4e00\u79cd\u65b9\u5f0f\uff0c\u6548\u7387\u6bd4\u9012\u5f52\u65b9\u6cd5\u7684\u6548\u7387\u9ad8\u3002<\/p>\n<pre>static long funFib2(long index) {\r\n   long f0 = 0;\r\n   long f1 = 1;\r\n   long f2 = 1;\r\n   if (index == 0) {\r\n      return f0;\r\n   } else if (index == 1) {\r\n      return f1;\r\n   } else if (index == 2) {\r\n      return f2;\r\n   }\r\n   for (int i = 3; i &lt;= index; i++) {\r\n      f0 = f1;\r\n      f1 = f2;\r\n      f2 = f0 + f1;\r\n   }\r\n   return f2;\r\n}<\/pre>\n<h3>\u5206\u6cbb\u7b97\u6cd5<\/h3>\n<p>\u5206\u6cbb\u7b97\u6cd5\u7684\u601d\u60f3\u662f\u5c06\u5f85\u89e3\u51b3\u7684\u95ee\u9898\u5206\u89e3\u4e3a\u51e0\u4e2a\u89c4\u6a21\u8f83\u5c0f\u4f46\u7c7b\u4f3c\u4e8e\u539f\u95ee\u9898\u7684\u5b50\u95ee\u9898\uff0c\u9012\u5f52\u5730\u6c42\u89e3\u8fd9\u4e9b\u5b50\u95ee\u9898\uff0c\u7136\u540e\u5408\u5e76\u8fd9\u4e9b\u5b50\u95ee\u9898\u7684\u89e3\u6765\u5efa\u7acb\u6700\u7ec8\u7684\u89e3\u3002\u5206\u6cbb\u7b97\u6cd5\u4e2d\u5173\u952e\u5730\u4e00\u6b65\u5176\u5b9e\u5c31\u662f\u9012\u5f52\u5730\u6c42\u89e3\u5b50\u95ee\u9898\u3002\u5173\u4e8e\u5206\u6cbb\u7b97\u6cd5\u7684\u4e00\u4e2a\u5178\u578b\u4f8b\u5b50\u5c31\u662f\u4e0a\u9762\u4ecb\u7ecd\u7684\u5f52\u5e76\u6392\u5e8f\u3002\u67e5\u770b\u66f4\u591a\u5173\u4e8e\u5206\u6cbb\u7b97\u6cd5\u7684\u5185\u5bb9<\/p>\n<h3>\u52a8\u6001\u89c4\u5212<\/h3>\n<p>\u52a8\u6001\u89c4\u5212\u4e0e\u5206\u6cbb\u65b9\u6cd5\u76f8\u4f3c\uff0c\u90fd\u662f\u901a\u8fc7\u7ec4\u5408\u5b50\u95ee\u9898\u7684\u89e3\u6765\u6c42\u89e3\u5f85\u89e3\u51b3\u7684\u95ee\u9898\u3002\u4f46\u662f\uff0c\u5206\u6cbb\u7b97\u6cd5\u5c06\u95ee\u9898\u5212\u5206\u4e3a\u4e92\u4e0d\u76f8\u4ea4\u7684\u5b50\u95ee\u9898\uff0c\u9012\u5f52\u5730\u6c42\u89e3\u5b50\u95ee\u9898\uff0c\u518d\u5c06\u5b83\u4eec\u7684\u89e3\u7ec4\u5408\u8d77\u6765\uff0c\u800c\u52a8\u6001\u89c4\u5212\u5e94\u7528\u4e8e\u5b50\u95ee\u9898\u91cd\u53e0\u7684\u60c5\u51b5\uff0c\u5373\u4e0d\u540c\u7684\u5b50\u95ee\u9898\u5177\u6709\u516c\u5171\u7684\u5b50\u5b50\u95ee\u9898\u3002\u52a8\u6001\u89c4\u5212\u65b9\u6cd5\u901a\u5e38\u7528\u6765\u6c42\u89e3\u6700\u4f18\u5316\u95ee\u9898\u3002\u67e5\u770b\u66f4\u591a\u5173\u4e8e\u52a8\u6001\u89c4\u5212\u7684\u5185\u5bb9<\/p>\n<p>\u52a8\u6001\u89c4\u5212\u5178\u578b\u7684\u4e00\u4e2a\u4f8b\u5b50\u662f\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217\u95ee\u9898\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u7b97\u6cd5\u8fd8\u6709\u5f88\u591a\uff0c\u6bd4\u5982\u8d2a\u5fc3\u7b97\u6cd5\uff0c\u56de\u6eaf\u7b97\u6cd5\u7b49\u7b49\uff0c\u8fd9\u91cc\u90fd\u4e0d\u518d\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u60f3\u8981\u719f\u7ec3\u638c\u63e1\uff0c\u8fd8\u662f\u8981\u9760\u5237\u9898\uff0c\u5237\u9898\uff0c\u5237\u9898\uff0c\u7136\u540e\u603b\u7ed3\u3002<\/p>\n<h1>\u4e94\u3001\u5e38\u89c1\u7b97\u6cd5\u9898<\/h1>\n<p>\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u7b97\u6cd5\u9898\u6c47\u603b\u3002<\/p>\n<p>\u4e0d\u4f7f\u7528\u4e34\u65f6\u53d8\u91cf\u4ea4\u6362\u4e24\u4e2a\u6570<\/p>\n<pre>static void funSwapTwo(int a, int b) {\r\n   a = a ^ b;\r\n   b = b ^ a;\r\n   a = a ^ b;\r\n   \r\n   System.out.println(a + \" \" + b);\r\n}<\/pre>\n<p>\u5224\u65ad\u4e00\u4e2a\u6570\u662f\u5426\u4e3a\u7d20\u6570<\/p>\n<p>&nbsp;<\/p>\n<p>\u5176\u5b83\u7b97\u6cd5\u9898<\/p>\n<p>1\u300115\u9053\u4f7f\u7528\u9891\u7387\u6781\u9ad8\u7684\u57fa\u7840\u7b97\u6cd5\u9898<br \/>\n2\u3001\u4e8c\u53c9\u6811\u76f8\u5173\u7b97\u6cd5\u9898<br \/>\n3\u3001\u94fe\u8868\u76f8\u5173\u7b97\u6cd5\u9898<br \/>\n4\u3001\u5b57\u7b26\u4e32\u76f8\u5173\u7b97\u6cd5\u95ee\u9898<\/p>\n<h1>\u516d\u3001\u603b\u7ed3<\/h1>\n<pre>static boolean funIsPrime(int m) {\r\n   boolean flag = true;\r\n   \r\n   if (m == 1) {\r\n      flag = false;\r\n   } else {\r\n      for (int i = 2; i &lt;= Math.sqrt(m); i++) {\r\n         if (m % i == 0) {\r\n            flag = false;\r\n            break;\r\n         }\r\n      }\r\n   }\r\n   return flag;\r\n}<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u81ea\u5df1\u5bf9\u5e38\u89c1\u7684\u7b97\u6cd5\u76f8\u5173\u5185\u5bb9\u7684\u603b\u7ed3\uff0c\u7b97\u6cd5\u8650\u6211\u5343\u767e\u904d\uff0c\u6211\u5f85\u7b97\u6cd5\u5982\u521d\u604b\uff0c\u9769\u547d\u5c1a\u672a\u6210\u529f\uff0c\u540c\u5fd7\u4ecd\u9700\u5237\u9898\uff0c\u52a0\u6cb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u662f\u5e38\u89c1\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6574\u7406\u603b\u7ed3\u7684\u4e0b\u7bc7\uff0c\u4e0a\u4e00\u7bc7\u4e3b\u8981\u662f\u5bf9\u5e38\u89c1\u7684\u6570\u636e\u7ed3\u6784\u8fdb\u884c\u96c6\u4e2d\u603b\u7ed3\uff0c\u8fd9\u7bc7\u4e3b\u8981\u662f\u603b\u7ed3\u4e00\u4e9b\u5e38\u89c1\u7684\u7b97\u6cd5\u76f8\u5173\u5185\u5bb9\uff0c\u6587\u7ae0\u4e2d\u5982\u6709\u9519\u8bef\uff0c\u6b22\u8fce\u6307\u51fa\u3002 \u4e00\u3001\u6982\u8ff0 \u4e8c\u3001\u67e5\u627e\u7b97\u6cd5 \u4e09\u3001\u6392\u5e8f\u7b97\u6cd5 \u56db\u3001\u5176\u5b83\u7b97\u6cd5 \u4e94\u3001\u5e38\u89c1\u7b97\u6cd5\u9898 \u516d\u3001\u603b\u7ed3 &nbsp; \u4e00\u3001\u6982\u8ff0 \u4ee5\u524d\u770b\u5230\u8fd9\u6837\u4e00\u53e5\u8bdd\uff0c\u8bed\u8a00\u53ea\u662f\u5de5\u5177\uff0c\u7b97\u6cd5\u624d\u662f\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u7075\u9b42\u3002\u7684\u786e\uff0c\u7b97\u6cd5\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\u7684\u5730\u4f4d\u771f\u7684\u5f88\u91cd\u8981\uff0c\u5728\u5f88\u591a\u5927\u516c\u53f8\u7684\u7b14\u8bd5\u9762\u8bd5\u4e2d\uff0c\u7b97\u6cd5\u638c\u63e1\u7a0b\u5ea6\u7684\u8003\u5bdf\u90fd\u5360\u636e\u4e86\u5f88\u5927\u4e00\u90e8\u5206\u3002\u4e0d\u7ba1\u662f\u4e3a\u4e86\u9762\u8bd5\u8fd8\u662f\u81ea\u8eab\u7f16\u7a0b\u80fd\u529b\u7684\u63d0\u5347\uff0c\u82b1\u65f6\u95f4\u53bb\u7814\u7a76\u5e38\u89c1\u7684\u7b97\u6cd5\u8fd8\u662f\u5f88\u6709\u5fc5\u8981\u7684\u3002\u4e0b\u9762\u662f\u81ea\u5df1\u5bf9\u4e8e\u7b97\u6cd5\u8fd9\u90e8\u5206\u7684\u5b66\u4e60\u603b\u7ed3\u3002 \u7b97\u6cd5\u7b80\u4ecb \u7b97\u6cd5\u662f\u6307\u89e3\u9898\u65b9\u6848\u7684\u51c6\u786e\u800c\u5b8c\u6574\u7684\u63cf\u8ff0\uff0c\u662f\u4e00\u7cfb\u5217\u89e3\u51b3\u95ee\u9898\u7684\u6e05\u6670\u6307\u4ee4\uff0c\u7b97\u6cd5\u4ee3\u8868\u7740\u7528\u7cfb\u7edf\u7684\u65b9\u6cd5\u63cf\u8ff0\u89e3\u51b3\u95ee\u9898\u7684\u7b56\u7565\u673a\u5236\u3002\u5bf9\u4e8e\u540c\u4e00\u4e2a\u95ee\u9898\u7684\u89e3\u51b3\uff0c\u53ef\u80fd\u4f1a\u5b58\u5728\u7740\u4e0d\u540c\u7684\u7b97\u6cd5\uff0c\u4e3a\u4e86\u8861\u91cf\u4e00\u4e2a\u7b97\u6cd5\u7684\u4f18\u52a3\uff0c\u63d0\u51fa\u4e86\u7a7a\u95f4\u590d\u6742\u5ea6\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6\u8fd9\u4e24\u4e2a\u6982\u5ff5\u3002 \u65f6\u95f4\u590d\u6742\u5ea6 \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u7b97\u6cd5\u4e2d\u57fa\u672c\u64cd\u4f5c\u91cd\u590d\u6267\u884c\u7684\u6b21\u6570\u662f\u95ee\u9898\u89c4\u6a21n\u7684\u67d0\u4e2a\u51fd\u6570f(n)\uff0c\u7b97\u6cd5\u7684\u65f6\u95f4\u5ea6\u91cf\u8bb0\u4e3a T(n) = O(f(n)) \u5b83\u8868\u793a\u968f\u95ee\u9898\u89c4\u6a21n\u7684\u589e\u5927\uff0c\u7b97\u6cd5\u6267\u884c\u65f6\u95f4\u7684\u589e\u957f\u7387\u548cf(n)\u7684\u589e\u957f\u7387\u76f8\u540c\uff0c\u79f0\u4f5c\u7b97\u6cd5\u7684\u6e10\u8fd1\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u7b80\u79f0\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u8fd9\u91cc\u9700\u8981\u91cd\u70b9\u7406\u89e3\u8fd9\u4e2a\u589e\u957f\u7387\u3002 \u4e3e\u4e2a\u4f8b\u5b50\uff0c\u770b\u4e0b\u97623\u4e2a\u4ee3\u7801\uff1a 1\u3001{++x;} 2\u3001for(i = 1; i &lt;= n; i++) { ++x; } 3\u3001for(j = 1; j &lt;= n; j++) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for(j = 1; j &lt;= n; j++) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { ++x; } \u4e0a\u8ff0\u542b\u6709 ++x \u64cd\u4f5c\u7684\u8bed\u53e5\u7684\u9891\u5ea6\u5206\u522b\u4e3a1 \u3001n \u3001n^2\uff0c \u5047\u8bbe\u95ee\u9898\u7684\u89c4\u6a21\u6269\u5927\u4e86n\u500d\uff0c3\u4e2a\u4ee3\u7801\u7684\u589e\u957f\u7387\u5206\u522b\u662f1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-15353","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=15353"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15353\/revisions"}],"predecessor-version":[{"id":15357,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15353\/revisions\/15357"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=15353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=15353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=15353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}