Documente Academic
Documente Profesional
Documente Cultură
(d) Write another recursive function which inputs two polynomials and outputs another
polynomial (again represented as a list) which is the multiplication of the two input
polynomials. (6 points)
(e) Run your program on two input lists of degree 5, and verify that your addition and
multiplication implementations are correct by evaluating the polynomials separately
at v = 3 and adding/multiplying the result and then, comparing the result by first
adding/multiplying the polynomials using your functions and then evaluating them at
v = 3. Include your test case in a separate write-up file (2 points).
3. Write a recursive Python program which inputs a list L from the user and reverses the order
of elements in the input list L. What is the time complexity of your program? Argue. (6
points)
4. Consider a list of strings which stores the names of people. We would like to write a program
to check whether a given input name matches any of the names present in the list. Note that
here, we are not only looking for exact matches, but also substring matches i.e. whether the
input name is a substring (or exact match) of any of the names in the list. For example, if
the input name is Anupam and your list has an element Anupam Sethi then you should
declare it a match. Write a Python program which inputs a list of names and a name to be
matched from the user and achieves the above functionality. (6 points)
5. Consider the frog jumping example from Minor 1. Two frogs are sitting at the bottom of a
flight of 10 steps and debating in how many ways can they jump up the stairs. They can
jump one, two or three steps at a time. For example, they can cover the 10 steps by jumping
(3, 3, 3, 1) or (2, 3, 3, 2) or other suitable combinations. Their mathematics is not very strong
(being frogs) and they approach you for help. Note that (3, 3, 3, 1) is distinct from (1, 3, 3, 3)
and likewise and that we only want to count the number of solutions and not report solutions.
(a) Write a recursive program (no tail-recursion) to give a general solution to the above
problem for n steps. (4 points)
(b) Write a tail-recursive program to solve the same problem. (4 points)
(c) Try out the two solutions written above for n = 10, 20, 30 100. Verify that two programs return the same solution (you should report the answers returned by the two
versions for each n). What happens to the computational time? Comment. (2 points)
Note: You should include all your time complexity analysis and test cases in a separate file ass4writeup.txt