Back to Browse

Binary Search in Python: Find Closest Number

19.3K views
Jul 11, 2018
22:49

In this video, we will be given a sorted array and a target number. Our goal is to find a number in the array that is closest to the target number. We will be making use of binary search to solve this problem. The array may contain duplicate values and negative numbers. Example 1: Input : arr[] = {1, 2, 4, 5, 6, 6, 8, 9} Target number = 11 Output : 9 9 is closest to 11 in given array Example 2: Input :arr[] = {2, 5, 6, 7, 8, 8, 9}; Target number = 4 Output : 5 This video is one part of the Binary Search playlist on my channel. For more videos on binary search and how to apply it to various problems, check out the other videos: https://www.youtube.com/playlist?list=PL5tcWHG-UPH1kjiE-Fqt1xCSkcwyfn2Jb The software written in this video is available at: https://github.com/vprusso/youtube_tutorials/blob/master/algorithms/search_algorithms/binary_search/find_closest_number.py Do you like the development environment I'm using in this video? It's a customized version of vim that's enhanced for Python development. If you want to see how I set up my vim, I have a series on this here: http://bit.ly/lp_vim If you've found this video helpful and want to stay up-to-date with the latest videos posted on this channel, please subscribe: http://bit.ly/lp_subscribe

Download

1 formats

Video Formats

360pmp430.5 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Binary Search in Python: Find Closest Number | NatokHD