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

List various problem solving techniques, List various problem solving techn...

List various problem solving techniques. There are two techniques:- 1.  Top down 2.  Bottom- up

What are expression trees, What are expression trees?  The leaves of an...

What are expression trees?  The leaves of an expression tree are operands, like as constants or variable names, and the other nodes have operators. This certain tree happens to

Which is the most suitable data type, Problem 1. You are asked to store...

Problem 1. You are asked to store Names of all 100 students of class A in your Learning Centre. Which data type will you use? What is its syntax? Explaining the data typ

Structured programming, What do you understand by term structured programmi...

What do you understand by term structured programming? Explain the structured programming as well.                                 Ans. S tructured Programming is expla

Enumerate about the carrier set members, Enumerate about the carrier set me...

Enumerate about the carrier set members Ruby is written in C, so carrier set members (which is, individual symbols) are implemented as fixed-size arrays of characters (which is

File organization, Define File organization''s and it''s types

Define File organization''s and it''s types

The complexity of searching an element, The complexity of searching an elem...

The complexity of searching an element from a set of n elements using Binary search algorithm is   O(log n)

Abstract Data Types, A useful tool which is used for specifying the logical...

A useful tool which is used for specifying the logical properties of a data type is called the abstract data type or ADT. The term "abstract data type" refers to the fundamental ma

Create a function to show data structure, Given a number that is represente...

Given a number that is represented in your data structure, you will need a function that prints it out in base 215 in such a way that its contents can be checked for correctness. Y

Discuss the properties of adt, Question 1 Write a program in 'C' to rea...

Question 1 Write a program in 'C' to read N numbers and print them in descending order Question 2 Discuss the properties of ADT Question 3 Write a note on

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