Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As others wrote, the complexity of the best algorithm is <code>O(n)</code>, especially since your array is not sorted.</p> <p>To make the search faster, you could subdivide the array and scan each portion separately in <strong>separate threads</strong>. This would scale linearly with the number of CPU cores you have available on your machine.</p> <p>If, for example, you have four cores available, then spawn four threads and let each thread scan one fourth of the array.</p> <p>Probably this discussion might help: <a href="http://www.dreamincode.net/forums/topic/245694-using-threads-to-reduce-array-search-time/" rel="nofollow">Using threads to reduce array search time</a></p> <hr> <p>In any case (and this is true for any performance related issues), you should profile your code. Create a test case for the approach you have, measure the time it takes and take this as a baseline. Then, for each modification you do, redo the measurement to check if it really improves the execution time. Also make sure to do each measurement more than once (within the same test case) and calculate the average, to reduce caching and other warming up effects (ideally, execute the code at least once before starting the first measurement).</p> <p>This is Java related, but gives some good feedback that it does not in all cases make sense to parallelize: <a href="http://www.youtube.com/watch?v=DCdGlxBbKU4&amp;feature=player_embedded" rel="nofollow">A Beginner´s Guide to Hardcore Concurrency</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload