How to find data in database ?

This is a discussion on How to find data in database ? within the C++ Programming forums, part of the General Programming Boards category; If I have 400,000 sorted number in database like this 023F460B70F41323DBD1D2B49C 02C433C23F22D4498AFDCB9802 02E2C880757F813D0A0C067439 037502424D9A07383A1E6B73B1 ..... ..... ..... ..... A5183AA10FAC1DCCD581254A4 A6A7646433330474835DBAFE5 ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    How to find data in database ?

    If I have 400,000 sorted number in database like this

    023F460B70F41323DBD1D2B49C
    02C433C23F22D4498AFDCB9802
    02E2C880757F813D0A0C067439
    037502424D9A07383A1E6B73B1
    .....
    .....
    .....
    .....
    A5183AA10FAC1DCCD581254A4
    A6A7646433330474835DBAFE5
    A7421081507B6CFAB19356F23

    and I want to find this data "9DB831A9207DA9DE9F3E45525" is in database or not.

    Do you know how to write program to do that?

    Thank you for your answer.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    yep.

    Show us what you came up with and i'll help. I'm loathe to help too much before at least seeing some code.You only learn by making mistakes.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    68
    I use this below code but it is very slow. My database data is sort number, so I think there may be the other ways to search quicker. If you know how to do that , please tell me.

    <code>
    // My 400,000 database data is Database_Data Array

    // I want to search "9DB831A9207DA9DE9F3E45525" in database
    m_Data = "9DB831A9207DA9DE9F3E45525";

    Found = 0;
    for (j=0; j<400,000; j++)
    {
    if (m_Data == Database_Data[j])
    {
    Found = 1;
    break;
    }
    }

    </code>
    Last edited by ooosawaddee3; 03-24-2003 at 09:16 PM.

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    binary search tree
    or AVL tree

  5. #5
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    I think the actual answer you're looking for has nothing to do with a database, but simply a fast(er) search algorithm.

    Since your data is sorted in order, try a binary search. It is faster (with a big-O of ln(n)).

    Basically the way you accomplish this is to go to the middle of the list and check if the value there is > or < the value you're searching for. If it is less than, you go to the middle between the start and your current point or if it's greater than, you go to the middle between the end and your current point.

    If that doesn't make any sense... I'll try to illustrate:

    Code:
    here's a sorted array with 9 elements:
    1 2 3 4 4 5 6 7 9
    
    let's say you want to search for 2. 
    1) start = index 0, end = index 8
    2) go to the middle: 8 / 2 = 4
    1 2 3 4 4 5 6 7 9
            ^
    3) if it is > your search value, end = index 4, repeat step 2
      if it is < your search value, start = index 4, repeat step 2
      if it == your search value, you're done.
    I may be overexplaining a bit, but I just want to make sure I'm being clear.

    hth
    Last edited by LuckY; 03-26-2003 at 12:45 PM.

  6. #6
    Rog
    Rog is offline
    Registered User
    Join Date
    Jan 2003
    Posts
    78
    I thought you over explained it very nicely...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to find coomon data in 3 files without rewind..
    By transgalactic2 in forum C Programming
    Replies: 31
    Last Post: 03-29-2009, 04:23 PM
  2. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  3. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 11:13 AM
  4. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 02:00 AM
  5. File Database & Data Structure :: C++
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 02-24-2002, 11:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21