Given: // This pseudocode tries to recursively calculate x^n mod m, // by using
ID: 1942263 • Letter: G
Question
Given:// This pseudocode tries to recursively calculate x^n mod m,
// by using formula: x^n mod m = (x^(n-1) mod m * x mod m ) mod m
procedure finds(n, x, m: positive integers) {
if x^n < m then
finds(n, x, m) =: x^n
else
finds(n, x, m) =: (x^(n-1) mod m * x mod m ) mod m
}
a) Write out a trace of calls for the following algorithm starting with finds(4,2,5)
b) What do you think this algorithm does? Please summarize input, output, and the function it is calculating. Note that the algorithm may have bugs.
c) Does the algorithm need fixing? If so please enter a fixed version here