{"id":1716,"date":"2026-06-02T17:10:25","date_gmt":"2026-06-02T09:10:25","guid":{"rendered":"http:\/\/wordpress.fangt.online\/?p=1716"},"modified":"2026-06-02T17:10:25","modified_gmt":"2026-06-02T09:10:25","slug":"%e5%bd%92%e5%b9%b6%e6%8e%92%e5%ba%8f%ef%bc%88merge-sort%ef%bc%89","status":"publish","type":"post","link":"http:\/\/wordpress.fangt.online\/index.php\/2026\/06\/02\/%e5%bd%92%e5%b9%b6%e6%8e%92%e5%ba%8f%ef%bc%88merge-sort%ef%bc%89\/","title":{"rendered":"\u5f52\u5e76\u6392\u5e8f\uff08Merge Sort\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5f52\u5e76\u6392\u5e8f\u662f\u4e00\u79cd<strong>\u5206\u6cbb\u7b97\u6cd5<\/strong>\u3002\u5b83\u5c06\u4e00\u4e2a\u5927\u6570\u7ec4\u5206\u6210\u4e24\u4e2a\u5c0f\u6570\u7ec4\uff0c\u5206\u522b\u9012\u5f52\u5730\u6392\u5e8f\uff0c\u7136\u540e\u5c06\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4\u5408\u5e76\u6210\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6838\u5fc3\u4e09\u6b65\u9aa4<\/strong>\uff08\u5206\u6cbb\u4e09\u90e8\u66f2\uff09\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5206\uff08Divide\uff09<\/strong>\uff1a\u627e\u5230\u4e2d\u70b9\uff0c\u5c06\u6570\u7ec4\u5206\u6210\u5de6\u53f3\u4e24\u534a\u3002<\/li>\n\n\n\n<li><strong>\u6cbb\uff08Conquer\uff09<\/strong>\uff1a\u9012\u5f52\u5730\u5bf9\u5de6\u53f3\u4e24\u534a\u8fdb\u884c\u5f52\u5e76\u6392\u5e8f\u3002<\/li>\n\n\n\n<li><strong>\u5408\uff08Combine\uff09<\/strong>\uff1a\u5c06\u4e24\u4e2a\u5df2\u6392\u5e8f\u7684\u5b50\u6570\u7ec4\u5408\u5e76\u6210\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5173\u952e\u8bcd<\/strong>\uff1a\u7a33\u5b9a\u6392\u5e8f\u3001\u5206\u6cbb\u3001\u989d\u5916\u7a7a\u95f4 O(n)\u3001\u65f6\u95f4\u590d\u6742\u5ea6\u7a33\u5b9a O(n log n)\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b97\u6cd5\u6b65\u9aa4\uff08\u4ee5\u5347\u5e8f\u4e3a\u4f8b\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u8981\u5bf9\u6570\u7ec4 <code>arr[l..r]<\/code> \u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7ec8\u6b62\u6761\u4ef6<\/strong>\uff1a<code>l >= r<\/code>\uff0c\u5373\u5b50\u6570\u7ec4\u957f\u5ea6 \u2264 1\uff0c\u5df2\u7ecf\u6709\u5e8f\uff0c\u76f4\u63a5\u8fd4\u56de\u3002<\/li>\n\n\n\n<li><strong>\u5206\u89e3<\/strong>\uff1a<code>mid = (l + r) \/ 2<\/code><\/li>\n\n\n\n<li><strong>\u9012\u5f52\u5de6\u534a<\/strong>\uff1a<code>mergeSort(arr, l, mid)<\/code><\/li>\n\n\n\n<li><strong>\u9012\u5f52\u53f3\u534a<\/strong>\uff1a<code>mergeSort(arr, mid+1, r)<\/code><\/li>\n\n\n\n<li><strong>\u5408\u5e76<\/strong>\uff1a\u5c06 <code>arr[l..mid]<\/code> \u548c <code>arr[mid+1..r]<\/code> \u5408\u5e76\u6210\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\uff0c\u653e\u56de <code>arr[l..r]<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5408\u5e76\u8fc7\u7a0b\uff08\u5173\u952e\u64cd\u4f5c\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4\u9700\u8981<strong>\u4e34\u65f6\u6570\u7ec4<\/strong>\u8f85\u52a9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5408\u5e76\u7b97\u6cd5\u6d41\u7a0b<\/strong>\uff08\u53cc\u6307\u9488\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>i \u6307\u5411\u5de6\u534a\u8d77\u59cb\u4f4d\u7f6e l\nj \u6307\u5411\u53f3\u534a\u8d77\u59cb\u4f4d\u7f6e mid+1\nk \u6307\u5411\u4e34\u65f6\u6570\u7ec4\u8d77\u59cb\u4f4d\u7f6e 0\n\nwhile i &lt;= mid and j &lt;= r:\n    if arr&#91;i] &lt;= arr&#91;j]:\n        tmp&#91;k++] = arr&#91;i++]\n    else:\n        tmp&#91;k++] = arr&#91;j++]\n\nwhile i &lt;= mid:  # \u5de6\u534a\u5269\u4f59\n    tmp&#91;k++] = arr&#91;i++]\nwhile j &lt;= r:    # \u53f3\u534a\u5269\u4f59\n    tmp&#91;k++] = arr&#91;j++]\n\n\u5c06 tmp&#91;0..k-1] \u62f7\u8d1d\u56de arr&#91;l..r]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ee3\u7801\u5b9e\u73b0<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7ecf\u5178\u7248\u672c\uff08\u9012\u5f52 + \u4e34\u65f6\u6570\u7ec4\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint tmp&#91;100010];  \/\/ \u5168\u5c40\u4e34\u65f6\u6570\u7ec4\uff0c\u907f\u514d\u9012\u5f52\u4e2d\u53cd\u590d\u5206\u914d\n\nvoid mergeSort(int arr&#91;], int l, int r) {\n    if (l &gt;= r) return;          \/\/ \u8fb9\u754c\uff1a\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\u6216\u7a7a\n    int mid = (l + r) \/ 2;\n    mergeSort(arr, l, mid);      \/\/ \u6392\u5e8f\u5de6\u534a\n    mergeSort(arr, mid + 1, r);  \/\/ \u6392\u5e8f\u53f3\u534a\n\n    \/\/ \u5408\u5e76 &#91;l, mid] \u548c &#91;mid+1, r]\n    int i = l, j = mid + 1, k = 0;\n    while (i &lt;= mid &amp;&amp; j &lt;= r) {\n        if (arr&#91;i] &lt;= arr&#91;j])\n            tmp&#91;k++] = arr&#91;i++];\n        else\n            tmp&#91;k++] = arr&#91;j++];\n    }\n    while (i &lt;= mid) tmp&#91;k++] = arr&#91;i++];\n    while (j &lt;= r)   tmp&#91;k++] = arr&#91;j++];\n\n    \/\/ \u62f7\u8d1d\u56de\u539f\u6570\u7ec4\n    for (i = l, k = 0; i &lt;= r; ++i, ++k)\n        arr&#91;i] = tmp&#91;k];\n}\n\nint main() {\n    int arr&#91;] = {5, 3, 8, 6, 2, 7, 1, 4};\n    int n = sizeof(arr) \/ sizeof(arr&#91;0]);\n    mergeSort(arr, 0, n - 1);\n    for (int i = 0; i &lt; n; ++i)\n        cout &lt;&lt; arr&#91;i] &lt;&lt; \" \";\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u590d\u6742\u5ea6\u5206\u6790<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">\u590d\u6742\u5ea6<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u503c<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u65f6\u95f4\u590d\u6742\u5ea6\uff08\u6700\u597d\uff09<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(n \\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n \\log n)<\/annotation><\/semantics><\/math><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u6bcf\u6b21\u5212\u5206\u5747\u5300<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u65f6\u95f4\u590d\u6742\u5ea6\uff08\u6700\u574f\uff09<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(n \\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n \\log n)<\/annotation><\/semantics><\/math><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u603b\u662f\u5212\u5206\u5747\u5300\uff0c\u65e0\u9000\u5316<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u65f6\u95f4\u590d\u6742\u5ea6\uff08\u5e73\u5747\uff09<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(n \\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n \\log n)<\/annotation><\/semantics><\/math><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u7a33\u5b9a<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u7a7a\u95f4\u590d\u6742\u5ea6<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n)<\/annotation><\/semantics><\/math><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u9700\u8981\u8f85\u52a9\u6570\u7ec4\uff08\u53ef\u4f18\u5316\u5230 $O(1)$ \u4f46\u590d\u6742\u4e14\u4e0d\u7a33\u5b9a\uff09<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u7a33\u5b9a\u6027<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\"><strong>\u7a33\u5b9a<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\">\u5408\u5e76\u65f6\u76f8\u7b49\u5143\u7d20\u4f18\u5148\u53d6\u5de6\u8fb9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u63a8\u5bfc<\/strong>\uff1a<br>\u9012\u63a8\u516c\u5f0f <math data-latex=\"T(n) = 2T(n\/2) + O(n)\"><semantics><mrow><mi>T<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>=<\/mo><mn>2<\/mn><mi>T<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mi>\/<\/mi><mn>2<\/mn><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>+<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">T(n) = 2T(n\/2) + O(n)<\/annotation><\/semantics><\/math>\uff0c\u6839\u636e\u4e3b\u5b9a\u7406 <math data-latex=\"T(n) = O(n \\log n)\"><semantics><mrow><mi>T<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><mo>=<\/mo><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">T(n) = O(n \\log n)<\/annotation><\/semantics><\/math>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f52\u5e76\u6392\u5e8f\u7684\u7279\u70b9<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f18\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7a33\u5b9a<\/strong>\uff1a\u76f8\u7b49\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\u4e0d\u53d8\uff08\u5bf9\u7ed3\u6784\u4f53\u6392\u5e8f\u6709\u7528\uff09\u3002<\/li>\n\n\n\n<li><strong>\u6700\u574f\u60c5\u51b5\u4e5f\u662f O(n log n)<\/strong>\uff1a\u4e0d\u50cf\u5feb\u901f\u6392\u5e8f\u53ef\u80fd\u9000\u5316\u4e3a <math data-latex=\"O(n^2)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n^2)<\/annotation><\/semantics><\/math>\u3002<\/li>\n\n\n\n<li><strong>\u9002\u5408\u94fe\u8868\u6392\u5e8f<\/strong>\uff1a\u94fe\u8868\u5f52\u5e76\u53ea\u9700 <math data-latex=\"O(1)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mn>1<\/mn><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(1)<\/annotation><\/semantics><\/math> \u989d\u5916\u7a7a\u95f4\u3002<\/li>\n\n\n\n<li><strong>\u9002\u5408\u5916\u90e8\u6392\u5e8f<\/strong>\uff1a\u53ef\u4ee5\u5206\u5757\u8bfb\u5165\u5185\u5b58\u6392\u5e8f\u540e\u5408\u5e76\uff08\u5982\u5927\u6587\u4ef6\u6392\u5e8f\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u7f3a\u70b9<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9700\u8981\u989d\u5916 O(n) \u7a7a\u95f4<\/strong>\uff1a\u4e0d\u5982\u5feb\u901f\u6392\u5e8f\u3001\u5806\u6392\u5e8f\u8282\u7701\u7a7a\u95f4\uff08\u539f\u5730\u6392\u5e8f\uff09\u3002<\/li>\n\n\n\n<li><strong>\u9012\u5f52\u6df1\u5ea6 <\/strong><math data-latex=\"O(\\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mrow><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(\\log n)<\/annotation><\/semantics><\/math>\uff1a\u4f46\u6808\u7a7a\u95f4\u76f8\u6bd4\u989d\u5916\u6570\u7ec4\u53ef\u5ffd\u7565\u3002<\/li>\n\n\n\n<li><strong>\u5e38\u6570\u56e0\u5b50\u8f83\u5927<\/strong>\uff1a\u6bd4\u5feb\u901f\u6392\u5e8f\u6162\u4e00\u4e9b\uff08\u5e73\u5747\u60c5\u51b5\u4e0b\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e94\u7528\u573a\u666f<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6c42\u9006\u5e8f\u5bf9\u6570\u91cf<\/strong><br>\u5728\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u5b50\u6570\u7ec4\u65f6\uff0c\u82e5\u53f3\u534a\u5f53\u524d\u5143\u7d20 <code>arr[j] &lt; arr[i]<\/code>\uff0c\u5219\u5de6\u534a\u4ece i \u5230 mid \u7684\u6240\u6709\u5143\u7d20\u90fd\u5927\u4e8e arr[j]\uff0c\u5373\u4ea7\u751f <code>(mid - i + 1)<\/code> \u4e2a\u9006\u5e8f\u5bf9\u3002 <strong>\u4ee3\u7801\u7247\u6bb5<\/strong>\uff08\u5728\u5408\u5e76\u8fc7\u7a0b\u4e2d\u7d2f\u52a0\uff09\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   long long cnt = 0;\n   \/\/ \u5728 while(i&lt;=mid &amp;&amp; j&lt;=r) \u4e2d\uff1a\n   if (arr&#91;i] &lt;= arr&#91;j]) tmp&#91;k++] = arr&#91;i++];\n   else {\n       tmp&#91;k++] = arr&#91;j++];\n       cnt += (mid - i + 1);   \/\/ \u5173\u952e\uff1a\u7edf\u8ba1\u9006\u5e8f\u5bf9\n   }<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u5927\u6587\u4ef6\u5916\u90e8\u6392\u5e8f<\/strong><br>\u5c06\u5927\u6587\u4ef6\u5206\u6210\u591a\u4e2a\u5c0f\u5757\uff0c\u6bcf\u5757\u6392\u5e8f\u540e\u5199\u5165\u4e34\u65f6\u6587\u4ef6\uff0c\u518d\u591a\u8def\u5f52\u5e76\u3002<\/li>\n\n\n\n<li><strong>\u94fe\u8868\u6392\u5e8f<\/strong><br>\u94fe\u8868\u5f52\u5e76\u6392\u5e8f\u662f O(n log n) \u4e14\u7a7a\u95f4 O(1) \u7684\u7ecf\u5178\u65b9\u6cd5\u3002<\/li>\n\n\n\n<li><strong>\u7a33\u5b9a\u6392\u5e8f\u9700\u6c42<\/strong><br>\u5f53\u6392\u5e8f\u7a33\u5b9a\u6027\u5f88\u91cd\u8981\u65f6\uff08\u5982\u5148\u6309\u6210\u7ee9\u6392\u5e8f\uff0c\u518d\u6309\u5b66\u53f7\u6392\u5e8f\u9700\u8981\u7a33\u5b9a\u7b97\u6cd5\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f52\u5e76\u6392\u5e8f vs \u5feb\u901f\u6392\u5e8f<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">\u7279\u6027<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u5f52\u5e76\u6392\u5e8f<\/th><th class=\"has-text-align-left\" data-align=\"left\">\u5feb\u901f\u6392\u5e8f<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">\u65f6\u95f4\u590d\u6742\u5ea6\uff08\u5e73\u5747\uff09<\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(n \\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n \\log n)<\/annotation><\/semantics><\/math><\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(n \\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n \\log n)<\/annotation><\/semantics><\/math><\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u65f6\u95f4\u590d\u6742\u5ea6\uff08\u6700\u574f\uff09<\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(n \\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mrow><mspace width=\"0.1667em\"><\/mspace><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n \\log n)<\/annotation><\/semantics><\/math><\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(n^2)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><msup><mi>n<\/mi><mn>2<\/mn><\/msup><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n^2)<\/annotation><\/semantics><\/math>\uff08\u53ef\u4f18\u5316\u4e3a\u968f\u673a\u5316\uff09<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u7a7a\u95f4\u590d\u6742\u5ea6<\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(n)<\/annotation><\/semantics><\/math> \u989d\u5916\u7a7a\u95f4<\/td><td class=\"has-text-align-left\" data-align=\"left\"><math data-latex=\"O(\\log n)\"><semantics><mrow><mi>O<\/mi><mo form=\"prefix\" stretchy=\"false\">(<\/mo><mrow><mi>log<\/mi><mo>\u2061<\/mo><mspace width=\"0.1667em\"><\/mspace><\/mrow><mi>n<\/mi><mo form=\"postfix\" stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"application\/x-tex\">O(\\log n)<\/annotation><\/semantics><\/math>\u9012\u5f52\u6808\uff08\u539f\u5730\u5212\u5206\uff09<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u7a33\u5b9a\u6027<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u7a33\u5b9a<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u4e0d\u7a33\u5b9a\uff08\u5e38\u89c4\u5b9e\u73b0\uff09<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u9002\u7528\u573a\u666f<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u7a33\u5b9a\u6392\u5e8f\u3001\u5916\u90e8\u6392\u5e8f\u3001\u94fe\u8868\u6392\u5e8f<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u5185\u5b58\u5185\u6392\u5e8f\u3001\u671f\u671b\u901f\u5ea6\u5feb<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">\u5e38\u6570\u56e0\u5b50<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u8f83\u5927<\/td><td class=\"has-text-align-left\" data-align=\"left\">\u8f83\u5c0f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ade\u8d5b\u5efa\u8bae<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u9898\u76ee\u5bf9\u7a33\u5b9a\u6027\u65e0\u7279\u6b8a\u8981\u6c42\uff0c\u4e14\u6570\u7ec4\u89c4\u6a21\u5927\uff0c\u4e00\u822c\u7528 <code>sort<\/code>\uff08\u5feb\u901f\u6392\u5e8f\/\u5185\u7701\u6392\u5e8f\uff09\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u9700\u8981\u6c42\u9006\u5e8f\u5bf9\uff0c\u6216\u5b9e\u73b0\u7a33\u5b9a\u6392\u5e8f\uff0c\u6216\u5bf9\u94fe\u8868\u6392\u5e8f\uff0c\u7528\u5f52\u5e76\u6392\u5e8f\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c1\u8003\u9898\u53d8\u5f0f<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6c42\u9006\u5e8f\u5bf9<\/strong><\/li>\n\n\n\n<li><strong>\u6c42\u91cd\u8981\u9006\u5e8f\u5bf9<\/strong>\uff08i &lt; j \u4e14 a[i] > 2*a[j]\uff09<\/li>\n\n\n\n<li><strong>\u8ba1\u7b97\u53f3\u4fa7\u5c0f\u4e8e\u5f53\u524d\u5143\u7d20\u7684\u4e2a\u6570<\/strong><\/li>\n\n\n\n<li><strong>\u5408\u5e76 K \u4e2a\u6709\u5e8f\u94fe\u8868<\/strong>\uff08\u5206\u6cbb\u5f52\u5e76\uff09\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u5f52\u5e76\u6392\u5e8f\u6c42\u6570\u7ec4\u4e2d\u7684\u5c0f\u548c<\/strong>\uff08\u6bcf\u4e2a\u5143\u7d20\u5de6\u8fb9\u6bd4\u5b83\u5c0f\u7684\u5143\u7d20\u4e4b\u548c\uff09\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5f52\u5e76\u6392\u5e8f\u662f\u4e00\u79cd\u5206\u6cbb\u7b97\u6cd5\u3002\u5b83\u5c06\u4e00\u4e2a\u5927\u6570\u7ec4\u5206\u6210\u4e24\u4e2a\u5c0f\u6570\u7ec4\uff0c\u5206\u522b\u9012\u5f52\u5730\u6392\u5e8f\uff0c\u7136\u540e\u5c06\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4\u5408\u5e76\u6210\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-1716","post","type-post","status-publish","format-standard","hentry","category-zl"],"_links":{"self":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/comments?post=1716"}],"version-history":[{"count":1,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1716\/revisions"}],"predecessor-version":[{"id":1717,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1716\/revisions\/1717"}],"wp:attachment":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/media?parent=1716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/categories?post=1716"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/tags?post=1716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}