title: Common pseudocode questions, puzzles and challenges
body: <p>I am looking for examples of pseudocode problems that you may have been asked in an interview or been asked to represent as part of your job or education. I'm not looking for examples from any domain in particular, so it can be related to design patterns, algorithms, data structures, caching strategies, anything to do with Software Engineering and Development, simple or complex.</p>
  
  <p>For example, some common ones I have found are mainly related to sorting and searching techniques:</p>
  
  <p><a href="http://en.wikipedia.org/wiki/Bubble_sort" rel="noreferrer">Bubblesort</a>:</p>
  
  <pre><code>procedure bubbleSort( A : list of sortable items ) defined as:
    do
      swapped := false
      for each i in 0 to length(A) - 2 inclusive do:
        if A[i] &gt; A[i+1] then
          swap( A[i], A[i+1] )
          swapped := true
        end if
      end for
    while swapped
  end procedure
  </code></pre>
  
  <p><a href="http://en.wikipedia.org/wiki/Insertion_sort" rel="noreferrer">Insertion sort</a>:</p>
  
  <pre><code>insertionSort(array A)
  begin
      for i := 1 to length[A]-1 do
      begin
          value := A[i];
          j := i - 1;
          done := false;
          repeat
              if A[j] &gt; value then
              begin
                  A[j + 1] := A[j];
                  j := j - 1;
                  if j &lt; 0 then
                      done := true;
              end
              else
                  done := true;
          until done;
          A[j + 1] := value;
      end;
  end;
  </code></pre>
  
  <p><a href="http://en.wikipedia.org/wiki/Binary_search_algorithm" rel="noreferrer">Binary search</a>:</p>
  
  <pre><code>   BinarySearch(A[0..N-1], value, low, high) {
         if (high &lt; low)
             return -1 // not found
         mid = low + ((high - low) / 2)
         if (A[mid] &gt; value)
             return BinarySearch(A, value, low, mid-1)
         else if (A[mid] &lt; value)
             return BinarySearch(A, value, mid+1, high)
         else
             return mid // found
     }
  </code></pre>
  
  <p>We may be able to build up a decent list of pseudocode algorithms and problems, if many people share their thoughts and experiences.</p>
  
  <p>I'm looking to come up with the pseudocode representation myself, as practice. So even if you can't find a pseudocode example, but you think it would be an ideal concept to represent in this way, that would help too.</p>
  
  <p>I also have a few questions related to the subject too:</p>
  
  <ul>
  <li>Which pseudocode have you been asked to write in an interview before?</li>
  <li>Do these questions tend to relate to short, simple algorithms that are one or two functions long?</li>
  <li>Should language specific constructs be avoided when writing pseudocode? As the representation is meant to be language agnostic, is it safer to not use terms like Dispose and foreach that don't exist in each language?</li>
  </ul>
  
  <p>Thanks</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>A few examples of some more I have found, I'll keep editing as I find more:</p>
  
  <hr>
  
  <p>Write a function that takes a single string to reverse the order of words within a sentence, not reversing the words:</p>
  
  <p>Input: "The cat sat on the mat, with another cat!" </p>
  
  <p>Output: "cat! another with mat, the on sat cat The"</p>
  
  <hr>
  
  <p>Write a function that takes a single string that will return the word that occurs most within that string, ignoring case and punctuation. If more than one word has the same number of occurences return the one that occurred first:</p>
  
  <p>Input: "The cat sat on the mat, with another cat!"</p>
  
  <p>Output: the</p>
  
  <hr>
  
  <p>Write a function to find the character that has the highest number of occurences within a certain string, ignoring case. If there is more than one character with equal highest occurences, return the character that appeared first within the string.</p>
  
  <p>Input: "Character"</p>
  
  <p>Output: c</p>
  
  <hr>
  
  <p>Write a function that reverses a string</p>
  
  <p>Input: "reverse"</p>
  
  <p>Output: "esrever"</p>