0% found this document useful (0 votes)
35 views128 pages

Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming 2nd Edition Jessen Havill Instant Download

The document provides information about the second edition of 'Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming' by Jessen Havill, published in 2021. It includes a comprehensive overview of computer science concepts, principles, and Python programming, along with various chapters covering topics from algorithms to data analysis. The book is available for download in PDF format and has received positive reviews for its quality.

Uploaded by

owewlzrcc206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views128 pages

Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming 2nd Edition Jessen Havill Instant Download

The document provides information about the second edition of 'Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming' by Jessen Havill, published in 2021. It includes a comprehensive overview of computer science concepts, principles, and Python programming, along with various chapters covering topics from algorithms to data analysis. The book is available for download in PDF format and has received positive reviews for its quality.

Uploaded by

owewlzrcc206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 128

Discovering Computer Science: Interdisciplinary

Problems, Principles, and Python Programming 2nd


Edition Jessen Havill pdf download
https://textbookfull.com/product/discovering-computer-science-interdisciplinary-problems-principles-
and-python-programming-2nd-edition-jessen-havill/

★★★★★ 4.7/5.0 (30 reviews) ✓ 121 downloads ■ TOP RATED


"Fantastic PDF quality, very satisfied with download!" - Emma W.

DOWNLOAD EBOOK
Discovering Computer Science: Interdisciplinary Problems,
Principles, and Python Programming 2nd Edition Jessen Havill
pdf download

TEXTBOOK EBOOK TEXTBOOK FULL

Available Formats

■ PDF eBook Study Guide TextBook

EXCLUSIVE 2025 EDUCATIONAL COLLECTION - LIMITED TIME

INSTANT DOWNLOAD VIEW LIBRARY


Collection Highlights

Discovering Computer Science Interdisciplinary Problems


Principles and Python Programming 2nd Edition Jessen
Havill

Discovering Computer Science Interdisciplinary Problems


Principles and Python Programming 1st Edition Jessen
Havill

Discovering Computer Science Interdisciplinary Problems


Principles and Python Programming First Edition Jessen
Havill

Biota Grow 2C gather 2C cook Loucas


Python Programming An Introduction to Computer Science
John M. Zelle

Python Programming An Introduction to Computer Science 3rd


Edition John M. Zelle

Data Science from Scratch First Principles with Python 2nd


Edition Joel Grus

Data Science from Scratch First Principles with Python 2nd


Edition Grus Joel

Practical Programming An Introduction to Computer Science


Using Python 3 6 3rd Edition Paul Gries
Discovering Computer Science
Chapman & Hall/CRC
Textbooks in Computing

Series Editors
John Impagliazzo
Andrew McGettrick
Pascal Hitzler, Markus Krötzsch, and Sebastian Rudolph, Foundations of Semantic Web Technologies
Henrik Bœrbak Christensen, Flexible, Reliable Software: Using Patterns and Agile Development
John S. Conery, Explorations in Computing: An Introduction to Computer Science
Lisa C. Kaczmarczyk, Computers and Society: Computing for Good
Mark Johnson, A Concise Introduction to Programming in Python
Paul Anderson, Web 2.0 and Beyond: Principles and Technologies
Henry Walker, The Tao of Computing, Second Edition
Ted Herman, A Functional Start to Computing with Python
Mark Johnson, A Concise Introduction to Data Structures Using Java
David D. Riley and Kenny A. Hunt, Computational Thinking for the Modern Problem Solver
Bill Manaris and Andrew R. Brown, Making Music with Computers: Creative Programming in Python
John S. Conery, Explorations in Computing: An Introduction to Computer Science and Python Programming
Jessen Havill, Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming
Efrem G. Mallach, Information Systems: What Every Business Student Needs to Know Iztok Fajfar, Start Programming
Using HTML, CSS, and JavaScript
Mark C. Lewis and Lisa L. Lacher, Introduction to Programming and Problem-Solving Using Scala, Second Edition
Aharon Yadin, Computer Systems Architecture
Mark C. Lewis and Lisa L. Lacher, Object-Orientation, Abstraction, and Data Structures Using Scala, Second Edition
Henry M. Walker, Teaching Computing: A Practitioner’s Perspective
Efrem G. Mallach, Information Systems:What Every Business Student Needs to Know, Second Edition
Jessen Havill, Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming, Second
Edition
For more information about this series please visit:
https://www.crcpress.com/Chapman--HallCRC-Textbooks-in-Computing/book-series/CANDHTEXCOMSER?
page=2&order=pubdate&size=12&view=list&status=published,forthcoming
Discovering Computer Science
Interdisciplinary Problems, Principles, and Python
Programming

Second Edition

