Recursive binary search, Computer Engineering

Assignment Help:

The implementation of a (non-recursive) binary search of an array. The assumption is that a given array is sorted. We want to see if a particular value, that we'll call the target value, is in that array and, if so, where. In a binary search one checks the value in the middle of the array, i.e., if there are N elements in the array, one checks if the element with index (int)N/2 matches the target. (Note that if there are an even number of elements in the array, there is no true mid-point. The element with an index of (int)N/2 has one more element "below" it than it does "above" it.) If the value in the middle of the array is less than the target, then the function searches the portion of the array that is above the current middle, i.e., the new array to be searched starts with the element above the current middle and there are N - (int)N/2 - 1 elements in that. If the value in the middle of the array is greater than the target, then the function searches the portion of the array that is below the current middle. In this case the new array to be search starts where the original array started but now it is considered to have N - (int)N/2 elements. When the function is given an array of one element and if there is no match, the function returns NULL. (Or, if there is nothing left to search, e.g., there are no more elements "above" the current mid-point of a two-element array, the function returns NULL.) If there is a match, the function returns the address of the element that matches the target. Write a function called bin search() that takes three arguments: an integer pointer, the number of elements, and the value to be searched for (the target value). As indicated above, if the target is found in the array, the function returns the address (i.e,. an integer pointer) where the target was found. If the value is not found, it returns NULL.


Related Discussions:- Recursive binary search

State the number of definitions of firewall, State the number of definition...

State the number of definitions of firewall Though there exist a number of definitions of firewall, in simplest terms it can be defined as "a mechanism used to protect a truste

Design goals of computer system, Design goals: The correct form of a c...

Design goals: The correct form of a computer system depends on the constraints and aim for which it was optimized. Computer architectures frequently trade off   cost, standard

Explain the benefits of interpreter, Explain the Benefits of Interpreter? ...

Explain the Benefits of Interpreter? The benefit of an interpreter though is that it doesn't need to go through the compilation stage during which machine instructions are gene

Explain about communication displays and matrix, Q. What is communication D...

Q. What is communication Displays and Matrix? Communication Displays Communication displays offer support in concluding frequency of communication whether congestion in me

Solve out linear equations, Assume that you have been asked to solve proble...

Assume that you have been asked to solve problem with exact area constraints, the area error being no more than 1% for each department. What are the linear equations you would nee

Project, the project database is avilable?

the project database is avilable?

What is status control and registers, Q. What is Status Control and Registe...

Q. What is Status Control and Registers? Status Control and Registers: These registers can't be used by programmers though are used to control CPU or execution of a program.

Write short note on quantization, Write short note on Quantization. Qua...

Write short note on Quantization. Quantization: This is the first step in PCM. The whole amplitude range of the modulating signal is divided in a number of standard levels term

What is programming paradigm, a. Explain the Programming Paradigm? Discuss ...

a. Explain the Programming Paradigm? Discuss four major programming paradigms. b. State the three basic logic operators available in C++? Write a small program in C++ that uses

What is data link layer, Q. What is Data link layer? Data link layer: ...

Q. What is Data link layer? Data link layer: data link layer is responsible for transmitting a group of bits between adjacent nodes. Group of bits is termed as frame. Network

Write Your Message!

Captcha
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