Binary search, Data Structure & Algorithms

Assignment Help:

An unsorted array is searched through linear search that scans the array elements one by one until the wanted element is found.

The cause for sorting an array is that we search the array "quickly". Now, if the array is sorted, we can use binary search, which greatly halves the size of the search space each time it study one array element.

An array-based binary search chooses the middle element in the array & compares its value to that of the key value. Since, the array is sorted; if the key value is less than the middle value then the key has to be in the first half of the array. Similarly, if the value of the key item is greater than that of the middle value within the array, then it is known that the key lies into second half of the array. In either case, in reality we can, "throw out" one half of search space or array along with only one comparison.

Now, knowing that the key has to be in one half of the array or the other, the binary search study the mid value of the half wherein the key has to reside. Thus, the algorithm narrows the search area by half at each step till it has either found the key data or the search fails.

As the name recommend, binary means two, so it split an array into two halves for searching. This search is applicable only onto an ordered table (in either ascending or in descending order).

Let us write down an algorithm for Binary Search & then we will discuss it. The array contains elements stored in ascending order.


Related Discussions:- Binary search

Complete trees, This is a k-ary position tree wherein all levels are filled...

This is a k-ary position tree wherein all levels are filled from left to right. There are a number of specialized trees. They are binary trees, AVL-trees, binary search trees, 2

Hash tables, Q. Explain the Hash Tables, Hash function and Hashing Techniqu...

Q. Explain the Hash Tables, Hash function and Hashing Techniques properly?             A n s . H as h Table is explained as follows : A hash table is a data struc

Threads in main method, Create main method or a test class that creates 2 E...

Create main method or a test class that creates 2 Element objects that are neighbours of each other, the first element temperature set at 100, the 2nd at 0 and use an appropriate h

Illustrate trivariate colour models, Illustrate Trivariate Colour Models ...

Illustrate Trivariate Colour Models Conventional colour models based on the tristimulus theory all contain three variables and so are called trivariate models. Let us now consi

Order of linear search, a. In worst case the order of linear search is O (n...

a. In worst case the order of linear search is O (n/2) b. Linear search is more competent than Binary search. c. For Binary search, the array must be sorted in ascending orde

State flowchart that take temperature input using pseudocode, Write an algo...

Write an algorithm using pseudocode which takes temperatures input over a 100 day period (once per day) and output the number of days when the temperature was below 20C and the num

Algorithm that counts number of nodes in a linked list, Q. Write an algorit...

Q. Write an algorithm that counts number of nodes in a linked list.                                       A n s . Algo rithm to Count No. of Nodes in Linked List C

Unification algorithm, i want to write code for unification algorithm with ...

i want to write code for unification algorithm with for pattern matching between two expression with out representing an expression as alist

Deletion of an element from the linked list, A LGORITHM (Deletion of an ele...

A LGORITHM (Deletion of an element from the linked list) Step 1  Begin Step 2  if the list is empty, then element cannot be deleted Step 3  else, if the element to be del

Reverse order of elements on a slack, Q. Describe the representations of gr...

Q. Describe the representations of graph. Represent the graph which is given to us using any two methods Ans: The different ways by which we can represent graphs are:

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