Question
How long does the recursive multiplication algorithm (page 25 ) take to multiply an $n$ -bit number by an $m$ -bit number? Justify your answer.
Step 1
First, we need to pad the smaller number with zeros to make both numbers have the same number of bits. This takes O(max(n, m)) time. Show more…
Show all steps
Your feedback will help us improve your experience
Mukesh Devi and 101 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Derive the time complexity of the following algorithm. Show your work. MULT IN : x and y, two n-bit binary numbers 1 if n = 1 2 if x = 1 ∧ y = 1 3 return 1 4 else 5 return 0 6 (x1, x0) ← (first ⌈n/2⌉ bits , last ⌈n/2⌉ bits ) of x 7 (y1, y0) ← (first ⌈n/2⌉ bits , last ⌈n/2⌉ bits ) of y 8 z1 ← MULT(x1 + x0, y1 + y0) 9 z2 ← MULT(x1, y1) 10 z3 ← MULT(x0, y0) 11 return z2 · 2^n + (z1 − z2 − z3) · 2^⌈n/2⌉ + z3 OUT: The product of x and y Some details: •All additions and subtractions take O(n) time. •In the final return line, the multiplications by 2^some power are actually bit shifts, and take O(n) time. •The base case takes O(1) time.
How much time does an algorithm take to solve a problem of size $n$ if this algorithm uses $2 n^{2}+2^{n}$ operations, each requiring $10^{-9}$ seconds, with these values of $n ?$ $$ \begin{array}{lllll}{\text { a) } 10} & {\text { b) } 20} & {\text { c) } 50} & {\text { d) } 100}\end{array} $$
Algorithms
Complexity of Algorithms
How much time does an algorithm using $2^{50}$ operations need if each operation takes these amounts of time? $$ \begin{array}{lllll}{\text { a) } 10^{-6} \mathrm{s}} & {\text { b) } 10^{-9} \mathrm{s}} & {\text { c) } 10^{-12} \mathrm{s}}\end{array} $$
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD