Example of binary search, Data Structure & Algorithms

Assignment Help:

Let us assume a file of 5 records that means n = 5

And k is a sorted array of keys of those 5 records.

1185_Example.png

Let key = 55, low = 0, high = 4

Iteration 1: mid = (0+4)/2 = 2 k(mid) = k (2) = 33

Now key > k (mid)

Thus low = mid + 1 = 3

Iteration 2: low = 3, high = 4 (low <= high)

Mid = 3+4 / 2 = 3.5 ~ 3 (integer value)

 Here key > k (mid)

Thus low = 3+1 = 4

Iteration 3: low = 4, high = 4 (low<= high)

Mid = (4+4)/2 = 4

Here key = k(mid)

Thus, the record is at mid+1 position that means 5


Related Discussions:- Example of binary search

Determine about the logic gates, Determine about the logic gates Many e...

Determine about the logic gates Many electronic circuits operate using binary logic gates. Logic gates essentially process signals that represent true or false or equivalent i.

Explain th term input and output- pseudocode, Explain th term input and ou...

Explain th term input and output-  Pseudocode Input and output indicated by the use of terms input number, print total, output total, print "result is" x and so on.

Perform inorder, QUESTION (a) Construct a binary tree for the following...

QUESTION (a) Construct a binary tree for the following numbers assuming that a number greater than the node (starting from the root) goes to the left else it goes to the right.

Define binary search technique, Binary search technique:-  This techniq...

Binary search technique:-  This technique is applied to an ordered list where elements are arranged either in ascending order or descending order. The array is separated into t

State an algorithm which inputs 3 - digit code for 280 items, A small shop ...

A small shop sells 280 different items. Every item is identified by a 3 - digit code. All items which start with a zero (0) are cards, all items which start with a one (1) are swee

Hashing and hash functions, Q. Describe the term hashing. Explain any two u...

Q. Describe the term hashing. Explain any two usually used hash functions. Explain one method of collision resolution.

Memory allocation strategies, Q. Explain the various memory allocation stra...

Q. Explain the various memory allocation strategies.                                                            Ans. M e m ory Allocation Strategies are given as follow

Present the algorithm of binary search. , B i n a ry Search Alg...

B i n a ry Search Algorithm is given as follows 1. if (low > high) 2.     return (-1) 3. mid = (low +high)/2; 4. if ( X = = a [mid]) 5.      return (mid); 6.

Perfect matching polytope ppm, Let G=(V,E) be a graph for which all nodes h...

Let G=(V,E) be a graph for which all nodes have degree 5 and where G is 5-edge is connected. a) Show that the vector x which is indexed by the edges E and for which xe = 1/5 for

Deletion of any element from the circular queue, Algorithm for deletion of ...

Algorithm for deletion of any element from the circular queue: Step-1: If queue is empty then say "queue is empty" & quit; else continue Step-2: Delete the "front" element

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