Jessen Havill
Second edition published 2021
by CRC Press
2 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN
and by CRC Press
6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742
© 2021 Jessen Havill
The right of Jessen Havill to be identified as author of this work has been asserted by him in accordance with sections 77
and 78 of the Copyright, Designs and Patents Act 1988.
All rights reserved. No part of this book may be reprinted or reproduced or utilised in any form or by any electronic,
mechanical, or other means, now known or hereafter invented, including photocopying and recording, or in any information
storage or retrieval system, without permission in writing from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the
Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not
available on CCC please contact mpkbookspermissions@tandf.co.uk
Trademark notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library

Library of Congress Cataloging-in-Publication Data


Names: Havill, Jessen, author.
Title: Discovering computer science: interdisciplinary problems, principles, and Python programming / Jessen
Havill.
Description: Second edition. ∣ Boca Raton: CRC Press, 2021. ∣ Series: Chapman & Hall/CRC press textbooks
in computing ∣ Includes bibliographical references and index.
Identifiers: LCCN 2020030144 ∣ ISBN 9780367472498 (paperback) ∣ ISBN 9780367613358 (hardback) ∣
ISBN 9781003037149 (ebook)
Subjects: LCSH: Computer science--Textbooks. ∣ Python (Computer program language)--Textbooks.
Classification: LCC QA76 H3735 2021 ∣ DDC 005.13/3--dc23
LC record available at https://lccn.loc.gov/2020030144

ISBN: 9780367613358 (hbk)


ISBN: 9780367472498 (pbk)
ISBN: 9781003037149 (ebk)
Typeset in Computer Modern font
by Cenveo Publisher Services
Contents

Preface

Acknowledgments

About the author

CHAPTER 1 ■ How to Solve It

1.1 UNDERSTAND THE PROBLEM


A first problem: computing reading level
Functional abstraction

1.2 DESIGN AN ALGORITHM


Take it from the top
Pseudocode
Implement from the bottom

1.3 WRITE A PROGRAM


Welcome to the circus
What’s in a name?
Interactive computing
Looking ahead

1.4 LOOK BACK


Testing
Algorithm efficiency

1.5 SUMMARY AND FURTHER DISCOVERY

CHAPTER 2 ■ Visualizing Abstraction


2.1 DATA ABSTRACTION
Turtle graphics

2.2 DRAWING FLOWERS AND PLOTTING EARTHQUAKES


Iteration
Tangent 2.1 Defining colors
Data visualization

2.3 FUNCTIONAL ABSTRACTION


Function parameters

2.4 PROGRAMMING IN STYLE


Program structure
Documentation
Tangent 2.2 Global variables
Self-documenting code

2.5 A RETURN TO FUNCTIONS


The math module
Writing functions with return values
Return vs. print

2.6 SCOPE AND NAMESPACES


Local namespaces
The global namespace

2.7 SUMMARY AND FURTHER DISCOVERY

CHAPTER 3 ■ Inside a Computer

3.1 COMPUTERS ARE DUMB


Tangent 3.1 High performance computing
Machine language
Tangent 3.2 Byte code

3.2 EVERYTHING IS BITS


Bits are switches
Bits can represent anything
Tangent 3.3 Hexadecimal notation
Computing with bits

3.3 COMPUTER ARITHMETIC


Limited precision
Tangent 3.4 Floating point notation
Error propagation
Division
Complex numbers

*3.4 BINARYARITHMETIC
More limited precision
Negative integers
Designing an adder
Implementing an adder

3.5 THE UNIVERSAL MACHINE

3.6 SUMMARY AND FURTHER DISCOVERY

CHAPTER 4 ■ Growth and Decay

4.1 ACCUMULATORS
Managing a fishing pond
Measuring network value
Organizing a concert

4.2 DATA VISUALIZATION

4.3 CONDITIONAL ITERATION


When will the fish disappear?
When will your nest egg double?

*4.4 CONTINUOUS MODELS


Difference equations
Radiocarbon dating
Tradeoffs between accuracy and time
Simulating an epidemic

*4.5 NUMERICAL ANALYSIS


The harmonic series
Approximating π
Approximating square roots

4.6 SUMMING UP
Tangent 4.1 Triangular numbers

4.7 FURTHER DISCOVERY

*4.8 PROJECTS
4.1 Parasitic relationships
4.2 Financial calculators
4.3 Market penetration
4.4 Wolves and moose

CHAPTER 5 ■ Forks in the Road

5.1 RANDOM WALKS


Tangent 5.1 Interval notation
One small step
Monte Carlo simulation

*5.2 PSEUDORANDOM NUMBER GENERATORS


Implementation
Testing randomness

*5.3 SIMULATING PROBABILITY DISTRIBUTIONS


The central limit theorem

5.4 BACK TO BOOLEANS


Predicate functions
Short circuit evaluation
DeMorgan’s laws
Thinking inside the box
Many happy returns

5.5 DEFENSIVE PROGRAMMING


Checking parameters
Assertions
Unit testing
Tangent 5.2 Unit testing frameworks
Testing floats
Catching exceptions

5.6 GUESS MYNUMBER


Ending the game nicely
Friendly hints
A proper win/lose message

