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

  Hubspot: inbound marketing and web 2.0

Hubspot: Inbound Marketing and Web 2.0

  Applications in involve computing various powers of e

The transcendental number, e. Many applications in mathematics involve computing various powers of e. It can be proven that ex = 1 + x/1 + x2/2! + x3/3! + ... for all values of x. Of course, this is an infinite sum.

  Write program using getline command

How would you write a program using the getline command, prompting the user to enter their first and then their last name. Also, using a float variable to enter their weight in lbs and height in inches.

  C program to accept three numbers inputs by user

Write down C program to accept three numbers input by a user, and outputs a table of temperatures in Fahrenheit, Celsius, and Kelvin.

  Program to compute risk of weight-related health problems

A quantity known as the body mass (BMI) is used to calculate the risk of weight-related health problems. Write a program that accepts weight and height and then displays the BMI value and Status.

  Creating table-find employee attended meeting on given date

The rows of this table record the fact that an employee from a particular project attended a meeting on the given date.

  Write application to input numbers in one dimensional array

Use a one dimensional array to solve the following problem: Write an application that inputs five numbers, each between 10 and 100, inclusive.

  Computing average net profit per sale of product

Your company bought 250,000 online advertising impressions and made average net profit per sale of product of $5.

  Write program asks user to enter temperature

Write a program that asks the user to enter a temperature, and then shows all the substances that will freeze at that temperature and all the substances that will boil at that temperature.

  Writing class containing two instance variables

Write class named ParkingMeter containing: two instance variables named timeLeft and maxTime of type int. Value of timeLeft must be initialized to 0.

  Draw a erd model a manufacturing company

Draw a ERD model A manufacturing company has several assembly plants in different cities. Each plant produces one product which requires certain parts in its assembly.

  Write a vhdl code for soda vending machine

Write a VHDL code that implements the above soda machine. You have to turn in the following: A state diagram showing the implementation of your design. Clearly show all the states and the conditions on which transitions occur.

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