Search a sorted array of floating point numbers

Assignment Help Data Structure & Algorithms
Reference no: EM13707323

Program: You need to write a program which uses binary search to search a sorted array of floating point numbers.

Part 1: - Create an array of doubles, using the following statement. Notice that the array is sorted.

Part 2: - array: .double 4.5 8.1 9.9 12.0 20.2 45.5 53.35 67.75 75.4 99.9 115.0 121.5

Part 3: Create a loop which will prompt the user to enter a double and then perform binary search to check whether the double is in your array and print a message.

Continue prompting and searching until the user enters a negative number.

Part 4:- For binary search, use the iterative algorithm shown below. This searches your array for the input value key, using your array, and initializing imin to 0 (subscript of first element), imax to 11 (subscript of last element),

 found = false; // continue searching while A[imin] to A[imax] is not empty while (imax >= imin && !found) { // calculate the midpoint for roughly equal partition int imid = (imin + imax) / 2; if(A[imid] == key) { // key found at index imid print message: key " found in location" imid; found = true; } // determine which subarray to search else if (A[imid] < key) // change min index to search upper subarray imin = imid + 1; else // change max index to search lower subarray imax = imid - 1; } // key was not found print message: key " not found";

You have to implement a binary search to search a sorted array of floating point numbers.

Reference no: EM13707323

Questions Cloud

Explain at least three scenarios where he is wrong : Explain at least three scenarios where he is wrong, that is, where users other than a file's owner need some kind of allowed access privileges
How does the choice affect the user of the class : Write a partial C++ class definition not implementation that contains the public interface of the Date class described in Exercise R9.2.
Python programming to solve this problem : Write a statement that adds 1 to deansList and prints studentName to standard out if gpa exceeds 3.5.
Sum of the elements of the arithmetic progression : An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same.
Search a sorted array of floating point numbers : You need to write a program which uses binary search to search a sorted array of floating point numbers - Create an array of doubles, using the following statement. Notice that the array is sorted.
Prepare a assembly program to initialize the led outputs : Write a main.asm file in PSoC designer. Make sure to have the subsequent in place - Initialize the LED outputs to 0's and Set the corresponding bit in INT_MSK0 to 1.
Prepare a function that generates a polynomial : Write a function genPoly(n) that generates a polynomial of length n (degree n-1), all of whose coefficients are 1.0.
Identify one reason indexes are useful : Describe what you would have to do if indexes weren't available in order to get the reason you initially stated and how the query optimizer generates and selects a query plan.
How long should a system be idle to benefit from hibernating : If reading or writing a cache-line of size 64 bytes to Flash requires 2.56 ?J and DRAM requires 0.5 nJ, and if idle power consumption for DRAM is 1.6 W (for 8 GB), how long should a system be idle to benefit from hibernating? Suppose a main memory..

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Modify the pseudocode design

Modify the pseudocode design

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Database over electronic files to store data

Discuss the benefits of a database over electronic files to store data determine what kinds of database products are used in your company?

  Decrypting the ciphertext to recover the plaintext

If you get ciphertext message YPHDCRPBEQTAA, decrypt to recover plaintext.

  System analystis you are required to analyse the

you are required to analyse the effectiveness of the qantas online air ticketing system. to do this you are required to

  Algorithm on dynamic programming-minimize amount of walking

Our goal is to plan this trip so that we minimize the maximum amount of walking done in a single day. Your algorithm should be based on dynamic programming and run efficiently.

  Evaluate algebraic expression by code with three-operand

Evaluate a short algebraic expression using code with three-operand instructions. The expression should have a minimum of three operands and 2 operators.

  Chinese remainder theory

For RSA signature, let p=17 and q=43. Design a digital signature for the message m=161, where the hashing function is the identity function and the computation at the signer's side is performed through the Chinese Remainder Theory.

  Algoithm to select to describe intrinsically recursive

Algoithms you select so you can describe and assess them. Write challenges did you face in process? How did you go about resolving them?

  Create algorithm to prepare daily hotel charge report

Create the algorithm to prepare the daily hotel charge report. Input consists of series of records which contain a room number, customer name, cost of the room, and cost of meals charged to the room.

  1 what are the different applications of data structure2

1. what are the different applications of data structure?2. what are the basic limitations of linear array?3.

  Write code to implement the expression

Write code to implement the expression: A= (B+C) * (D+E) on 3-, 2-, 1- and 0- address machines. In accordance with programming language practice, computing the expression should not change the values of its operands. Show all instructions.

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