
I'm currently taking a intro to algorithms course and I need help solving this problem. Shown above since I'm skeptical and not so sure. :) I have two questions:
Question 1: From what I understood from my algorithms book, I believe the runtime complexity of this problem is f(n) = 3n. Why? Well because the while loop will continue to run n times and for each iteration of the loop you have 3 operations ( 1 subtraction, 1 multiplication, and 1 addition) Is my though process correct or wrong? Should it really be f(n) = 5n because of the assignment statements. I know both are the same complexity, but I'd really like to make sure explicitly.
Question 2: As for showing if the algorithm finds the value of the polynomial, is sufficient enough for me to just give an example of it finding the value of a particular polynomial say 3n^2 + 2n + 1 to prove the algorithm works or is there a better way to do so.
iindependent of the work done inside the loop (other thani=i-1)?