Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the most straight-forward way is to walk through the bit-string while recording the max lengths for all <code>0</code> and all <code>1</code> sub-strings. This is of <code>O (n)</code> complexity as suggested by others.</p> <p>If you can afford some sort of a data-parallel computation, you might want to look at parallel patterns as explained <a href="http://www.drdobbs.com/architecture-and-design/parallel-pattern-7-reduce/222000718" rel="nofollow">here</a>. Specifically, take a look at <a href="http://www.drdobbs.com/architecture-and-design/parallel-pattern-7-reduce/222000718" rel="nofollow">parallel reduction</a>. I think this problem can be implemented in <code>O (log n)</code> time if you can afford one of those methods.</p> <p>I'm trying to think of a parallel reduction for this problem:</p> <ol> <li><p>On the first level of the reduction, each thread will process chunks of 8 bit strings (depending on the number of threads you have and the length of the string) and produce a <strong>summary</strong> of the bit string like: <code>0 -&gt; x, 1 -&gt; y, 0 -&gt; z, ....</code></p></li> <li><p>On the next level each thread will merge two of these summaries into one, any possible joins will be performed at this phase (basically, if the previous summary ended with a <code>0</code> (<code>1</code>) and the next summary begins with a <code>0</code> (<code>1</code>), then the last entry and the first entry of the two summaries can be collapsed into one).</p></li> <li><p>On the top level there will be just one structure with the overall summary of the bit string, which you'll have to step through to figure out the largest sequences (but this time they are all in summary form, so it should be faster). Or, you can make each summary structure keep track of the larges <code>0</code> and <code>1</code> sub-strings, this will make it unnecessary to walk through the final structure.</p></li> </ol> <p>I guess this approach only makes sense in a very limited scope, but since you seem to be very keen on getting better than <code>O (n)</code>...</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.
 

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