Thread: Efficient Algorithm for Project

  1. #1
    Registered User
    Join Date
    Oct 2022
    Posts
    95

    Efficient Algorithm for Project

    Hello,

    I'm currently working on an door access control project that utilizes a microcontroller to compare employee data stored on their access cards with the data scan by reader. The system would works fine for a smaller number of employees, but as the number of employees grows to the range of 10,000 to 30,000, the scanning process becomes slow.

    I'm looking suggestions and recommendations for a more efficient algorithm that can significantly reduce the time taken to scan and compare the records. My current approach uses an array to store employee IDs and names, but I am open to exploring new ideas.

    Thank you in advance for your valuable input!

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    You have not given enough information.
    All you say is that you are storing the info in "an array".
    What are you searching for in the array?
    The employee ID?
    What does the ID look like?
    Are they stored in order in the array?
    How are you searching for it?
    What else is stored in the employee record?
    Assuming you are doing a linear search, possibly in an unordered array, then you could try storing the records in order by the employee ID and doing a binary search.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    qsort, qsort_s - cppreference.com
    Sort the array.
    This is what you do at the start of the day, and only needs to be done once.
    Even the most enthusiastic HR departments won't be changing the roster more often than that.

    bsearch, bsearch_s - cppreference.com
    The average search time for a linear search of 30K elements is comparing 15K elements.
    The average search time for a binary search of 30K elements is comparing 15 elements (that's a thousand times fewer).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Amicable numbers efficient algorithm?
    By Andi Rrashi in forum C Programming
    Replies: 15
    Last Post: 11-04-2011, 06:02 PM
  2. Efficient Sorting Algorithm
    By GCNDoug in forum C++ Programming
    Replies: 10
    Last Post: 11-13-2008, 09:06 AM
  3. Replies: 1
    Last Post: 10-15-2006, 05:17 AM
  4. efficient compression algorithm pls
    By gooddevil in forum C Programming
    Replies: 7
    Last Post: 05-08-2004, 03:33 AM
  5. Efficient Algorithm
    By purple in forum C Programming
    Replies: 10
    Last Post: 02-05-2003, 03:01 PM

Tags for this Thread