{"id":6734,"date":"2021-09-30T15:30:38","date_gmt":"2021-09-30T10:00:38","guid":{"rendered":"https:\/\/python-programs.com\/?p=6734"},"modified":"2021-11-22T18:39:29","modified_gmt":"2021-11-22T13:09:29","slug":"binary-search-algorithm-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/binary-search-algorithm-in-python\/","title":{"rendered":"Binary Search Algorithm in Python"},"content":{"rendered":"

Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners<\/a> tutorial.<\/p>\n

Binary Search:<\/strong><\/p>\n

A binary search is an algorithm for finding a specific element in a list. Assume we have a list of a thousand elements and we need to find the index location of a specific element. Using the binary search algorithm, we can quickly determine the index location of an element.<\/p>\n

There are several search algorithms, but the binary search is the most widely used.<\/p>\n

To use the binary search algorithm, the elements in the list must be sorted. If the elements are not already sorted, sort them first.<\/p>\n

Examples:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given_elements =[2, 7, 3, 4, 9, 15]\u00a0 \u00a0key= 9<\/pre>\n

Output:<\/strong><\/p>\n

Element 9 is found at index 4<\/pre>\n

Binary Search Algorithm in Python<\/h2>\n