title: Recursive linear search algorithm
body: <p>I have a homework assignment to create a recursive linear search algorithm from one index to another. For some reason the following code return -1 every time.</p>
  
  <pre><code>public static int recLinearSearch(ArrayList&lt;String&gt; pList, String pKey, int pBeginIdx, int pEndIdx) {
      if (pBeginIdx &gt; pEndIdx) {
          return -1;
      } else if (pList.get(pBeginIdx).equals(pKey)) {
          return pList.indexOf(pBeginIdx);
      }
      // Recursive case
      else return recLinearSearch(pList, pKey, pBeginIdx + 1, pEndIdx - 1);
  
  
  }
  </code></pre>
  
  <p>This is how I'm calling it:</p>
  
  <pre><code>ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();
  
  list.add("Jonathan");
  list.add("Zier");
  
  System.out.println(list.size()); // returns 2
  
  int idx = Hw3_1.recLinearSearch(list, "Jonathan", 0, list.size() - 1);
  System.out.println(idx);    //returns -1
  </code></pre>