Results 1 to 4 of 4

Thread: What is the binary search in data structure

  1. #1
    Join Date
    Mar 2010
    Posts
    393

    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. #2
    Join Date
    May 2009
    Posts
    511

    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. #3
    Join Date
    Apr 2009
    Posts
    488

    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. #4
    Join Date
    May 2009
    Posts
    527

    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( ) ;}
    This is the perfect example of binary search in data structure. The above program is written in C programming language. It is showed in the program that how the array is declared and then how it is stored and finally searched with binary search. I think that when you refer this program and execute it you will definitely came to know the concept of binary search.

Similar Threads

  1. How to Upload Binary data using the API?
    By Martineau in forum Software Development
    Replies: 5
    Last Post: 16-06-2011, 08:44 PM
  2. What is linear search in data structure?
    By Venugopala in forum Software Development
    Replies: 3
    Last Post: 04-01-2011, 08:11 AM
  3. Replies: 3
    Last Post: 04-01-2011, 01:25 AM
  4. Transferring binary data through PHP
    By Welsh in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 05:21 PM
  5. How binary data is passed to HTTP
    By Gannon in forum Software Development
    Replies: 4
    Last Post: 29-01-2010, 04:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,019,531.41396 seconds with 16 queries