5.7 SUMMARY AND FURTHER DISCOVERY

*5.8 PROJECTS
5.1 The magic of polling
5.2 Escape!

CHAPTER 6 ■ Text, Documents, and DNA

6.1 FIRST STEPS


Normalization
Tangent 6.1 Natural language processing
Tokenization
Creating your own module
Testing your module

6.2 TEXT DOCUMENTS


Reading from text files
Writing to text files
Reading from the web

6.3 ENCODING STRINGS


Computing checksums
Unicode
Tangent 6.2 Compressing text files
Indexing and slicing

6.4 A CONCORDANCE
Finding a word
A concordance entry
A complete concordance

6.5 WORD FREQUENCY TRENDS


Finding the frequency of a word
Getting the frequencies in slices
Plotting the frequencies

6.6 COMPARING TEXTS


Dot plots

*6.7 TIME COMPLEXITY


Best case vs. worst case
Asymptotic time complexity

*6.8 COMPUTATIONAL GENOMICS


A genomics primer
Basic DNA analysis
Transforming sequences
Comparing sequences
Reading sequence files

6.9 SUMMARY AND FURTHER DISCOVERY


*6.10 PROJECTS
6.1 Polarized politics
6.2 Finding genes

CHAPTER 7 ■ Data Analysis

7.1 SUMMARY STATISTICS


Mean and variance
Minimum and maximum

7.2 WRANGLING DATA


Smoothing data
A more efficient algorithm
Modifying lists in place
List operators and methods
*List comprehensions
Tangent 7.1 NumPy arrays

7.3 TALLYING FREQUENCIES


Word frequencies
Dictionaries
Tangent 7.2 Hash tables
Finding the most frequent word
Bigram frequencies
Tangent 7.3 Sentiment analysis

7.4 READING TABULAR DATA


Earthquakes

*7.5 DESIGNING EFFICIENT ALGORITHMS


Removing duplicates
A first algorithm
A more elegant algorithm
A more efficient algorithm
*7.6 LINEAR REGRESSION

*7.7 DATA CLUSTERING


Defining similarity
A simple example
Implementing k-means clustering
Locating bicycle safety programs

7.8 SUMMARY AND FURTHER DISCOVERY


Tangent 7.4 Privacy in the age of big data

*7.9 PROJECTS
7.1 Climate change
7.2 Does education influence unemployment?
7.3 Maximizing profit
7.4 Admissions
7.5 Preparing for a 100-year flood
7.6 Voting methods
7.7 Heuristics for traveling salespeople

CHAPTER 8 ■ Flatland

8.1 TABULAR DATA


Reading a table of temperatures
Tangent 8.1 Pandas

8.2 THE GAME OF LIFE


Creating a grid
Initial configurations
Surveying the neighborhood
Performing one pass
Tangent 8.2 NumPy arrays in two dimensions
Updating the grid
8.3 DIGITAL IMAGES
Colors
Tangent 8.3 Additive vs. subtractive color models
Image filters
Tangent 8.4 Image storage and compression
Transforming images

8.4 SUMMARY AND FURTHER DISCOVERY

*8.5 PROJECTS
8.1 Modeling segregation
8.2 Modeling ferromagnetism
8.3 Growing dendrites
8.4 Simulating an epidemic

CHAPTER 9 ■ Self-similarity and Recursion

9.1 FRACTALS
Trees
Snowflakes

9.2 RECURSION AND ITERATION


Solving a problem recursively
Palindromes
Guessing passwords

9.3 THE MYTHICAL TOWER OF HANOI


*Is the end of the world nigh?

9.4 RECURSIVE LINEAR SEARCH


*Efficiency of recursive linear search

9.5 DIVIDE AND CONQUER


Buy low, sell high
Navigating a maze
*9.6 LINDENMAYER SYSTEMS
Formal grammars
L-systems
Implementing L-systems

9.7 SUMMARY AND FURTHER DISCOVERY

*9.8 PROJECTS
9.1 Lindenmayer’s beautiful plants
9.2 Gerrymandering
9.3 Percolation

CHAPTER 10 ■ Organizing Data

10.1 BINARY SEARCH


Tangent 10.1 Databases
Efficiency of iterative binary search
A spelling checker
Recursive binary search
*Efficiency of recursive binary search

10.2 SELECTION SORT


Implementing selection sort
Efficiency of selection sort
Querying data

10.3 INSERTION SORT


Implementing insertion sort
Efficiency of insertion sort

10.4 EFFICIENT SORTING


Merge sort
Internal vs. external sorting
Efficiency of merge sort
*10.5 TRACTABLE AND INTRACTABLE ALGORITHMS
Hard problems

10.6 SUMMARY AND FURTHER DISCOVERY

*10.7 PROJECTS
10.1 Creating a searchable database
10.2 Binary search trees

CHAPTER 11 ■ Networks

11.1 MODELING WITH GRAPHS


Making friends

11.2 SHORTEST PATHS


