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

  Identifying the use cases of the system

Identifying the use cases of the system based on the narrative above, and giving a brief description for each of the use cases.

  Create a loop structure to display all integer values

Determine if the first number is larger than, smaller than, or equal to the second number.

  Question 1you are required to create a detailed analysis

question 1you are required to create a detailed analysis for each of the following array-based sorting algorithmsa

  Determine complete list of nodes which ancestor

Let the following tree: tree a. Determine the children of Q? b. What is the complete list of nodes which have D as ancestor? c. Determine the height of this tree (as height is defined in text)?

  Determine the branching factor

Expalin the search algorithm that results from each of the following special cases. How does it relate to other algorithms we have discussed.

  Explain queue crawl through memory in direction of its head

Does queue crawl through memory in direction of its head or its tail? Describe your answer. Describe how lack of metrics for measuring certain software properties affects software engineering discipline.

  Solving single source shortest paths problem

Here is a proposed algorithm to solve single source shortest paths problem in a weighted directed graph G with possibly negative edges weights.

  Draw a flowchart for the algorithm

Compute the final answer by rounding the last value to 4 decimal places type the computed value at the bottom of the list and Draw a flowchart for the algorithm below and have it checked by the TA

  Question about site structure

Browse the Web to discover examples of the following site structures Linear and Hierarchical and describe how the content fits the structure.

  Prepare a flowchart chart to print the largest number

Write a flow chart to print the largest of any three numbers - Prepare a flowchart chart to print the largest number.

  Modify algorithm to always select president of company

How would you modify your algorithm to always select the president of the company (regardless of his fun rating or the consequences on the overall amount of fun we can achieve)?

  Develop the pseudo code need

Develop the pseudo code needed to find the average of ten 8-bit numbers. Use a loop.

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