Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming 2nd Edition Jessen Havill download
Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming 2nd Edition Jessen Havill download
https://textbookfull.com/product/discovering-computer-science-
interdisciplinary-problems-principles-and-python-programming-2nd-
edition-jessen-havill/
https://textbookfull.com/product/discovering-computer-science-
interdisciplinary-problems-principles-and-python-programming-2nd-
edition-jessen-havill-2/
https://textbookfull.com/product/discovering-computer-science-
interdisciplinary-problems-principles-and-python-programming-1st-
edition-jessen-havill/
https://textbookfull.com/product/discovering-computer-science-
interdisciplinary-problems-principles-and-python-programming-
first-edition-jessen-havill/
https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-
loucas/
Python Programming An Introduction to Computer Science
John M. Zelle
https://textbookfull.com/product/python-programming-an-
introduction-to-computer-science-john-m-zelle/
https://textbookfull.com/product/python-programming-an-
introduction-to-computer-science-3rd-edition-john-m-zelle/
https://textbookfull.com/product/data-science-from-scratch-first-
principles-with-python-2nd-edition-joel-grus/
https://textbookfull.com/product/data-science-from-scratch-first-
principles-with-python-2nd-edition-grus-joel/
https://textbookfull.com/product/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
Preface
Acknowledgments
*3.4 BINARYARITHMETIC
More limited precision
Negative integers
Designing an adder
Implementing an adder
4.1 ACCUMULATORS
Managing a fishing pond
Measuring network value
Organizing a concert
4.6 SUMMING UP
Tangent 4.1 Triangular numbers
*4.8 PROJECTS
4.1 Parasitic relationships
4.2 Financial calculators
4.3 Market penetration
4.4 Wolves and moose
*5.8 PROJECTS
5.1 The magic of polling
5.2 Escape!
6.4 A CONCORDANCE
Finding a word
A concordance entry
A complete concordance
*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.5 PROJECTS
8.1 Modeling segregation
8.2 Modeling ferromagnetism
8.3 Growing dendrites
8.4 Simulating an epidemic
9.1 FRACTALS
Trees
Snowflakes
*9.8 PROJECTS
9.1 Lindenmayer’s beautiful plants
9.2 Gerrymandering
9.3 Percolation
*10.7 PROJECTS
10.1 Creating a searchable database
10.2 Binary search trees
CHAPTER 11 ■ Networks
*11.6 PROJECTS
*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.7 PROJECTS
12.1 Tracking GPS coordinates
12.2 Economic mobility
12.3 Slime mold aggregation
12.4 Boids in space
Bibliography
Index
_______________
* Sections with *** in lieu of a page number are available on the book website.
Preface
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.
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.
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.”
Book website
Online materials for this book are available at
https://www.discoveringCS.net.
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.
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
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
7 Data Analysis
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
10 Organizing Data
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
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
Dear Professor Chamberlain,—I have just received and read your most
interesting letter on my return from Kizuki,—where I should have
liked to remain longer, but I must go to see the Bon-odori at Shimo-
ichi, where it is danced differently from anywhere else, so far as I
can learn, and in a thrillingly ghostly manner,—so that one thinks he
is looking at a Dance of Souls.
Before leaving I had a copy of Murray’s Guide sent to the Kokuzō,
who was more than pleased to see the picture of the great temple
reproduced and to hear what was said about it. Before I went away,
he gave me another singular entertainment, such as he alone could
do—for he is King of Kizuki. (By the way, the old reverence for the
Kokuzō is not dead. Folks do not believe now that whoever he looks
at immediately becomes unable to move; but as I and my
companion followed him to the great shrine, the pilgrims fell down
and worshipped him as he passed.)
This was the entertainment he gave me:—Having invited me to the
temple grounds, where seats were prepared, and a supper got ready
for us, Mr. Senke gave some order, and the immense court
immediately filled with people,—thousands. Then at a signal began a
round dance, such as I had never seen before,—the Hōnen-odori, as
anciently performed in Kizuki. It was so fascinating that I watched it
until two o’clock in the morning. At least three hundred dancers
were in the ring;—and the leader, standing on a mochi-mortar
turned upside down, with an umbrella over his head, formed the axis
of the great round, and turned slowly within it upon his pedestal. He
had a superb voice. The Kokuzō also got the beautiful miko dances
photographed to please me, and presented me with many curious
MSS., some of which I hope to show you later on. They were written
expressly for me.
Now as to the shōryō-bune. Just as the Bon-odori differs in every
part of Japan, and just as everything at Kizuki is totally different
from everything at Ise, even to the Miko-kagura, so is the custom of
sending away the Ships of the Souls different here. In many parts
the ships are launched at two or three o’clock in the morning of the
day after the Bon; or if ships are not launched, then floating lanterns
are sent out by way of guiding the dead home. But in Kizuki the
shōryō-bune are launched only by day and for those who have been
drowned at sea, and the shapes of the ships vary according to the
kind of ship in which the lost man or woman perished. And they are
launched every year for ten years after the death:—and when the
soul returns yearly to visit the home, the ship is made ready, and a
little stick of incense is lighted before launching it to take the
beloved ghost back again, and a little stock of provisions is placed in
it upon kawarake (principally dango). And the kaimyō of the dead is
written upon the sail. And these boats are launched,—not at night,
as elsewhere, but in the daytime.
I have had the shōryō-bune boxed and addressed to you, and a
priest wrote for me the kaimyō upon the sail and the date of death,
according to the usual custom. But you will not get the thing before
three weeks, as I am forwarding it by express, and you know how
slow the process is!
As for my letters, use anything you wish, and, if you desire, my
name. The only matter is this: that I am so small a personage as an
author that I am much in doubt whether the use of my name
attached to any opinion would give the opinion more weight than if
expressed impersonally. Unless it should, it might not be good for
the book. I leave the decision entirely to you.
I have been reading Mr. Lowell’s book over again; for it is one thing
to read it in Philadelphia, and quite another thing to read it after
having spent a year and a half in Japan. And the power and the
charm impress me more than ever. But I am so much horrified by its
conclusions—at least a few of them—that I try very hard to find a
flaw therein. I think the idea that the degree of the development of
individuality in a people necessarily marks its place in the great
march of mind is not true necessarily. At least it may be argued
about. For as the tendency of the age is toward class specialization
and interdependent subdivision of all branches of knowledge and all
practical application of that knowledge, the development of the
individuality of every integer of a community would seem to me to
unfit the unit to form a close part of any specialized class. In brief, I
doubt, or rather I wish to doubt, that the development of
individuality is a lofty or desirable tendency. Much of what is called
personality and individuality is intensely repellent, and makes the
principal misery of Occidental life. It means much that is connected
with pure aggressive selfishness: and its extraordinary development
in a country like America or England seems a confirmation of
Viscount Torio’s theory that Western civilization has the defect of
cultivating the individual at the expense only of the mass, and giving
unbounded opportunities to human selfishness, unrestrained by
religious sentiment, law, or emotional feeling.
THE CITY OF MATSUE
What you say about your experience with Japanese poetry is indeed
very telling and very painful to one who loves Japan. Depth, I have
long suspected, does not exist in the Japanese soul-stream. It flows
much like the rivers of the country,—over beds three quarters dry,—
very clear and charmingly beshadowed;—but made temporarily
profound only by some passional storm. But it seems to me that
some tendencies in Japanese prose give hope of some beautiful
things. There was a story some time ago in the Asahi Shimbun about
a shirabyōshi that brought tears to my eyes, as slowly and painfully
translated by a friend. There was tenderness and poetry and pathos
in it worthy of Le Fanu (I thought of the exquisite story of Le Fanu,
“A Bird of Passage,” simply as a superb bit of tender pathos) or Bret
Harte—though, of course, I don’t know what the style is. But the
Japanese poem, as I judge from your work and the “Anthologie
Japonaise,” seems to me exactly the Japanese coloured print in
words,—nothing much more. Still, how the sensation of that which
has been is flashed into heart and memory by the delicious print or
the simple little verse.
I go to-morrow or the next day to Shimo-ichi. If you get the shōryō-
bune, let me know. Any of your servants can, I think, fix the little
masts and pennons in place. A small incense vessel and kawarake
with dango, or models of dango, might be added by Dr. Tylor to the
exhibit; but I suppose these are not essential.
With sincerest regards, ever truly,
Lafcadio Hearn.
TO PAGE M. BAKER
Matsue, August, 1891.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com