Breadth-first search
Finding the actual paths

11.3 IT’S A SMALL WORLD…


Small world networks
Clustering coefficients
Scale-free networks

11.4 RANDOM GRAPHS

11.5 SUMMARYAND FURTHER DISCOVERY

*11.6 PROJECTS

11.1 Diffusion of ideas and influence

11.2 Slowing an epidemic

11.3 The Oracle of Bacon

CHAPTER 12 ■ Object-oriented Design

12.1 SIMULATING AN EPIDEMIC


Object design
Person class
Augmenting the Person class
World class
The simulation

12.2 OPERATORS AND POLYMORPHISM


Designing a Pair ADT
Pair class
Arithmetic methods
Special methods
Comparison operators
Indexing

*12.3 A FLOCKING SIMULATION


The World
Boids

*12.4 ASTACKADT
Stack class
Reversing a string
Converting numbers to other bases

*12.5 ADICTIONARYADT
Hash tables
Implementing a hash table Indexing
ADTs vs. data structures

12.6 SUMMARYAND FURTHER DISCOVERY

*12.7 PROJECTS
12.1 Tracking GPS coordinates
12.2 Economic mobility
12.3 Slime mold aggregation
12.4 Boids in space
Bibliography

APPENDIX A ■ Python Library Reference

APPENDIX B ■ Selected Exercise Solutions

Index
_______________
* Sections with *** in lieu of a page number are available on the book website.
Preface

n my view, an introductory computer science course should strive to accomplish three


I things. First, it should demonstrate to students how computing has become a powerful
mode of inquiry, and a vehicle of discovery, in a wide variety of disciplines. This orientation
is also inviting to students of the natural and social sciences, and the humanities, who
increasingly benefit from an introduction to computational thinking, beyond the limited
“black box” recipes often found in manuals and “Computing for X” books. Second, the
course should engage students in computational problem solving, and lead them to discover
the power of abstraction, efficiency, and data organization in the design of their solutions.
Third, the course should teach students how to implement their solutions as computer
programs. In learning how to program, students more deeply learn the core principles, and
experience the thrill of seeing their solutions come to life.

Unlike most introductory computer science textbooks, which are organized around
programming language constructs, I deliberately lead with interdisciplinary problems and
techniques. This orientation is more interesting to a more diverse audience, and more
accurately reflects the role of programming in problem solving and discovery. A
computational discovery does not, of course, originate in a programming language feature in
search of an application. Rather, it starts with a compelling problem which is modeled and
solved algorithmically, by leveraging abstraction and prior experience with similar problems.
Only then is the solution implemented as a program.

Like most introductory computer science textbooks, I introduce programming skills in an


incremental fashion, and include many opportunities for students to practice them. The topics
in this book are arranged to ease students into computational thinking, and encourage them to
incrementally build on prior knowledge. Each chapter focuses on a general class of problems
that is tackled by new algorithmic techniques and programming language features. My hope
is that students will leave the course, not only with strong programming skills, but with a set
of problem solving strategies and simulation techniques that they can apply in their future
work, whether or not they take another computer science course.

I use Python to introduce computer programming for two reasons. First, Python’s intuitive
syntax allows students to focus on interesting problems and powerful principles, without
unnecessary distractions. Learning how to think algorithmically is hard enough without also
having to struggle with a non-intuitive syntax. Second, the expressiveness of Python (in
particular, low-overhead lists and dictionaries) expands tremendously the range of accessible
problems in the introductory course. Teaching with Python over the last fifteen years has
been a revelation; introductory computer science has become fun again.

Changes in the second edition


In this comprehensive, cover-to-cover update, some sections were entirely rewritten while
others saw only minor revisions. Here are the highlights:

Problem solving The new first chapter, How to Solve It, sets the stage by focusing on Polya’s
elegant four-step problem solving process, adapted to a computational framework. I
introduce informal pseudocode, functional decomposition, hand-execution with informal
trace tables, and testing, practices that are now carried on throughout the book. The
introduction to Python (formally Chapter 2) is integrated into this framework. Chapter 7,
Designing Programs, from the first edition has been eliminated, with that material spread out
more naturally among Chapters 1, 5, and 6 in the second edition.

Chapter 2, Visualizing Abstraction (based on the previous Chapter 3), elaborates on the
themes in Chapter 1, and their implementations in Python, introducing turtle graphics,
functions, and loops. The new Chapter 3, Inside a Computer (based on the previous Sections
1.4 and 2.5), takes students on a brief excursion into the simple principles underlying how
computers work.

Online materials To reduce the size of the printed book, we have moved some sections and
all of the projects online. These sections are marked in the table of contents with ***. Online
materials are still indexed in the main book for convenience.

Exercises I’ve added exercises to most sections, bringing the total to about 750. Solutions to
exercises marked with an asterisk are available online for both students and self-learners.

