Program for binary search, Data Structure & Algorithms

Assignment Help:

Illustrates the program for Binary Search.

Program: Binary Search

/*Header Files*/

#include

#include

/*Functions*/

void binary_search(int array[ ], int value, int size)

{

int found=0;

int low=0, high=size-1,  mid;

mid = (high+low)/2;

printf("\n\n Searching for %d\n", value);

while((!found)&&(high>=low))

{

printf("Low %d Mid%d High%d\n", low, mid, high);

if(value==array[mid] )

{

printf("Key value searched out at position %d",mid+1);

found=1;

}

else

{if (value

high = mid-1;

else

 low = mid+1;

mid = (high+low)/2;

}

}

if (found==1

printf("Search successful");

else

printf("Key value not found");

}

/*Main Function*/

void main(void)

{

int array[100], i;

/*Inputting Values to Array*/

for(i=0;i<100;i++)

{ printf("Enter the name:");

scanf("%d", array[i]);

}

printf("Result of search %d\n", binary_searchy(array,33,100));

printf("Result of search %d\n", binary_searchy(array, 75,100));

printf("Result of search %d\n", binary_searchy(array,1,100));

}


Related Discussions:- Program for binary search

Explain the bubble sort algorithm, Explain the bubble sort algorithm. ...

Explain the bubble sort algorithm. Answer This algorithm is used for sorting a list. It makes use of a temporary variable for swapping. It compares two numbers at an insta

Total weight of minimum spanning tree, a) Run your program for α = 0.05, 0...

a) Run your program for α = 0.05, 0.5, and 0.95. You can use n = 30, and W = 10. What is impact of increasing value of α on connectivity of G'? To answer this question, for each v

Write a program to create a heap file, Write a program to create a heap fil...

Write a program to create a heap file that holds the records in the file " data_2013 " The source records are variablelength.However, the heap file should hold fixed-length reco

Algorithm for multiplication of two sparse matrices using li, algorithm for...

algorithm for multiplication of two sparse matrices using linked lists..

Explain the rgb model, RGB Model The RGB model is based on the assumpti...

RGB Model The RGB model is based on the assumption that any desired shade of colour can be obtained by mixing the correct amounts of red, green, and blue light. The exact hues

Acyclic graph, Tree is a widely used data structure employed for representi...

Tree is a widely used data structure employed for representing several problems. We studied tree like a special case of acyclic graph. Though, rooted trees are most prominent of al

Amortized algorithm analysis, In the amortized analysis, the time needed to...

In the amortized analysis, the time needed to perform a set of operations is the average of all operations performed. Amortized analysis considers as a long sequence of operations

Row major storage, Q. Take an array A[20, 10] of your own. Suppose 4 words ...

Q. Take an array A[20, 10] of your own. Suppose 4 words per memory cell and the base address of array A is 100. Find the address of A[11, 5] supposed row major storage.

Surrounding of sub division method, Surrounding of sub division method ...

Surrounding of sub division method A polygon surrounds a viewport if it completely encloses or covers the viewport. This happens if none of its sides cuts any edge of the viewp

Algorithms & flowchart, write an algorithm to find the average number of oc...

write an algorithm to find the average number of occurances of MECHANIL in an english passage

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