Consider the following algorithm:
Algorithm 4 Mystery Alg
IN: $x, y \in \mathbb{N}$
1: $f \leftarrow 2$
2: while $y > 1$ do
3: \quad while $y \neq 0 \pmod{f}$ do
4: \quad \quad $f \leftarrow f + 1$
5: \quad end while
6: \quad while $y \equiv 0 \pmod{f}$ do
7: \quad \quad $x \leftarrow x \times f$
8: \quad \quad $y \leftarrow \frac{y}{f}$
9: \quad end while
10: end while
11: return $x$
(a) Prove that the algorithm terminates whenever it is given valid inputs.
(b) What does the algorithm output? Prove that your answer is correct.
(c) Find, in Big O notation, the maximum number of iterations of the outer loop as a function of $y$.
(d) How many times can the while loop on line 3 iterate during any given iteration of the outer while loop?
What is the maximum value $f$ can reach?
(e) Find, in Big O notation, the maximum number of iterations of the loop on line 6 as a function of $y$.
(f) Assuming multiplication and division are $O(b^{1.465})$, where $b$ is the size in bits of $x$ and $y$, find the time
complexity of the algorithm in terms of $b$ and $y$. Then, simplify to get an expression of $b$ alone.
(g) Is this a good algorithm (i.e. a fast way to get its output)? Justify your answer.