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

Explain passing parameters using pointers, Q. Explain Passing Parameters Us...

Q. Explain Passing Parameters Using Pointers ? This method overcomes the drawback of using variable names directly in procedure. It uses registers to pass procedure pointers to

Explain about the object identity of object oriented, Explain about the Obj...

Explain about the Object Identity of object oriented analysis Object identity is a feature of an object that differentiates the objects from all other objects in the applicati

EME, How can i made Carnot engine

How can i made Carnot engine

Determine about the verilog task, Determine about the Verilog Task - Ta...

Determine about the Verilog Task - Tasks are capable of enabling a function as well as enabling other versions of a Task. - Tasks also run with a zero simulation however the

In 8085 which is called as high order / low order register, Flag is known a...

Flag is known as Low order register & Accumulator is known as High order Register.

Explain token ring, Explain Token Ring. Token Ring: A token ring is ...

Explain Token Ring. Token Ring: A token ring is a collection of single point -to-point links, which arise from a circle. In a token ring a special bi t pattern, termed as th

Multiple valued logics, Multiple valued logics: Multiple valued logics...

Multiple valued logics: Multiple valued logics, where altered types of truth value such as "unknown" are may be allowed. These have some of the particular advantages of fuzzy

Acting rationally - artificial intelligence, Acting Rationally: "Al" C...

Acting Rationally: "Al" Capone was finally convicted for tax evasion. Were the police reacting on rationally?? To solve this puzzle, we must first look at how the performance

Syntax and semantics - first-order logic, Syntax and Semantics: Propos...

Syntax and Semantics: Propositional logic is prohibited in its expressiveness: so just to represent true and false facts for the world. By a type of extending propositional lo

Explain what is a macro and why is it important, Question 1: Spreadshee...

Question 1: Spreadsheet packages are widely used in Business. a) Explain why spreadsheets are so useful. b) Spreadsheet files are sometimes saved for use by other software p

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