title: Calculate x ^ y in O(log n)
body: <p>Interview question: </p>
  
  <blockquote>
    <p>Calculate x ^ y in O(log n)</p>
  </blockquote>
  
  <p>There are different answers like "Use the Indian Power algorithm" or  </p>
  
  <pre><code>double power(double x, int y) 
  {
      if(y == 0) return 1;
  
      double d = power(x, y/2);
  
      if(y%2 == 0) return d*d;
      else return x*d*d;
  }
  </code></pre>
  
  <ol>
  <li><p>is it a correct answer?</p></li>
  <li><p>is there any better way of writing a code for this question?</p></li>
  </ol>