Binary search algorithm to search an array

Assignment Help Programming Languages
Reference no: EM1367198

1. The binary search algorithm that follows may be used to search an array when the elements are in order. This algorithm is analogous to the following approach for finding a name in a telephone book.

a. open the book in the middle, and look at the middle name on the page.
b. If the middle name isn't the one you're looking for, decide whether it comes before or after the name you want.
c. Take the appropriate half of the section of the book you were looking in and repeat these steps until you land on the name.
Algorithm for Binary Search
1. Let bottom be the subscript of the initial array element.
2. Let top be the subscript of the last array element.
3. Repeat as long as bottom isn't greater than top and target has not been found
4. Let middle be the subscript of the element halfway between bottom and top.
5. if the element at middle is target
6. Return middle as the position of the target.
else if the element at middle is larger than the target
8. Let top be middle-1
else
9. Let bottom be middle+1

Reference no: EM1367198

Questions Cloud

Implication of demand of law : Your are the chief economic advisor to the King of Terra. The king has observed that while the price of energy has increased 20 percent over the past five years, consumers have actually increased their energy consumption by 10 percent over the sam..
Illustrate cost of good x to drive it to equilibrium : Find out QD and QS when cost of good X is $12.00. Is re a surplus or shortage. Illustrate what should happen to cost of Good X to drive it to Equilibrium.
Flexible exchange rate system : Suppose that expectation of reducing housing values cause households to decrease their demand for new houses and the financing that accompanies it.
Developmental-care deficit : Why do these examples meet the DSCR or provide evidence that there is a developmental-care deficit?
Binary search algorithm to search an array : The binary search algorithm that follows may be used to search array when elements are in order. This algorithm is analogous to following approach for finding name in telephone book.
Effect of increase in demand-supply on equilibrium : Show the impact on the equilibrium price and quantity that results from; (1) an increase in demand and (2) an increase in supply.
Health maintenance organizations : Acute care hospitals and health maintenance organizations are increasing the number of community health education programs they provide.
Explain why companies get better results-information system : Using three components of information systems and complementary assets concepts, explain why some companies achieve better results with information systems than others.
Determine the real risk-free interest rate : The central bank reduce the discount to rise the nation's monetary base. The nation has highly mobile international capital markets and a fixed exchange rate system.

Reviews

Write a Review

Programming Languages Questions & Answers

  Ethics and social responsibility

Ethics and social responsibility at McDonalds

  Write program to clear the screen and locate the cursor

Write a program that clears the screen, locates the cursor near the middle of the screen, prompts the user for two integers, adds the integers.

  Design and implement set of classes to model employees

Design and implement a set of classes to model the employees of a hospital: doctor, nurse, administrator, etc. Include methods in each class.

  Explaining box properties available in css

Browse the Web and choose a site that could benefit from box properties available in CSS. Make a screen capture of the page and indicate how you would change border and spacing properties.

  What is the throughput of the system

what is the throughput of the system

  Write program to choose female student-completed more course

Suppose that input consists of a student file. You are told to write a program to select female students who have completed more than two courses.

  Computing first seven values of fibonacci number sequence

Write a program that uses a loop to compute the first seven values of the Fibonacci number sequence.

  Pseudocode for a program to solve mathematical problem

Pseudocode for a program to solve the following problem. A student borrows $3,000 at an interest rate 2% per month on the unpaid balance.

  Create a multi-threaded competition

Create a multi-threaded competition

  Php code to add-delete product using ajax programming

PHP Code to add a new product and delete a existing product Implement AJAX Programming based solutions to write code to add a new product to the database.

  Write function to take the name of file as one parameter

Write a function named paragraphStats() that takes one parameter:the name of a file. The file contains a single line of text.

  Program for class quiz to implement measurable interface

State a class Quiz to implement Measurable interface. A quiz has a score and a letter grade (such as B+).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd