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

Database design and sql queries, In assignment, you have already started th...

In assignment, you have already started the process of designing a database for the Beauty Salon mini-case (enclosed again below), mainly in the phase of conceptual database design

Arrays, Data array A has data series from 1,000,000 to 1 with step size 1, ...

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

Algorithm, write an algorithm for the gpa of six students

write an algorithm for the gpa of six students

Data flow diagrams, How to construct a data flow diagram for a college assi...

How to construct a data flow diagram for a college assignment and marking systemA

Computer arhitecture, The controversy of RISC versus CISC never ends. Suppo...

The controversy of RISC versus CISC never ends. Suppose that you represent an advocate for the RISC approach; write at least a one-page critic of the CISC approach showing its disa

Difference in grounded header and circular header Link List, Q. State the d...

Q. State the difference between a grounded header link list and a circular header link list?     Ans: A header linked list is a linked list which all the time c

Algorithm for insertion into the circular queue, Algorithm for insertion of...

Algorithm for insertion of any element into the circular queue: Step-1: If "rear" of the queue is pointing at the last position then go to step-2 or else Step-3 Step-2: make

Procedure of analysis of algorithm, Example 1:  Following are Simple sequen...

Example 1:  Following are Simple sequence of statements Statement 1;  Statement 2; ... ... Statement k; The entire time can be found out through adding the times for

Binary search tree (bst), Q. Explain what do we understand by Binary Search...

Q. Explain what do we understand by Binary Search Tree (BST)? Make a BST for the following given sequence of the numbers. 45, 32, 90, 21, 78, 65, 87, 132, 90, 96, 41, 74, 92

Optimization Methods, Optimal solution to the problem given below. Obtain t...

Optimal solution to the problem given below. Obtain the initial solution by VAM Ware houses Stores Availibility I II III IV A 5 1 3 3 34 B 3 3 5 4 15 C 6 4 4 3 12 D 4 –1 4 2 19 Re

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