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

List various problem solving techniques, List various problem solving techn...

List various problem solving techniques. There are two techniques:- 1.  Top down 2.  Bottom- up

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

Calculus, basic calculation for algorith.

basic calculation for algorith.

Explain the stack, QUESTION Explain the following data structures: ...

QUESTION Explain the following data structures: (a) List (b) Stack (c) Queues Note : your explanation should consist of the definition, operations and examples.

Minimum cost spanning trees, A spanning tree of any graph is only a subgrap...

A spanning tree of any graph is only a subgraph that keeps all the vertices and is a tree (having no cycle). A graph might have many spanning trees. Figure: A Graph

Algorithm to sort a given list by quick sort method, Q. Write down an algor...

Q. Write down an algorithm to sort a given list by making use of Quick sort method. Describe the behaviour of Quick sort when input given to us is already sorted.

Define about the inheritance hierarchy, Define about the inheritance hierar...

Define about the inheritance hierarchy Languages Eiffel and D provide constructs in language for invariants and pre- and post conditions which are compiled into the code and ar

How many nodes in a tree have no ancestor, How many nodes in a tree have no...

How many nodes in a tree have no ancestors 1 node in atree have no ancestors.

Asymptotic notation.., important points on asymptotic notation to remember

important points on asymptotic notation to remember

Creation of a circular linked list, Program: Creation of a Circular linked ...

Program: Creation of a Circular linked list ALGORITHM (Insertion of an element into a Circular Linked List) Step 1        Begin Step 2      if the list is empty or new

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