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

Are there standards for electronic imaging, Are there standards for electro...

Are there standards for electronic imaging? Given the sensitive nature of most permanent records, there are microphotography standards in place which contain microfilm, compute

Name the approaches used for generating the control signals, What are the t...

What are the two approaches used for generating the control signals in proper sequence? Hardwired control Micro programmed control

Elaborate the memory devices - semiconductor memory, Elaborate the memory ...

Elaborate the memory devices  - Semiconductor memory All of the memory used as main store in a modern computer is applied as semiconductors fabricated on wafers of silicon. Sem

What are language processor development tools, What are Language Processor ...

What are Language Processor Development Tools (LPDTs)? LPDT that is Language processor development tools focuses upon generation of the analysis phase of language processors. T

Answering systems- database query, Answering Systems / Database Query T...

Answering Systems / Database Query There are a large number of opportunities for get faster through parallelizing a Database Management System (DBMS). However, the actual purpo

Adder substractor, how can we bimpliment half substractor using nand gate

how can we bimpliment half substractor using nand gate

How many bits must be decoded for 128 × 8 ram chips, How many bits must be ...

How many bits must be decoded for chip select? What is the size of decoder when 128 × 8 RAM chips are required to provide a memory capacity of 2048 bytes? Ans. All higher order l

Design issues related to interrupt-driven input - output, Q. Design issues ...

Q. Design issues related to interrupt-driven Input - output? So interrupt handling includes interruption of currently executing program, execution of interrupt servicing progra

Explain increments and skips subsequent instruction, Q. Explain Increments ...

Q. Explain Increments and skips subsequent instruction? Increments A and skips subsequent instruction if the content of A has become 0. This is a complex instruction then requi

What is multiprogramming, What is multiprogramming or multitasking? The...

What is multiprogramming or multitasking? The operating system manages the concurrent implementation of several application programs to make the best possible uses of computer

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