Is my Insertion Sort optimal? I'm learning sorting algorithms and wrote my own implementation of Insertion Sort. Is it optimal? Is there anything that can be done better?
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;

void display(std::vector&lt;int&gt; arr)
{
  for (int i = 0; i &lt; arr.size(); ++i)
    {
      std::cout &lt;&lt; arr[i] &lt;&lt; ' ';
    }
  std::cout &lt;&lt; std::endl;
}

std::vector&lt;int&gt;&amp; insertionSort(std::vector&lt;int&gt;&amp; arr)
{
  int i = 1;
  while (i &lt; arr.size())
    {
      int j = i;
      while ((j &gt; 0) &amp;&amp; (arr[j-1] &gt; arr[j]))
    {
      std::swap(arr[j-1],arr[j]);
      --j;
    }
      ++i;
    }
  return arr;
}  

int main()
{
  std::vector&lt;int&gt; arr{1,4,3,5,6,2};
  display(insertionSort(arr));
  return 0;
}
Your insertionSort() is OK, but I would write:
template&lt;std::forward_iterator Iter&gt;
void insertion_sort(Iter first, Iter last) {
    for (Iter it = first; it != last; ++it)
        std::rotate(std::upper_bound(first, it, *it), it, std::next(it));
}

insertion_sort(v.begin(), v.end());

display() copys your vector, so make the parameter as const (lvalue) reference.
Use ranged-for loop for printing:
for (auto n : vec) {
    std::cout &lt;&lt; n &lt;&lt; ' ';
}
std::cout &lt;&lt; '\n'; // don't use std::endl

Or you can use one-liner
std::copy(v.begin(), v.end(), std::ostream_iterator&lt;int&gt;(std::cout, ' '));