Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Its complexity is O(N * (N + M)), where N = <code>one.length()</code>, M = <code>two.length()</code>. </p> <p>It works in the following way: for each character of <code>l_one</code> (there are N of them) it scans <code>l_two</code> (since <code>l_two</code> is an <code>ArrayList</code>, scan is linear, so it takes O(M) steps, see [1]) and removes item from <code>l_one</code> if necessary (removing from <code>ArrayList</code> takes O(N), see [1]), so you get O(N * (N + M)).</p> <p>You can lower the complexity to O(N * M) by using <code>LinkedList</code> for <code>l_one</code> (since removing from <code>LinkedList</code> is O(1), see [2]), and further lower it to O(N * log(M)) by using <code>TreeSet</code> for <code>l_two</code> (since searching in <code>TreeSet</code> takes O(log(M)), see [3]).</p> <p><strong>References:</strong></p> <ol> <li><em>All of the other operations run in linear time</em> (<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html" rel="nofollow"><code>ArrayList</code> javadoc</a>)</li> <li><em>All of the operations perform as could be expected for a doubly-linked list</em>, (<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/LinkedList.html" rel="nofollow"><code>LinkedList</code> javadoc</a>)</li> <li><em>This implementation provides guaranteed log(n) time cost for the basic operations (<code>add</code>, <code>remove</code> and <code>contains</code>)</em> (<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/TreeSet.html" rel="nofollow"><code>TreeSet</code> javadoc</a>)</li> </ol>
 

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