Algorithm of binary search, Data Structure & Algorithms

Assignment Help:

Step 1: Declare array 'k' of size 'n' i.e. k(n) is an array which stores all the keys of a file containing 'n' records

Step 2: i←0

Step 3: low←0, high←n-1

Step 4: while (low <= high)do

mid = (low + high)/2

if (key=k[mid]) then

write "record is at position", mid+1   //as the array starts from the 0th position

else

if(key < k[mid]) then

 high = mid - 1

else

low = mid + 1

 endif

endif

endwhile

Step 5: Write "Sorry, key value not found"

Step 6: Stop


Related Discussions:- Algorithm of binary search

Areas of use - sequential files, Sequential files are most frequently utili...

Sequential files are most frequently utilized in commercial batch oriented data processing where there is the concept of a master file on which details are inserted periodically. F

Search on a heap file, Consider the file " search_2013 ". This is a text fi...

Consider the file " search_2013 ". This is a text file containingsearch key values; each entry is a particular ID (in the schema given above). You are tosimulate searching over a h

Lilz, I need to know about data structure and algorithms. can you help me?

I need to know about data structure and algorithms. can you help me?

State the ruby programming language, The Ruby Programming Language Alth...

The Ruby Programming Language Although data structures and algorithms we study aren't tied to any program or programming language, we need to write particular programs in speci

Sorting algorithm, Sorting Algorithm A sorting algorithm is an algorit...

Sorting Algorithm A sorting algorithm is an algorithm which puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Eff

Draw a flowchart to input start time and end time of vehicle, Speed cameras...

Speed cameras read the time a vehicle passes a point (A) on road and then reads time it passes a second point (B) on the same road (points A and B are 100 metres apart). Speed of t

Rotations in binary tree, H o w can you r ot a t e a B i n a r y...

H o w can you r ot a t e a B i n a r y Tr e e? E x pl a i n r i g h t a n d l eft r ot a tion s by taking an e x a mpl e.   If after

Relation of time and space complexities of an algorithm, What is complexity...

What is complexity of an algorithm? What is the basic relation between the time and space complexities of an algorithm? Justify your answer by giving an example.

If a node having two children is deleted from a binary tree, If a node havi...

If a node having two children is deleted from a binary tree, it is replaced by?? Inorder successor

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