Week 10 Reflections
Recursion
Due: 11:59 PM on Sunday, April 11
Weekly Recap
Congratulations! We have finished the tenth week of class. This week, we focused on recursion, which is a problem solving technique that works from the top-down by making a big problem smaller, then combining the solutions to the smaller versions of the problem. To recap this week:
- On Monday, we formalized the problem solving technique of iteration, which starts with an empty or partial solution, then incrementally improves the solution using a loop (either for or while). We illustrated how many of our solutions so far this semester have relied on iteration, such as counting the number of hashtags in a social media post and creating a concordance in Lab 6 using dictionaries. Then, we contrasted the approach of iteration with another problem solving technique called recursion, which works in the opposite direction to make problems smaller (instead of focusing on making solutions bigger).
- On Wednesday, we discussed real-world example of recursion, including completing a TODO list, decision making by artificial intelligence (including route planning in Google Maps), and algorithmically creating art. We then explored the three parts to a recursive solution: (1) the recursive call, where a function calls itself and passes in a smaller version of the original input (representing the smaller problem to be solved), (2) the base case, which represents the smallest problem for which we already know the solution (indicating where the function no longer needs to call itself to continue solving the problem), and (3) combining the solution, which takes the solutions to the smaller problems and uses them to create the total solution to the original problem. Afterwards, we looked at two examples of recursive functions: one that calculates n raised to the power of k (modeling what happens when we use the ** operator in Python), and another function that creates the reverse of a string.
- On Friday, we worked as a class to create a recursive function that sums the numbers in a list by modifying our earlier example of calculating the length of a list, and we discussed the related problem of calculating the factorial of a number n (i.e., the product of the numbers 1 up to n). Next, we discussed both how recursion can produce faster solutions to a problem than iteration (when each smaller problem is much smaller than the original), as well as when recursive solutions can be slower (when we need to make multiple recursive calls each time the function is called). We also discussed common mistakes in designing recursive functions. Finally, we highlighted how we might know that a recursive solution is a appropriate for a given problem that we want to solve.
- In lab, we practiced recursion on three different types of data: numbers, strings, and art work.
Your Reflections
In this activity, you have the opportunity to reflect on your own experiences and connections with computer science. In particular, you should answer the following three questions:
- What did you learn this week?
- What would you now like to know more about?
- What connections can you make between something from class this week and your life (e.g., your personal interests, your future goals, your other classes, or society at large)?
You should type up your answers to the above questions in a single document using your favorite word processing software (e.g., Microsoft Word, Apple Pages, Google Docs), save the file as a PDF, and upload it to Gradescope under the assignment "Week 8 Reflections". Each answer should be at least one paragraph of 3-5 sentences (instead of 3-5 sentences total across all answers).
At the end of your document, please indicate that you have followed the honor code on this assignment by writing:
I have adhered to the Honor Code in this assignment.