Write a Python function that implements binary search. The function takes two parameters – a file name and the value it is searching for. Your function should read in this file and similarly formatted files. Assume that the input file, such as data.txt, is sorted. Your code should return two values: (1) the number of comparisons performed to find/not find the value and (2) the index position of the value (or -1 if it is not found). Please comment on code so I can better understand. Try not to use any online sources because l've probably already looked at them and I want further understanding, if so please link them so I know if l've already searched through that example.
Write a Python function that implements binary search. The function takes two parameters – a file name and the value it is searching for. Your function should read in this file and similarly formatted files. Assume that the input file, such as data.txt, is sorted. Your code should return two values: (1) the number of comparisons performed to find/not find the value and (2) the index position of the value (or -1 if it is not found). Please comment on code so I can better understand. Try not to use any online sources because l've probably already looked at them and I want further understanding, if so please link them so I know if l've already searched through that example.
Chapter3: Data Representation
Section: Chapter Questions
Problem 12VE
Related questions
Question
Thank you, make up a file if need be of sorted data
![Write a Python function that implements binary search. The function takes two parameters – a
file name and the value it is searching for. Your function should read in this file and similarly
formatted files. Assume that the input file, such as data.txt, is sorted. Your code should return
two values: (1) the number of comparisons performed to find/not find the value and (2) the
index position of the value (or -1 if it is not found). Please comment on code so I can better
understand. Try not to use any online sources because l've probably already looked at them
and I want further understanding, if so please link them so I know if l've already searched
through that example.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9b46879e-b35c-4e4b-9252-3c9a6d509171%2F46af20ec-39b3-4a07-b5d0-d4ac32ab3639%2F6isw5mm.png&w=3840&q=75)
Transcribed Image Text:Write a Python function that implements binary search. The function takes two parameters – a
file name and the value it is searching for. Your function should read in this file and similarly
formatted files. Assume that the input file, such as data.txt, is sorted. Your code should return
two values: (1) the number of comparisons performed to find/not find the value and (2) the
index position of the value (or -1 if it is not found). Please comment on code so I can better
understand. Try not to use any online sources because l've probably already looked at them
and I want further understanding, if so please link them so I know if l've already searched
through that example.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning