subject
Computers and Technology, 16.10.2020 17:01 minaale

You have a large text file of people. Each person is represented by one line in the text file. The line starts with their ID number and after that, has the person's name. The lines are sorted by ID number in ascending order. There are n lines in this file. You write a search function that returns the name of a person whose ID number is given The simplest way to do that would be to program a loop that goes through each line and compares the ID number in the line against the given ID number. If there is a match, then it returns the name in that line. This is very inefficient, because the worst-case scenario is that this program needs to go through almost everyone the person we are looking for could be last. using the fact that he tli s sored wil greany speed up the processbus to use a birarysearch alkrhm We go to the middle line of the file first and compare the ID found there (P) to the given ID (Q). (f the number of lines is even, we go above or below the arithmetic middle.) if P=Q then our algorithm terminates . we have found the person we are looking for. If P is less than Q, that means that the person we are looking for is in the second half of the file. We now repeat our algorithm on the second half of the file. If P is greater than Q, that means that the person we are looking for is in the first half of the file. We now repeat our algorithm on the first half of the file. Required:
Of what order is the worst-case number of comparison operations that needed for this algorithm to terminate?

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 23:30
Show that there is a language a ⚆ {0, 1} â— with the following properties: 1. for all x â a, |x| ≤ 5. 2. no dfa with fewer than 9 states recognizes a. hint: you don’t have to define a explicitly; just show that it has to exist. count the number of languages satisfying (1) and the number of dfas satisfying (2), and argue that there aren’t enough dfas to recognize all those languages. to count the number of languages satisfying (1), think about writing down all the strings of length at most 5, and then to define such a language, you have to make a binary decision for each string about whether to include it in the language or not. how many ways are there to make these choices? to count the number of dfas satisfying (2), consider that a dfa behaves identically even if you rename all the states, so you can assume without loss of generality that any dfa with k states has the state set {q1, q2, . . , qk}. now think about how to count how many ways there are to choose the other four parts of the dfa.
Answers: 3
question
Computers and Technology, 22.06.2019 19:30
When creating a presentation in libre office impress, where does the editing of slides take place?
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
How to do this programming flowchart?
Answers: 3
question
Computers and Technology, 24.06.2019 21:50
The use of phrases, fragments, and punctuation can influence the mood of a passage; keeping this in mind, how would you describe the mood of the followingpassage? "fog on the essex marshes, fog on the kentish heights, fog creeping into the cabooses of collier-brigs; fog lying out on the yards, and hovering in the riggingof great ships; fog drooping on the gunwales of barges and small boats. fog in the eyes and throats of ancient greenwich pensioners, wheezing by thefiresides of their wards; fog in the stem and bowl of the afternoon pipe of the wrathful skipper; fog cruelly pinching the toes and fingers of his shivering little'prentice boy on deck." (5 points)
Answers: 2
You know the right answer?
You have a large text file of people. Each person is represented by one line in the text file. The l...
Questions
question
Social Studies, 27.09.2019 14:30
question
English, 27.09.2019 14:30
Questions on the website: 13722363