{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Workbook for Chapter 4 of Explorations in Computing"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Section 4.5: Implementing Insertion Sort"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T50. Use the code cell below to define the final version of `isort` as shown in Figure 4.6 of the text book. You can either\n",
"* copy and paste your definition of `move_left` from your workbook for the previous section, and then add the top-level `isort`\n",
"* click on this link and copy and paste the function definition: `isort.py`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T51. Add `print(a[:i], a[i:])` to the body of the `for` loop, just before the call to `move_left` on line 4. Type ⌃⏎ to execute the function definition."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T52. Create a list of strings to test your function:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T53. Ask Python to show you the list it just made:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T54. Pass your list to `isort`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T55. Make some more test lists of varying sizes and pass them to `isort`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T56. Notice how many lines are printed in the output section below each call: if you make a list with $n$ items your function should print $n-1$ lines as the list is sorted. Can you explain why there are always $n-1$ lines?"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": []
}
],
"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.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}