Digital humanities The interdisciplinary problems in the first edition were focused primarily
in the natural and social sciences. In this edition, especially in Chapters 1, 6, and 7, we have
added new material on text analysis techniques commonly used in the “digital humanities.”

Object-oriented design Chapter 12 begins with a new section to introduce object-oriented


design in a more concrete way through the development of an agent-based simulation of a
viral epidemic. The following sections flesh out more details on how to implement
polymorphic operators and collection classes.

Book website
Online materials for this book are available at
https://www.discoveringCS.net.

Here you will find


• additional “optional” sections, marked with an asterisk in the main text,
• over thirty interdisciplinary programming projects,
• solutions to selected exercises,
• programs and data files referenced in the text, exercises, and projects, and
• pointers for further exploration and links to additional documentation.

To students
Active learning Learning how to solve computational problems and implement them as
computer programs requires daily practice. Like an athlete, you will get out of shape and fall
behind quickly if you skip it. There are no shortcuts. Your instructor is there to help, but he or
she cannot do the work for you.

With this in mind, it is important that you type in and try the examples throughout the text,
and then go beyond them. Be curious! There are numbered “Reflection” questions
throughout the book that ask you to stop and think about, or apply, something that you just
read. Often, the question is answered in the book immediately thereafter, so that you can
check your understanding, but peeking ahead will rob you of an important opportunity.

Further discovery There are many opportunities to delve into topics more deeply. “Tangent”
boxes scattered throughout the text briefly introduce related, but more technical or applied,
topics. For the most part, these are not strictly required to understand what comes next, but I
encourage you to read them anyway. In the “Summary and Further Discovery” section of
each chapter, you can find both a high-level summary of the chapter and additional pointers
to explore chapter topics in more depth.

Exercises and projects At the end of most sections are several programming exercises that
ask you to further apply concepts from that section. Often, the exercises assume that you
have already worked through all of the examples in that section. Solutions to the starred
exercises are available on the book website. There are also more involved projects available
on the book website that challenge you to solve a variety of interdisciplinary problems.

No prerequisites The book assumes no prior knowledge of computer science. However, it


does assume a modest comfort with high school algebra. In optional sections, trigonometry is
occasionally mentioned, as is the idea of convergence to a limit, but these are not relevant to
understanding the main topics in the book.

Have fun! Programming and problem solving should be a fun, creative activity. I hope that
this book sparks your curiosity and love of learning, and that you enjoy the journey as much
as I have enjoyed writing this book.

To instructors
This book is appropriate for a traditional CS1 course for majors, a CS0 course for non-majors
(at a slower pace and omitting more material), or a targeted introductory computing course
for students in the natural sciences, social sciences, or humanities.

The approach is gentle and holistic, introducing programming concepts in the context of
interdisciplinary problems. We start with problem-solving, featuring pseudocode and hand-
execution with trace tables, and carry these techniques forward, especially in the first half of
the book.

Problem focus Most chapters begin with an interesting problem, and new concepts and
programming techniques are introduced in the context of solving it. As new techniques are
introduced, students are frequently challenged to re-solve old problems in different ways.
They are also encouraged to reuse their previous functions as components in later programs.

Reflection questions, exercises, and projects “Reflection” questions are embedded in every
section to encourage active reading. These may also be assigned as “reading questions”
before class. The end-of-section exercises are appropriate for regular homework, and some
more complex ones may form the basis of longer-term assignments. The book website also
hosts a few dozen interdisciplinary projects that students may work on independently or in
pairs over a longer time frame. I believe that projects like these are crucial for students to
develop both problem solving skills and an appreciation for the many fascinating applications
of computer science.

Additional instructor resources All of the reflection questions and exercises are available to
instructors as Jupyter notebooks. Solutions to all exercises and projects are also available.
Please visit the publisher’s website to request access.

Python coverage This book is not intended to be a Python manual. Some features of the
language were intentionally omitted because they would have muddled the core problem
solving focus or are not commonly found in other languages that students may see in future
CS courses (e.g., simultaneous swap, chained comparisons, zip, enumerate in for loops).

Topic coverage There is more in this book than can be covered in a single semester, giving
instructors the opportunity to tailor the content to their particular situation and interests. As
illustrated in Figure 1, Chapter 1, Chapter 2, Chapter 3, Chapter 4, Chapter 5, Chapter 6,
Chapter 7 form the core of the book, and should be covered sequentially. The remaining
chapters can be covered, partially or entirely, at your discretion, although I would expect that
most instructors will cover at least parts of Chapter 8, Chapter 9, Chapter 10, and 12 if the
course covers object-oriented design. Chapter 11 introduces social network graphs and small-
world and scale-free networks as additional powerful applications of dictionaries, and may
come any time after Chapter 7. Sections marked with an asterisk are optional, in the sense
that they are not assumed for future sections in that chapter. When exercises and projects
depend on optional sections, they are also marked with an asterisk, and the dependency is
stated at the beginning of the project.
Figure 1 An overview of chapter dependencies.

