{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 4: Recursion & Looping (Review Questions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The questions below assume that you have read the [first ](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/main/04_iteration/00_content.ipynb), [second ](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/main/04_iteration/02_content.ipynb), and the [third ](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/main/04_iteration/03_content.ipynb) part of Chapter 4.\n", "\n", "Be concise in your answers! Most questions can be answered in *one* sentence." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Essay Questions " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q1**: Solving a problem by **recursion** is not only popular in computer science and math. Name some examples from the fields of business or economics where problems are also solved in a **backward** fashion!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q2**: Explain what **duck typing** means! Why can it cause problems? Why is it [not a bug but a feature](https://www.urbandictionary.com/define.php?term=It%27s%20not%20a%20bug%2C%20it%27s%20a%20feature)?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q3**: What is **syntactic sugar**?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q4**: Describe in your own words why the **recursive** version of `fibonacci()`, the \"Easy at first Glance\" example in the chapter, is computationally **inefficient**! Why does the **iterative** version of `fibonacci()`, the \"Hard at first Glance\" example, run so much faster?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q5**: What is the conceptual difference between a **container** and a **list**?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q6**: What is a good use case for the `for`-loop's optional `else`-clause?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## True / False Questions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Motivate your answer with *one short* sentence!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q7**: When a **recursion** does **not** reach the base case, this is an example of the **early exit** strategy." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q8**: Any programming language **without** looping constructs like the `for` or `while` statements is **not** Turing complete." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q9**: A **recursive** formulation is the same as a **circular** one: The terms are **synonyms**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q10**: Formulating a computational problem as a **recursion** results in an **efficient** implementation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q11**: Whereas a **recursion** may accidentally result in a **never-ending** program, `while`-loops and `for`-loops are guaranteed to **terminate**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q12**: Before writing **any** kind of **loop**, we **always** need to think about a **stopping criterion** ahead of time." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Q13**: **Container** types such as `list` objects are characterized by their **support** for **being looped over**, for example as in:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```python\n", "for element in container:\n", " # do something for every element\n", " ...\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " < your answer >" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.2" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": false, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }