Lecture 10 Ticket Solution
Complete before the beginning of class on Friday, 09/23
Download this ticket in pdf format or .tex source.
Multiply the binary numbers 1011010
and 110111
by hand using the algorithm described in the Binary Representation notes. Check your work by converting the numbers to decimal and performing the decimal multiplication as well. Please show your work.
Solution
-
Here is the multiplication carried out in binary.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1011010 a x 110111 b ------- 1011010 a + 10110100 a << 1 --------- = 100001110 + 101101000 a << 2 ---------- = 1001110110 + 10110100000 a << 4 ------------ = 100000010110 + 101101000000 a << 5 --------------- = 1001101010110 a * b
We convert the binary numbers to decimal as follows:
\[\begin{align*} 1011010_2 &= 64 + 16 + 8 + 2 = 90\\ 110111_2 &= 32 + 16 + 4 + 2 + 1 = 55\\ 1001101010110_2 &= 4096 + 512 + 256 + 64 + 16 + 4 + 2 = 4950 \end{align*}\]Sure enough, multiplying \(90 \times 55\) in decimal, we get \(4950\).
-
If \(a\) and \(b\) are both represented by \(n\) bits, then the running time of \(\mathrm{Multiply}\) is \(O(n^2)\). This is because each \(\mathrm{Add}\) operation runs in time \(O(n)\), and \(\mathrm{Multiply}\) calls \(\mathrm{Add}\) at most \(n\) times.
For \(a, b \leq N\), the running time \(O((\log N)^2)\). This is because numbers up to \(N\) can be represented by \(n = O(\log N)\) bits. (To see this, observe that all numbers up to \(1 + 2 + 4 + \cdots + 2^B = 2^{B+1} - 1 = 11\cdots1_2\) can be represented with \(B\) bits. So if \(N < 2^B\) (eqivalently \(\log N < B\)), then \(B\) bits are sufficient to represent \(N\).)