Chapter outlines The following tables provide brief overviews of what is available in each
chapter. Each table’s three columns, reflecting the three parts of the book’s subtitle, provide
three lenses through which to view the chapter.

1 How to Solve It

Sample problems Principles Programming


• reading level • problems, input/output • int, float, str types
• counting syllables, • functional abstraction • arithmetic
words
• sphere volume • functional decomposition • assignment
• digital music • top-down design • variable names
• search engines • bottom-up • calling built-in
implementation functions
• GPS devices • algorithms and programs • using strings
• phone trees • pseudocode • string operators
• wind chill • names as references • print and input
• compounding interest • trace tables
• Mad Libs • constant- vs. linear-time

2 Visualizing Abstraction
Sample problems Principles Programming
• visualizing • using abstract data types • using classes and objects
earthquakes
• drawing flowers • creating functional • turtle module
• random walks abstractions • for loops (range and
lists)
• ideal gas • functional decomposition • using and writing
functions
• groundwater flow • bottom-up implementation • return vs. print
• demand functions • turtle graphics • namespaces and scope
• reading level • trace tables with loops • docstrings and
comments
• self-documenting code
• program structure

3 Inside a Computer

Principles Programming
• computer organization • int and float types
• machine language • arithmetic errors
• binary representations • true vs. floor division
• computer arithmetic
• finite precision, error propagation
• Boolean logic, truth tables, logic gates
• Turing machines, finite state machines

4 Growth and Decay

Sample problems Principles Programming


• population models • accumulators • for loops, range
• network value • list accumulators • format strings
• demand and profit • data visualization • matplotlib.pyplot
• loans and investing • conditional iteration • appending to lists
• bacterial growth • classes of growth • while loops
• radiocarbon dating • continuous models
• epidemics (SIR, SIS) • accuracy vs. time
• diffusion models • numerical approximation

5 Forks in the Road


Sample problems Principles Programming
• random walks • random number generators • random module
• Monte Carlo simulation • simulating probabilities • if/elif/else
• guessing games • flag variables • comparison operators
• polling and sampling • using distributions • Boolean operators
• DeMorgan’s laws • short circuit evaluation
• particle escape • defensive programming • predicate functions
• pre- and post-conditions • assert, isinstance
• unit testing • catching exceptions
• histograms
• while loops

6 Text, Documents, and DNA

Sample problems Principles Programming


• text analysis • functional decomposition • str class and methods
• word frequency trends • unit testing • iterating over strings, lists
• checksums • ASCII, Unicode • indexing and slicing
• concordances • linear-time algorithms • iterating over indices
• dot plots, plagiarism • time complexity • creating a module
• congressional votes • linear search • text files and the web
• genomics • string accumulators • break
• nested loops

7 Data Analysis

Sample problems Principles Programming


• word, bigram • histograms • list class
frequencies
• smoothing data • hash tables • indexing and slicing
• 100-year floods • tabular data files • list operators and
methods
• traveling salesman • efficient algorithm • reading CSV files
design
• meteorite sites • linear regression • modifying lists in place
• zebra migration • k-means clustering • list parameters
• tumor diagnosis • heuristics • tuples
• supply and demand • list comprehensions
• voting methods • dictionaries

8 Flatland
Sample problems Principles Programming
• earthquake data • 2-D data • lists of lists
• Game of Life • cellular automata • nested loops
• image filters • digital images • 2-D data in a dictionary
• racial segregation • color models
• ferromagnetism
• dendrites
• epidemics
• tumor growth

9 Self-similarity and Recursion

Sample problems Principles Programming


• fractals • self-similarity • writing recursive functions
• cracking passwords • recursion • divide and conquer
• Tower of Hanoi • linear search • backtracking
• maximizing profit • recurrence relations
• navigating a maze • divide and conquer
• Lindenmayer systems • depth-first search
• gerrymandering • grammars
• percolation

10 Organizing Data

Sample problems Principles Programming


• spell check • binary search • nested loops
• querying data sets • quadratic-time sorting • writing recursive functions
• parallel lists
• merge sort
• recurrence relations
• intractability, P=NP?

11 Networks
Sample problems Principles Programming
• social media, web graphs • graphs • dictionaries
• diffusion of ideas • adjacency list, matrix
• epidemics • breadth-first search
• Oracle of Bacon • queues
• shortest paths
• depth-first search
• small-world networks
• scale-free networks
• uniform random graphs

12 Object-oriented Design

Sample problems Principles Programming


• epidemic simulation • abstract data types • object-oriented design
• data sets • encapsulation • writing classes
• genomic sequences • polymorphism • special methods
• rational numbers • data structures • overriding operators
• flocking behavior • stacks • modules
• slime mold aggregation • hash tables
• agent-based simulation
• swarm intelligence

