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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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