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

Binary tree and binarytree parts, Q. What do you understand by the term Bin...

Q. What do you understand by the term Binary Tree? What is the maximum number of nodes which are possible in a Binary Tree of depth d. Explain the terms given below with respect to

Data communication, #question.explain different types of errors in data tra...

#question.explain different types of errors in data transmission.

Programs, Develop a program that accepts the car registration( hint: LEA 43...

Develop a program that accepts the car registration( hint: LEA 43242010)

Linked lists, what are grounded header linked lists?

what are grounded header linked lists?

Small program on Algorithms , Objective The goal of this project is to ext...

Objective The goal of this project is to extend and implement an algorithm presented in the course and to apply notions introduced by the course to this program/algorithm. The ass

Array, extra key inserted at end of array is called

extra key inserted at end of array is called

Depth-first search (dfs) , In this respect depth-first search (DFS) is the...

In this respect depth-first search (DFS) is the exact reverse process: whenever it sends a new node, it immediately continues to extend from it. It sends back to previously explore

Graph, Multilist Representation of graph

Multilist Representation of graph

Matrix stored in memory, Method to measure address of any element of a matr...

Method to measure address of any element of a matrix stored in memory. Let us consider 2 dimensional array a of size m*n further consider that the lower bound for the row index

General Tree, How to create an General Tree and how to search general tree?...

How to create an General Tree and how to search general tree?

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