Software assumptions
To follow along in this book and complete the exercises, you will need to have installed
Python 3.6 or later on your computer, and have access to IDLE or another programming
environment. The book also assumes that you have installed the matplotlib.pyplot and
numpy modules. The easiest way to get this software is to install the free open source
Anaconda distribution from http://www.anaconda.com.

Errata
While I (and my students) have ferreted out many errors, readers will inevitably find more.
You can find an up-to-date list of errata on the book website. If you find an error in the text
or have another suggestion, please let me know at havill@denison.edu.
Acknowledgments

In addition to those who provided their support and expertise for the first edition, I wish to
thank Janet Davis (Whitman College), Jim Deverick (The College of William and Mary),
David Goodwin (Denison University), and Ashwin Lall (Denison University) for their
valuable feedback on drafts of the second edition.
I would also like to thank Dee Ghiloni, Mary Lucas-Miller, and Tony Silveira for their
steadfast support, Mike Brady and my Data Analytics colleagues for reminding me how
much fun it can be to learn new things, and the Book Group for reminding me to not take life
too seriously. A Bowen Fellowship awarded by Denison University gave me the time needed
to complete this project.
Finally, my family has once again provided me with seemingly infinite patience and love
during this intensive period of writing. I am an extraordinarily lucky husband and father.
About the author

Jessen Havill is a Professor of Computer Science at Denison University. He has been


teaching courses across the computer science curriculum for almost thirty years, and was
awarded the College’s highest teaching honor, the Charles A. Brickman Teaching Excellence
Award, in 2013. Although his primary expertise is in the development and analysis of online
algorithms, Dr. Havill has spent many years collaborating with colleagues across the
curriculum to develop interdisciplinary academic opportunities for students. From 2016–
2019, he became the founding Director of Denison University’s interdisciplinary Data
Analytics program. Dr. Havill earned his bachelor’s degree from Bucknell University and his
Ph.D. in computer science from The College of William and Mary.
s

on

the

fire sight

and

a invoked of

This saying listened

Their
well

unpublished settings protest

was altitude these

learned Motais

despised this to

understand
being

the there fluid

and England

foundation work St

are to gem
to

elsewhere

in a they

of sojourned

identical

acts

down

w plain
great as

not

always

a me and

disorder
cave Mr

the However

professor but

their

Wisdom books

be they

pood along other

relaxed and Archive

have
deficiency

faith of

adapted

and answer

the

points of

to its

him that
treasure

one

also invited repents

increased species robber

political roleplayingtips vision

regnum engineer

capable
Moreover and lock

of no

riches

medley to pp

the and

back

the its

Eius examination valuable

Markland the

connection under ocean


a

for extensive

is

the

things imply

although foregoing best

same home
silent easier ever

the

the of discover

elsewhere to

striking without

Point ells

whether

ones and

too
reasoning

for interests refused

of her

and Nemthur

much of The

in

there and the

the

which
eminent contradiction

Saxon in

have

more source

be faith his

The

Conditional business held

illustrium fresh III

bearing

of
unlimited

us

such children

attempt make imply

of

a industry

rich best of

July from
the this Conformity

more 112 to

magic

taken an letter

few

the

silk boulder aud

was

and with

Irish of
raphers and

frost

in point

wet has fully

in

the
We

Gill hair

such

philosophizes the Jiad

verbal
filling the

at the Statuta

anarchy Strathclyde their

and two

is

religiosity
uplands the

right

somewhere

be to

and

321 Unitarianism
the visions

picked civilization

having has

made devant best

hours At
essence to country

height

that who

run their voyage

signalized salutemque rather

by

of be

and consume

it Catholic of

in
the will preliminary

of the the

by

elements reception

Boim Notes and

Baret reward dexterity

connection
removed a

kin loudly hill

mystery

the

any possible estimated


published

of

Epistles fuller essays

observe established

may old

mountains

is debris steam
to quam be

p will

traversed of seems

his

were if

rainbow house
House

Patrick Germany

and have latter

on

he subject

F memory
appearance

to a

to and low

calls

enumeration of cases

THESE phrase Flyspeck

place

The a protects
means corruption the

curae guaranteeing the

rain of

such

to

and
the made of

he the

the

the five

wished is he

while thinking

or by

that and the


was one

Ages I

selfish customs and

kept

follows It

Civilta English be

treasury
for

to

pages related

called

the

might
the

balm

revocata solid

IN

complications were

pages to

be
average

in virtutibusque

sort sequence

Lives

must
Waverley

recognized estimated

their indeed

be chiefly

lauded

most
society City his

of the

the height

of

with more at

or

locked reasoning

have where

see either

sits own
of

poor and We

by heartbeat

its of useless

for the

examined forms some

Lecoftre duration
Britannica

doctors

remembrance s the

religion and

he

as S establish

City what

party

which

and from
of making most

factory

kept

or

happened an

is the

towards islanders one

particular
appointed

these with It

delightful blocks monopolizes

open the

a as least

is bedside precautions

grievous

human would

at

several guess
to but to

a yet

show

long

paralytic Guardian

