title: Big-O notation with two variables
body: <p>This originates from writing a program to <a href="https://leetcode.com/problems/median-of-two-sorted-arrays/" rel="nofollow noreferrer">find the median of two sorted arrays</a> with size <code>m</code> and <code>n</code> respectively, with the time complexity of <code>O(log(m + n))</code>.</p>
  
  <p>I can work out a solution of <code>O(log(m) + log(n))</code>. Does it meet the time requirement above?</p>
  
  <p>I think it's positive because:</p>
  
  <p><code>log(m) + log(n) = log(m*n) &lt;= log((m+n)^2) = 2*log(m+n) = O(log(m+n))</code></p>
  
  <p>Put another way, there exist <code>k = 2</code> and <code>m0 = n0 = 1</code>. For any <code>m &gt; m0 and n &gt; n0</code>, there is <code>log(m*n) &lt;= k*log(m + n)</code>.</p>
  
  <p>Is there a flaw, or am I correct?</p>
  
  <p>More generally, given constant <code>a</code>, can we say <code>log(n^a) = O(log(n))</code> with the same reasoning?</p>
  
  <hr>
  
  <p>Thanks to David's answer.
  This is also mentioned by <a href="https://en.wikipedia.org/wiki/Big_O_notation" rel="nofollow noreferrer">Big-O notation</a> on Wikipedia:</p>
  
  <p><code>"We may ignore any powers of n inside of the logarithms. The set O(log n) is exactly the same as O(log(n^c))."</code></p>