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

Persuasive communication , 1)   Discuss various types of persuasive communi...

1)   Discuss various types of persuasive communication you might be needed to write or present in your professional and personal life. 2)    Describe two ways to organize a resume

Mplement a second-order low-pass filter using the finite dif, you will impl...

you will implement a second-order low-pass filter using the finite difference method. The finite difference method is a useful mathematical method that is used to numerically solve

Inventor, I am the inventor of the railway signaling device now operated by...

I am the inventor of the railway signaling device now operated by timer. I wish to move on to the next phase where the equipment will be operated by DTMF codes. The device is a si

Important points of simulations, Important points of simulations In thi...

Important points of simulations In this simulation it is essential to consider: (1)  What and how data is gathered (2)  How simulation is done (3)  How system would wo

How can we convert infix expression to a postfix expression, One can change...

One can change an infix expression to a postfix expression using a By using Stack you can convert infix expression to a postfix expression

Distinguish between an agent system and an expert system, Problem : (a)...

Problem : (a) The concept of an agent is generally defined by listing the properties that agents exhibit. Identify and describe the properties that you would associate with th

Explain analysis and synthesis phase of a compiler, Explain analysis and sy...

Explain analysis and synthesis phase of a compiler. The synthesis and analysis phases of a compiler are: Analysis Phase: In this breaks the source program in constituent

History of information technology and organisations, History of Information...

History of Information Technology and Organisations The increasing sophistication in information systems and the growth in their use have been influenced by three main factors

Define the term electronic cheques in briefly, Define the term Electronic C...

Define the term Electronic Cheques in briefly. The other mechanism for Internet payment is electronic cheques. Along with electronic cheques, there payer (either a business or

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