title: Parallelism; recursive or iterative?
body: <p>I've been asked a very interesting question about threads and how to implement them, specifically recursive or iterative. This is in the context of sorting algorithms like quicksort. </p>
  
  <p>When you have an array of elements that need sorting, would you rather implement a tree structure of threads(so recursive) that keep spawning new threads until the sorting size threshold is reached, or would you rather divide the array from the very beginning in even chunks and spawn threads for them?</p>
  
  <p>Example recursive psuedocode:</p>
  
  <pre><code>void sort(int array[], int start, int end){
      if(array.size &gt; THRESHOLD){
          //partition logic with calls to sort()            
      }
      //sorting logic
  }
  </code></pre>
  
  <p>Example iterative psuedocode:</p>
  
  <pre><code>void sort(int array[], int start, int end){
      if(array.size &gt; THRESHOLD){    
          int numberOfChunks = array.size / 1000;
          for(int i = 0; i &lt; numberOfChunks; i++){
              //spawn thread for every chunk with calls to sort(), technically also recursion but only once and can be rewritten easily
          }
      }
      //sorting logic
  }
  </code></pre>
  
  <p>Assume the calls to sort are separate threads. I didn't want to clutter the examples with boilerplate. Try and look past the multitude of errors.</p>
  
  <p>Picture:</p>
  
  <p><a href="https://i.stack.imgur.com/YqQKv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YqQKv.png" alt=""></a>
  What I've been taught in college for quicksort is to use the recursive method. But(and this is my opinion and nothing else) I think recursion has a tendency to make code unreadable and complex. Sure it looks fancy and works well, but it's harder to read.</p>
  
  <p>What is the recommended way of doing things here?</p>