title: If stack operations are constant time O(1), what is the time complexity of this algorithm?
body: <p>BinaryConversion:
  We are inputting a positive integer n with the output being a binary representation of n on a stack.</p>
  <p>What would the time complexity here be? I'm thinking it's O(n) as the while loop halves every time, meaning the iterations for a set of inputs size 'n' decrease to n/2, n/4, n/8 etc.</p>
  <p>Applying sum of geometric series whereby n = a and r = 1/2, we get 2n.</p>
  <p>Any help appreciated ! I'm still a noob.</p>
  <pre><code>create empty stack S
  while n &gt; 0 do
      push (n mod 2) onto S
      n = floor(n / 2)
  end while
  return S
  </code></pre>