Re: bsearch in C

Discussion in 'C Programming' started by Richard Heathfield, Aug 7, 2003.

  1. Edward A Thompson wrote:

    > Is there any common knowledge out there about what the threshold for
    > bsearch (stdlib.h) performing better than a sequential search of an
    > array? If I have an array of 600 structure vs 6000?


    Suck it and see.

    Common sense may help, though. We expect bsearch to be O(log n), and linear
    search to be O(n). If n is, say, 100, we would expect linear search to find
    the position of a random item (known to be present) in an average of 50
    tries, but binary search to find it in a mere 6 to 7 tries.

    --
    Richard Heathfield :
    "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    K&R answers, C books, etc: http://users.powernet.co.uk/eton
     
    Richard Heathfield, Aug 7, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Artie Gold

    Re: bsearch in C

    Artie Gold, Aug 7, 2003, in forum: C Programming
    Replies:
    0
    Views:
    410
    Artie Gold
    Aug 7, 2003
  2. Eric Sosman

    Re: bsearch in C

    Eric Sosman, Aug 7, 2003, in forum: C Programming
    Replies:
    9
    Views:
    518
    Richard Heathfield
    Aug 12, 2003
  3. Ramprasad A Padmanabhan

    a small bsearch example

    Ramprasad A Padmanabhan, Oct 28, 2003, in forum: C Programming
    Replies:
    1
    Views:
    3,794
    Mark Gordon
    Oct 28, 2003
  4. Ramprasad A Padmanabhan

    bsearch script segfault

    Ramprasad A Padmanabhan, Dec 4, 2003, in forum: C Programming
    Replies:
    11
    Views:
    500
    Ramprasad A Padmanabhan
    Dec 5, 2003
  5. Angus Comber

    Struggling with bsearch - on a struct!

    Angus Comber, Feb 5, 2004, in forum: C Programming
    Replies:
    4
    Views:
    356
    Al Bowers
    Feb 6, 2004
Loading...

Share This Page