{"id":223,"date":"2024-11-10T22:59:45","date_gmt":"2024-11-10T22:59:45","guid":{"rendered":"https:\/\/akosgombkoto.info\/?page_id=223"},"modified":"2025-01-15T09:36:34","modified_gmt":"2025-01-15T09:36:34","slug":"binaris-kereses-algoritmus","status":"publish","type":"page","link":"https:\/\/akosgombkoto.info\/en\/binaris-kereses-algoritmus\/","title":{"rendered":"Bin\u00e1ris keres\u00e9s algoritmus"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; admin_label=&#8221;Header&#8221; _builder_version=&#8221;4.27.3&#8243; _module_preset=&#8221;default&#8221; custom_padding=&#8221;0px||0px||false|false&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_row column_structure=&#8221;1_2,1_2&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; custom_padding=&#8221;0px|||||&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_image src=&#8221;https:\/\/akosgombkoto.info\/wp-content\/uploads\/2025\/01\/data-science-070-2.png&#8221; title_text=&#8221;data-science-070-2&#8243; _builder_version=&#8221;4.27.4&#8243; _module_preset=&#8221;default&#8221; max_width_tablet=&#8221;500px&#8221; max_width_phone=&#8221;220px&#8221; max_width_last_edited=&#8221;off|tablet&#8221; max_height_tablet=&#8221;200px&#8221; max_height_phone=&#8221;100px&#8221; max_height_last_edited=&#8221;on|phone&#8221; custom_margin=&#8221;|||-8vw|false|false&#8221; custom_margin_tablet=&#8221;|||0vw|false|false&#8221; custom_margin_phone=&#8221;&#8221; custom_margin_last_edited=&#8221;on|tablet&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;][\/et_pb_image][\/et_pb_column][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; custom_padding=&#8221;120px||||false|false&#8221; custom_padding_tablet=&#8221;0px||||false|false&#8221; custom_padding_phone=&#8221;&#8221; custom_padding_last_edited=&#8221;on|tablet&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_text _builder_version=&#8221;4.27.3&#8243; _module_preset=&#8221;d72c0383-6487-4f2c-ac5c-7d48a6376757&#8243; header_font=&#8221;Roboto Slab||||||||&#8221; header_text_color=&#8221;#000000&#8243; header_font_size=&#8221;52px&#8221; header_line_height=&#8221;1.2em&#8221; custom_margin=&#8221;||10px||false|false&#8221; header_font_size_tablet=&#8221;40px&#8221; header_font_size_phone=&#8221;20px&#8221; header_font_size_last_edited=&#8221;on|phone&#8221; locked=&#8221;off&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<h1>Binary Search Algorithm<\/h1>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/akosgombkoto.info\/wp-content\/uploads\/2024\/11\/03_Binary_Search_Kepernyokep-2024-11-09-204252-1.png&#8221; title_text=&#8221;03_Binary_Search_K\u00e9perny\u0151k\u00e9p 2024-11-09 204252 (1)&#8221; show_in_lightbox=&#8221;on&#8221; _builder_version=&#8221;4.27.3&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][\/et_pb_image][\/et_pb_column][\/et_pb_row][\/et_pb_section][et_pb_section fb_built=&#8221;1&#8243; admin_label=&#8221;Blog&#8221; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_row _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.16&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221;][et_pb_text _builder_version=&#8221;4.27.4&#8243; _module_preset=&#8221;default&#8221; text_font=&#8221;Roboto Mono||||||||&#8221; text_text_color=&#8221;#fcb03a&#8221; text_font_size=&#8221;18px&#8221; text_line_height=&#8221;1.8em&#8221; background_color=&#8221;#042f4f&#8221; custom_padding=&#8221;15px|20px|15px|20px|true|true&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<p style=\"text-align: justify;\" class=\"translation-block\">Binary Search is one of the most commonly used algorithms for searching in a list.\nThe code was executed twice, as shown in the image. It includes error handling: the element 52 is found in the list defined in the code, as seen in the Visual Studio command line output, while for the element 61, it correctly indicates that it is not part of the list, which is indeed true.<\/p>\n<p>[\/et_pb_text][et_pb_toggle title=&#8221;Binary Search m\u0171k\u00f6d\u00e9se: (leny\u00edl\u00f3 tartalom &#8211; kattints a jobb sz\u00e9ls\u0151 + ikonra)&#8221; open_toggle_text_color=&#8221;#fcb03a&#8221; open_toggle_background_color=&#8221;#042f4f&#8221; closed_toggle_text_color=&#8221;#fcb03a&#8221; closed_toggle_background_color=&#8221;#042f4f&#8221; icon_color=&#8221;#fcb03a&#8221; open_icon_color=&#8221;#fcb03a&#8221; _builder_version=&#8221;4.27.4&#8243; _module_preset=&#8221;default&#8221; title_font_size=&#8221;18px&#8221; closed_title_font_size=&#8221;18px&#8221; body_text_color=&#8221;#FFFFFF&#8221; body_font_size=&#8221;16px&#8221; body_line_height=&#8221;1.8em&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<p style=\"text-align: justify;\">Binary Search is an efficient algorithm for searching in sorted lists, applying the divide-and-conquer principle. The steps are as follows:<\/p>\n<p style=\"text-align: justify;\">1. Conditions:<br \/>Binary Search requires that the list containing the data to be searched is sorted, meaning the elements must be arranged in ascending (or descending) order.<\/p>\n<p style=\"text-align: justify;\">2. Initial Assumption:<br \/>The search starts with the middle element of the list. The boundaries of the search range are defined by the start (left) and the end (right) of the list.<\/p>\n<p style=\"text-align: justify;\">3. Examining the Middle Element:<br \/>If the middle element matches the target, the search is successful, and the position of the target is returned.<br \/>If the middle element is smaller than the target, the search continues on the right side (after the middle element).<br \/>If the middle element is larger than the target, the search continues on the left side (before the middle element).<br \/>4. Narrowing Down:<br \/>At each step, the search range is halved based on the middle element, reducing the search space and speeding up the process.<\/p>\n<p style=\"text-align: justify;\">5. Completion:<br \/>The search ends either when the target element is found or when the left pointer (left) surpasses the right pointer (right), indicating that the target is not in the list.<\/p>\n<p style=\"text-align: justify;\">Example:<br \/>Suppose we want to find the number 40 in a sorted list:<\/p>\n<p style=\"text-align: justify;\" class=\"translation-block\">[10, 20, 30, 40, 50, 60, 70, 80]\n<br>\nFirst Step:\nLeft pointer (left) = 0\nRight pointer (right) = 7\nMiddle element: arr[3] = 40\nSince the middle element equals the target (40), the search is successful.\n<br>\nTime Complexity:\nBinary Search reduces the search range by half at each step, resulting in logarithmic complexity: O(log n), where n is the number of elements in the list. Even in the worst-case scenario, only a logarithmic number of steps is required.<\/p>\n<p style=\"text-align: justify;\">Advantages:<br \/>Allows fast searching in large, sorted lists.<br \/>By halving the search range in each step, it quickly locates the target element.<br \/>Disadvantages:<br \/>The list must be sorted. If the list is unsorted, it must first be sorted, which adds extra time and computational cost.<\/p>\n<p>[\/et_pb_toggle][et_pb_toggle title=&#8221;K\u00f3dmag: (leny\u00edl\u00f3 tartalom &#8211; kattints a jobb sz\u00e9ls\u0151 + ikonra)&#8221; open_toggle_text_color=&#8221;#fcb03a&#8221; open_toggle_background_color=&#8221;#042f4f&#8221; closed_toggle_text_color=&#8221;#fcb03a&#8221; closed_toggle_background_color=&#8221;#042f4f&#8221; icon_color=&#8221;#fcb03a&#8221; open_icon_color=&#8221;#fcb03a&#8221; _builder_version=&#8221;4.27.3&#8243; _module_preset=&#8221;default&#8221; title_font_size=&#8221;18px&#8221; closed_title_font_size=&#8221;18px&#8221; body_text_color=&#8221;#FFFFFF&#8221; body_font_size=&#8221;16px&#8221; body_line_height=&#8221;1.8em&#8221; global_colors_info=&#8221;{}&#8221;]<\/p>\n<pre class=\"aLF-aPX-K0-aPE\">def binary_search(list, target):\n    left, right = 0, len(list) - 1\n    \n    while left &lt;= right:\n        mid = (left + right) \/\/ 2\n        \n        # Ha a k\u00f6z\u00e9ps\u0151 elem az, amit keres\u00fcnk\n        if list[mid] == target:\n            return mid\n        \n        # Ha a k\u00f6z\u00e9ps\u0151 elem nagyobb, akkor a bal oldalra keres\u00fcnk tov\u00e1bb\n        elif list[mid] &gt; target:\n            right = mid - 1\n        \n        # Ha a k\u00f6z\u00e9ps\u0151 elem kisebb, akkor a jobb oldalra keres\u00fcnk tov\u00e1bb\n        else:\n            left = mid + 1\n            \n    # Ha nem tal\u00e1lhat\u00f3 az elem\n    return -1\n\nlist = [11, 34, 52, 76, 93, 110, 67, 47,98, 75]\ntarget = 52\n\nindex = binary_search(list, target)\nif index != -1:\n    print(f\"Az elem ({target}) megtal\u00e1lhat\u00f3 az {index} indexen.\")\nelse:\n    print(f\"Az elem ({target}) nem tal\u00e1lhat\u00f3 a list\u00e1ban.\")<\/pre>\n<p><code><\/code><\/p>\n<p>[\/et_pb_toggle][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>","protected":false},"excerpt":{"rendered":"<p>Bin\u00e1ris keres\u00e9si algoritmusA Binary Search az egyik leggyakrabban alkalmazott list\u00e1ban val\u00f3 keres\u00e9sre alkalmas algoritmus.A k\u00f3dja k\u00e9tszer lett lefuttatva, mint a k\u00e9pen l\u00e1tszik, van benne hibakezel\u00e9s, azaz az 52-es elemet megtal\u00e1lja a k\u00f3dban l\u00e9v\u0151 list\u00e1b\u00f3l, mint az a Visual Studio-ban k\u00e9sz\u00fclt k\u00f3dr\u00f3l k\u00e9sz\u00fclt k\u00e9p parancssor\u00e1ban l\u00e1tszik, a 61-es elemre pedig ki\u00edrja, hogy nem a lista r\u00e9sze, [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"class_list":["post-223","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/akosgombkoto.info\/en\/wp-json\/wp\/v2\/pages\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/akosgombkoto.info\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/akosgombkoto.info\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/akosgombkoto.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/akosgombkoto.info\/en\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":14,"href":"https:\/\/akosgombkoto.info\/en\/wp-json\/wp\/v2\/pages\/223\/revisions"}],"predecessor-version":[{"id":691,"href":"https:\/\/akosgombkoto.info\/en\/wp-json\/wp\/v2\/pages\/223\/revisions\/691"}],"wp:attachment":[{"href":"https:\/\/akosgombkoto.info\/en\/wp-json\/wp\/v2\/media?parent=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}