{"id":89018,"date":"2024-02-16T09:24:25","date_gmt":"2024-02-16T01:24:25","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=89018"},"modified":"2024-02-16T09:24:25","modified_gmt":"2024-02-16T01:24:25","slug":"jump-search","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/jump-search.html","title":{"rendered":"\u7b97\u6cd5\u2014\u2014\u8df3\u8dc3\u641c\u7d22"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u50cf\u4e8c\u8fdb\u5236\u641c\u7d22\u4e00\u6837\uff0c\u8df3\u8dc3\u641c\u7d22\u662f\u6392\u5e8f\u6570\u7ec4\u7684\u641c\u7d22\u7b97\u6cd5\u3002\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7\u56fa\u5b9a\u6b65\u9aa4\u8df3\u8fc7\u6216\u8df3\u8fc7\u67d0\u4e9b\u5143\u7d20\u4ee3\u66ff\u641c\u7d22\u6240\u6709\u5143\u7d20\u6765\u68c0\u67e5\u8f83\u5c11\u7684\u5143\u7d20\uff08\u800c\u4e0d\u662f\u7ebf\u6027\u641c\u7d22\uff09\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4f8b\u5982\uff0c\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5927\u5c0f\u4e3an\u7684\u6570\u7ec4arr []\u548c\u5757\uff08\u8981\u8df3\u8f6c\uff09\u7684\u5927\u5c0fm\u3002\u7136\u540e\u6211\u4eec\u641c\u7d22\u7d22\u5f15arr [0]\uff0carr [m]\uff0carr [2m] ... ..arr [km]\u7b49\u7b49\u3002\u4e00\u65e6\u6211\u4eec\u627e\u5230\u95f4\u9694\uff08arr [km]<\/p>\n

\u6211\u4eec\u8003\u8651\u4ee5\u4e0b\u6570\u7ec4\uff1a\uff080,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610\uff09\u3002\u6570\u7ec4\u7684\u957f\u5ea6\u4e3a16.\u8df3\u8dc3\u641c\u7d22\u5c06\u4ee5\u4e0b\u5217\u6b65\u9aa4\u627e\u523055\uff0c\u5047\u8bbe\u8981\u8df3\u8fc7\u7684\u5757\u5927\u5c0f\u4e3a4.<\/p>\n

\u6b65\u9aa41\uff1a\u4ece\u7d22\u5f150\u8df3\u8f6c\u5230\u7d22\u5f154;
\n\u6b65\u9aa42\uff1a\u4ece\u7d22\u5f154\u8df3\u8f6c\u5230\u7d22\u5f158;
\n\u6b65\u9aa43\uff1a\u4ece\u7d22\u5f158\u8df3\u8f6c\u5230\u7d22\u5f1516;
\n\u6b65\u9aa44\uff1a\u7531\u4e8e\u7d22\u5f1516\u5904\u7684\u5143\u7d20\u5927\u4e8e55\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u8fd4\u56de\u4e00\u6b65\u5230\u7d22\u5f159.
\n\u6b65\u9aa45\uff1a\u4ece\u7d22\u5f159\u6267\u884c\u7ebf\u6027\u641c\u7d22\u4ee5\u83b7\u53d6\u5143\u7d2055\u3002
\n\u8981\u8df3\u8fc7\u7684\u6700\u4f73\u5757\u5927\u5c0f\u662f\u591a\u5c11\uff1f<\/strong>
\n\u5728\u6700\u574f\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5fc5\u987b\u8fdb\u884cn \/ m\u8df3\u8f6c\uff0c\u5982\u679c\u6700\u540e\u4e00\u4e2a\u68c0\u67e5\u503c\u5927\u4e8e\u8981\u641c\u7d22\u7684\u5143\u7d20\uff0c\u5219\u5bf9\u7ebf\u6027\u641c\u7d22\u8fdb\u884cm-1\u6bd4\u8f83\u3002\u56e0\u6b64\uff0c\u6700\u574f\u60c5\u51b5\u4e0b\u7684\u6bd4\u8f83\u603b\u6570\u5c06\u4e3a\uff08\uff08n \/ m\uff09+ m-1\uff09\u3002\u5f53m =\u221an\u65f6\uff0c\u51fd\u6570\uff08\uff08n \/ m\uff09+ m-1\uff09\u7684\u503c\u5c06\u662f\u6700\u5c0f\u503c\u3002\u56e0\u6b64\uff0c\u6700\u597d\u7684\u6b65\u957f\u662fm = \u221an\u3002<\/p>\n

\/\/ C++ program to implement Jump Search\r\n\r\n#include <bits\/stdc++.h>\r\nusing namespace std;\r\n\r\nint jumpSearch(int arr[], int x, int n)\r\n{\r\n\/\/ Finding block size to be jumped\r\nint step = sqrt(n);\r\n\r\n\/\/ Finding the block where element is\r\n\/\/ present (if it is present)\r\nint prev = 0;\r\nwhile (arr[min(step, n)-1] < x) { prev = step; step += sqrt(n); if (prev >= n)\r\nreturn -1;\r\n}\r\n\r\n\/\/ Doing a linear search for x in block\r\n\/\/ beginning with prev.\r\nwhile (arr[prev] < x)\r\n{\r\nprev++;\r\n\r\n\/\/ If we reached next block or end of\r\n\/\/ array, element is not present.\r\nif (prev == min(step, n))\r\nreturn -1;\r\n}\r\n\/\/ If element is found\r\nif (arr[prev] == x)\r\nreturn prev;\r\n\r\nreturn -1;\r\n}\r\n\r\n\/\/ Driver program to test function\r\nint main()\r\n{\r\nint arr[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21,\r\n34, 55, 89, 144, 233, 377, 610 };\r\nint x = 55;\r\nint n = sizeof(arr) \/ sizeof(arr[0]);\r\n\r\n\/\/ Find the index of 'x' using Jump Search\r\nint index = jumpSearch(arr, x, n);\r\n\r\n\/\/ Print the index where 'x' is located\r\ncout << \"\\nNumber \" << x << \" is at index \" << index;\r\nreturn 0;\r\n}\r\n\r\n\/\/ Contributed by nuclode<\/pre>\n

\u8f93\u51fa\uff1a<\/p>\n

Number 55 is at index 10<\/p>\n

\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO\uff08\u221an\uff09
\n\u8f85\u52a9\u7a7a\u95f4\uff1aO\uff081\uff09<\/p>\n

\u6ce8\u610f\uff1a<\/strong><\/p>\n

\u8be5\u67e5\u627e\u53ea\u9488\u5bf9\u5df2\u7ecf\u6392\u5e8f\u7684\u6570\u7ec4\u3002
\n\u8981\u8df3\u8fc7\u7684\u5757\u7684\u6700\u4f73\u5927\u5c0f\u662fO\uff08\u221an\uff09\u3002\u8fd9\u4f7f\u5f97\u8df3\u8dc3\u641c\u7d22O\uff08\u221an\uff09\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002
\n\u8df3\u8dc3\u641c\u7d22\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5728\u7ebf\u6027\u641c\u7d22\uff08\uff08O\uff08n\uff09\uff09\u548c\u4e8c\u8fdb\u5236\u641c\u7d22\uff08O\uff08Log n\uff09\uff09\u4e4b\u95f4\u3002
\n\u4e8c\u8fdb\u5236\u641c\u7d22\u6bd4\u8df3\u8dc3\u641c\u7d22\u66f4\u597d\uff0c\u4f46\u8df3\u8f6c\u641c\u7d22\u5177\u6709\u6211\u4eec\u4ec5\u904d\u5386\u4e00\u6b21\u7684\u4f18\u70b9\uff08\u4e8c\u8fdb\u5236\u641c\u7d22\u53ef\u80fd\u9700\u8981\u6700\u591a\u4e3a0\uff08Log n\uff09\u8df3\u8f6c\uff09\uff0c\u8003\u8651\u8981\u641c\u7d22\u7684\u5143\u7d20\u662f\u6700\u5c0f\u5143\u7d20\u6216\u5c0f\u4e8e\u6700\u5c0f\u7684\uff09\u3002\u56e0\u6b64\uff0c\u5728\u8df3\u56de\u6210\u672c\u9ad8\u6602\u7684\u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Jump Search\u3002<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.cnblogs.com\/wongyi\/p\/7729755.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttp:\/\/lrxjmw.cn\/jump-search.html<\/a>\u7f16\u8f91\uff1a\u738b\u6bc5\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u50cf\u4e8c\u8fdb\u5236\u641c\u7d22\u4e00\u6837\uff0c\u8df3\u8dc3\u641c\u7d22\u662f\u6392\u5e8f\u6570\u7ec4\u7684\u641c\u7d22\u7b97\u6cd5\u3002\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7\u56fa\u5b9a\u6b65\u9aa4\u8df3\u8fc7\u6216\u8df3\u8fc7\u67d0\u4e9b\u5143\u7d20\u4ee3\u66ff\u641c\u7d22\u6240\u6709\u5143\u7d20 […]<\/p>\n","protected":false},"author":564,"featured_media":89019,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[158],"class_list":["post-89018","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-jump-search"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/89018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/564"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=89018"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/89018\/revisions"}],"predecessor-version":[{"id":89113,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/89018\/revisions\/89113"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/89019"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=89018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=89018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=89018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}