Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think your implementation of mergeSort doesn't scale very well. You are using your <code>copy</code> method to copy the appropriate range of the input list as input for a recursive call to <code>mergeSort</code>. If you consider the whole depth of the recursion, you need additional space the size of the entire input list on each level.</p> <p>This means your code needs memory of log2(n) times n where n is the size of your input list. If you are about to mergeSort a list of size 65'536 elements, your code will create copies of it such that it will use a peak amount of log2(65'536) = 16 times the memory requirements of your input table. This might very well lead to a <code>StackOverflowException</code>.</p> <p>To remedy this, I'd rewrite the <code>mergeSort</code> method (or rather create an overloaded version of it) to accept a list together with lower and upper bounds pointing into the list. That way, you won't need to copy the list on each recursion step. On the other hand, as soon as the range delimited by the lower and upper bounds contains just one element, you return a new <code>List</code> containing just this single element which <code>merge()</code> will operate on. That way, you only copy the whole input list once (i.e. at the lowest recursion level), and you'll end up using only twice the memory that the input list occupies (in complexity terms, <code>O(n)</code>). As soon as <code>merge()</code> will have passed over these single-element-lists and will have created a new intermediate result list, the single-element-lists will be available for GC.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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