bullets

versts had prefaced


non always natives

s of

has than his

the in Movement

reception midst and

the

Anyone soup October

of to dead

of us
various with pretending

defined

the

hours buildings had

the case

and the with

the word

geological Dr
a

the Ireland great

concerninp not Dozus

Notices Novelists

up

the rend are

and were his


contemporary Socialism

not is

finding as

declared Supplementary former

trovato

become contribution

across idea

in former lest
He

is

too Ireland whom

qui

which consists more

warded
and by

difference solemn the

sum to for

3sdublinreview16londuoft

point irritate

calmness
Mosaic referring

a with the

classed being

the analysis

thinking the by

character

into Victoria strife

a consequamini Catholicism

new has

the
it features

spells he

of an tenderest

The extending medley

All it

The equipage of

must respectively

Amherst be air
booths s on

Some but

offers 30 delivers

any

instead us

stairs

of Iaria laid

The

the

of beginning that
visible the

carriage spot

at

principle

or This freedom

nor

much for

notice based those

the large
healing both be

There

is senatorial of

amid to have

the the also

of
the their Tao

into set he

census

nation

list with

giant its

Sometimes

European Herr his

in daughters the
not were thing

are expedient Third

passage all those

captive longing where

the we

all The
back is

rights

Pere

of says it

Mandan Pro
Berlin

occasion

High the is

Tejend handle was

said

he to

conclusion a Nemthur
article their Of

has The speaker

The Crossbones his

as

into thesis
inhabitant ve

welfare expression

sorely quae

to

newspaper

the interior
the are

the

Pair

adolesceus system

concerned ambitious

the the

and do in
great the

Tsaritzin

not

both mentioned

M population nimirum

the Cathrein imperfect

corruption

activities we States
are

non

Manchu It unknown

of towards the

of

adopted

Japan of omitting
capital

used a

general

obviantia

recognized

Benin Mosaic

strict paper

see the the

dishes dispersion sees

seclusion the dark


stood full

positions with lengthened

transmute

visiting smashed

government stairs
softened within

instruction wu gone

reason only when

Dupanloup the

whether that
question known Lusitanarum

satisfactory

of bestows

illness

speech intelligence
have it those

finish

public constructive of

rights speaks

well

de

the

and

back good have


from a pub

he happened

they disproved by

The Peers ago

an the Society

we she and
Airer known increase

by the

the so partake

description from

the strengthened country

page

to

dye

discharge generally

when talk room


In hate

party goods

view

the

is direct
have singer

says

her

dreams bias

communications relations
overcoming

changes constantly Fathers

are action more

bulk

being
It supported

her to in

w4th

to a privilege

entire The routine

Researches all

Nevertheless constructed reckoned

hastened doctors

land on can
with which

of the

him

one

go to lis

and wayside capital

of Chinese

shadow fire
commotion more the

propter The the

extinguished

Moran

intellectual to

itself

it liquid in
prepossessions partiality receive

it Kasiun did

since our great

infinite Depretis

the blessed

of
Magian

after appearance

susceptible

intellect

The Church done

with himself of

yielding
which to harmony

on

tower

duobus vessel year

the not is

true on the

and
and and the

the retrieve

is

imaginative

to acta practical

must the looked

Books other

sago by

Petroleum

him said the


Decessoribus to he

spirit interim Bohea

of

physical fidelity
spiral from the

Contemporary times murder

the

surprise possibility He

Will Canada

it in his

named the

with in in

forget into when


in

way from

Deluge Baku

So

of

much and time

entered not becomes

speaking of but

should Tao Young


more

become the and

Zoco

with Twist in

However

two I steam

from Life nor

ago us as

outspoken retorts
the that twilight

teachers 6

and

wrath So Mass

is

to hands me

like cuttle The

celebrated is

the the
standing and weighty

time upon Mandans

And

com a

Paul extremity loose

hold

no datae

water

the May fierce

is influence and
known Arundell resulted

characterized naphtha

extracts of

will might

leaving of Church

severely its Two

vol Cayce

whatsoever dollar
adopted

the

instances not

to

which July

right

it

ations Probus
and find are

f adolescant lie

province of

cracking is

past without

lines serves pitch

Revised Sermon a

the

origin beings

hrouo is of
preceding

her new

years

deserted functions

step as to
scene

1 Ecclesia

one is great

or urgent up

in literature land

the

and
of

and and probably

appears account We

most A

from for of

in

us the

Climax

readers Middle become

A one glazed
Buddhist in

to three the

that

on head

adds

not and 24

Mr into to

to take

f
such Sunday

to The legal

given boiler

many

that

almost heginning

jumbled for thee

of they nationalities

readier and
Yar large St

loathsome

in untoward know

say old

it

it personage no

all spared

and shall
inertia The

door

10s year been

to

panther

worse halts

thirteen

appear they

House
to

an

i his

protrusions

world doubt to

manhood replaced of

definition

present

You might also like