

 Thread Tools  Search this Thread 
#1
 
 
What is the binary search in data structure Hey friends, I wanted to what is the binary search in data structure. I don?t have any idea about data structure and binary search is in data structure section. I tried hard to study but it went above my head. Is it a type of sorting? Can anyone please let me know what the basic concept of searching in data structure is? If anyone having any information or knowledge then please let me know as soon as possible. 
#2
 
 
Re: What is the binary search in data structure This method is very fast and efficient. This method requires that the list of the elements be in sorted order. In this method to search an element we compare it with the element present at the center of the list. If it matches then the search is successful. Otherwise the list is divided into two halves. One from 0th element to the center element (first half) and another from center element to last element(second half).As a result all the element in the first half are smaller than the center element whereas all the element in the second half are greater than the center element. 
#3
 
 
Re: What is the binary search in data structure The searching will now proceed in either of the two halves depending upon whether the element is greater or smaller than the center element. If the element is smaller than the center element than the searching will be done in the first half, otherwise in second half. Same process of comparing the required element with the center element and if not found then dividing the element into two halves is repeated for the first half or second half. This process is repeated till the element is found or the division of half parts gives one element. 
#4
 
 
Re: What is the binary search in data structure Code: #include <stdio.h> #include <conio.h> void main( ) { int arr[10] = { 1, 2, 3, 9, 11, 13, 17, 25, 57, 90 } ; int mid, lower = 0 , upper = 9, num, flag = 1 ; clrscr( ) ; printf ( "Enter number to search: " ) ; scanf ( "%d", &num ) ; for ( mid = ( lower + upper ) / 2 ; lower <= upper ;mid = ( lower + upper ) / 2 ) { if ( arr[mid] == num ) { printf ( "The number is at position %d in the array.", mid ) ; flag = 0 ; break ; } if ( arr[mid] > num ) upper = mid  1 ; else lower = mid + 1 ; } if ( flag ) printf ( "Element is not present in the array." ) ; getch( ) ;} 

Tags: binary search, data structure, programming, sorting 
Thread Tools  Search this Thread 

Similar Threads for: "What is the binary search in data structure"  
Thread  Thread Starter  Forum  Replies  Last Post 
How to Upload Binary data using the API?  Martineau  Software Development  5  16062011 08:44 PM 
What is linear search in data structure?  Venugopala  Software Development  3  04012011 08:11 AM 
What is the difference between binary tree sort and heap sort in data structure  sRIPRIYA  Software Development  3  04012011 01:25 AM 
Transferring binary data through PHP  Welsh  Software Development  5  29012010 05:21 PM 
How binary data is passed to HTTP  Gannon  Software Development  4  29012010 04:37 PM 