Intro Cos 126
Intro Cos 126
S CIENCE
126
Fall 2023
https://www.princeton.edu/~cos126
https://www.princeton.edu/~cos126
3-body simulation
computer-generated music “Stories from the Silk Road”
NOTICE
dr
ey
Ch
en
g
you may not record or redistribute recordings of this class.
Au
brought to you by
CO MPUTER
S CIENCE
126
Fall 2023
https://www.princeton.edu/~cos126
Questions welcome at any time
5
Computer Science R OBERT S EDGEWICK | K EVIN W AYNE
rs of the field,
us computer scientist
s.
SEDGEWICK
WAYNE
COS 126, S PRING 2023
Computer Science
cally analyzing
ents. An Introduction to
, fully introducing primary
‣ digital revolution
algorithms, and data
can serve as the basis for
s of performance.
‣ course mechanics
omputer
C cience
s challenges, prepare them
Donald Knuth’s Art of
breast of new research.
‣ course resources
at Princeton University,
S
ember of the faculty since
Xerox PARC, IDA, and
ition. Professor Sedgewick
An Interdisciplinary Approach
ROBERT SEDGEWICK
$79.99 U.S. | $83.99 CANADA
K E V I N WAY N E
https://introcs.cs.princeton.edu
topic examples
7
fi
fi
COS 126, S PRING 2023
Computer Science
‣ digital revolution
‣ course mechanics
omputer
C cience ‣ course resources
S An Interdisciplinary Approach
ROBERT SEDGEWICK
K E V I N WAY N E
https://introcs.cs.princeton.edu
The digital revolution
Key idea. “Everything” can be encoded as a sequence of bits (0s and 1s).
9
The digital revolution
・Key idea. “Everything” can be encoded as a sequence of bits (0s and 1s).
– Numbers and text.
– Pictures, songs, and movies.
– Your DNA.
– 3D objects.
– Computer programs.
– …
Claude Shannon
“The Bit Player” 10
Transforming the way we work and live…
11
Transforming science and engineering…
ocean modeling di usion MRI of brain food web in Serengeti nuclear physics
colliding galaxies an aerosol droplet containing coronavirus air ow over landing gear
12
ff
fl
The digital revolution has only just begun
In 2020. 50 billion+ smart connected devices, all developed to collect, analyze, and share data.
13
What will the future be?
‣ Language Processing
‣ Robotics
‣ Healthcare
‣ Communication
‣ Finance
citp.princeton.edu
‣ ...
The digital revolution has only just begun
You are already a consumer (and producer and product). Now, become a creator!
Programming:
Break a big problem
into smaller pieces and
identify the right steps to solve it.
16
Use your new superpower ethically!
17
Understanding Computer Science can help get you elected!
18
COS 126, S PRING 2023
Computer Science
‣ digital revolution
‣ course mechanics
omputer
C cience ‣ course resources
S An Interdisciplinary Approach
ROBERT SEDGEWICK
K E V I N WAY N E
https://introcs.cs.princeton.edu
Course website
https://www.princeton.edu/~cos126
20
Live lectures
21
“ Flipped lecture ” format
Programming | Algorithms
SEDGEWICK
[Sedgewick and Flajolet] are not only worldwide leaders of the field,
they also are masters of exposition. I am sure that every serious computer scientist WAYNE
will find this book rewarding in many ways.
—From the Foreword by Donald E. Knuth
Computer Science
Despite growing interest, basic information on methods and models for mathematically analyzing
algorithms has rarely been directly accessible to practitioners, researchers, or students. An Introduction to
the Analysis of Algorithms, Second Edition, organizes and presents that knowledge, fully introducing primary
techniques and results in the field.
Robert Sedgewick and the late Philippe Flajolet have drawn from both classical mathematics and computer
A N I N T E R D I S C I P L I N A RY A P P R O A C H
science, integrating discrete mathematics, elementary real analysis, combinatorics, algorithms, and data
structures. They emphasize the mathematics needed to support scientific studies that can serve as the basis for
predicting algorithm performance and for comparing different algorithms on the basis of performance.
Techniques covered in the first half of the book include recurrences, generating functions, asymptotics, and
analytic combinatorics. Structures studied in the second half of the book include permutations, trees, strings,
tries, and mappings. Numerous examples are included throughout to illustrate applications to the analysis of
algorithms that are playing a critical role in the evolution of our modern computational infrastructure.
Improvements and additions in this new edition include
Computer
n Simplified derivations via analytic combinatorics throughout
The book’s thorough, self-contained coverage will help readers appreciate the field’s challenges, prepare them
for advanced results—covered in their monograph Analytic Combinatorics and in Donald Knuth’s Art of
Computer Programming books—and provide the background they need to keep abreast of new research.
ROBERT SEDGEWICK is the William O. Baker Professor of Computer Science at Princeton University,
Science
where was founding chair of the computer science department and has been a member of the faculty since
1985. He is a Director of Adobe Systems and has served on the research staffs at Xerox PARC, IDA, and
INRIA. He is the coauthor of the landmark introductory book, Algorithms, Fourth Edition. Professor Sedgewick
The late PHILIPPE FLAJOLET was a Senior Research Director at INRIA, Rocquencourt, where he created
and led the ALGO research group. He is celebrated for having opened new lines of research in the analysis
of algorithms; having systematized and developed powerful new methods in the field of analytic combinatorics;
having solved numerous difficult, open problems; and having lectured on the analysis of algorithms all over
the world. Dr. Flajolet was a member of the French Academy of Sciences.
22
Precepts
・80-minute precepts.
・Ed Lessons
– Announcements
– Download the project zip for precept
– Precept exercises (for the most part)
– Review before and/or after precept, as needed
・Can I reuse precept code on assignments / programming exams?
– YES!
・Attendance required!
・If you cannot attend a precept, attend another
– Email preceptor and sign in
・If you are ill
– Makeup precept TTh 7:30–8:20pm (Zoom)
23
Biomedical Precept (P10)
24
Raspberry Pi Precept (P16A)
For students with some Java experience interested in learning topics beyond the scope of the course
・Meets Tue/Thu 11:00am.
・Same lectures and programming assignments.
・About half precept time will explore the use of Java to program on the Raspberry Pi platform.
・If you have some Java experience and have a maker spirit, then you may nd this precept appealing
・Third semester
– Fall’23 - led by Nick Sudarsky’23 - IW and Senior Thesis formed the basis for this precept!
fi
25
Class meetings
26
Programming assignments and Final Project
[ assignment logos by Kathleen Ma ’18, Ilene E ’21 and Ethan Sontarp ’24 ] 27
fi
Recursive Graphics
Sierpinski Triangles
28
Recursive Graphics
Sierpinski Triangles
30
N-Body Simulation
32
fi
fi
Submitting assignments
33
Submitting assignments
DEMO
34
Submitting assignments
35
fi
fi
Submitting assignments
What does Download Project mean? Starting with the Loops assignment, you will download the project zip from
TigerFile
When are assignments published? The assignments are available now. However, we reserve the right to change
them. So they project zip and of cial project zip will be published on the Monday morning, before the Sunday due
date.
36
fi
Two Programming exams
Problem. Develop a Java program that can draw one of several game boards, shown here:
Library. To help you get started, you have access to a new library called Board, similar to StdIn and StdDraw, which
provides the following functions: 37
Two Written exams
・We provide some previous written exams. Caveat - not every semester is identical
– WE 1 - single-side of one 8.5x11 sheet - in your own handwriting
(b) Complete the following code fragment to rotate the variables a, b, and c: after the last
– WE 2 - two-sides of one 8.5x11 sheet - in your own handwriting
statement, b should store the old value of a; c should store the old value of b; and a
should store the old value of c.
In each blank, write one of a, b, c, or temp. You may use each variable name once,
more than once, or not at all.
38
Collaboration policies
Executive summary.
r c o d e !
・Do discuss concepts with others. N o t y o u
・Do partner with a classmate (when permitted).
・Do acknowledge any collaboration with others.
・Do not copy code from anywhere or anyone.
・READ THE COURSE SYLLABUS.
・COLLABORATION POLICY QUIZ.
・ASK QUESTIONS.
39
Collaboration policies
Plagiarism detection.
・We use sophisticated tools to nd plagiarism.
・Obfuscating copied code does not work.
・Cite your sources in the acknowledgments.txt le!
RRR warning: Plagiarizing code is treated the same as plagiarizing prose (but is much easier to catch).
40
fi
fi
Grading
Programming
Assignments
Participation (5%). Attend and participate in precepts.
(40%)
Exams
Typical grade
(45%)
Course grades. Uncurved. distribution
grade percentage
B+ 87.0
⋮ ⋮
A B C D F
41
Icebreaker
Activity. Meet a classmate (that you don’t already know!) and discuss the following:
・What you hope to get out of COS 126.
・What you’re most excited about academically.
・What you’re passionate about non-academically.
・Then, keep chatting!
42
COS 126, S PRING 2023
Computer Science
‣ digital revolution
‣ course mechanics
omputer
C cience ‣ course resources
S An Interdisciplinary Approach
ROBERT SEDGEWICK
K E V I N WAY N E
https://introcs.cs.princeton.edu
Resources (programming environment)
Recommended IDE. Custom IntelliJ 2023.2.1 environment. upgrade to our Fall 2023 version
・Embedded Bash terminal. (see lab TAs for troubleshooting)
・Autoformat, autoimport, autocomplete, ....
・Continuous code inspection; integrated Checkstyle and SpotBugs.
・…
44
Resources (web)
Course website.
・Syllabus and course policies.
・Lecture videos and slides.
・Precept lessons.
・Programming assignments.
https://www.princeton.edu/~cos126
Booksite.
・Download code from book.
・Brief summary of content.
・For use while online.
・NOT the textbook.
・NOT the course website.
Of ce hours.
・ Longer discussions. protip: attend!
McGraw.
・Peer tutoring.
・Consultations.
・…
・mcgraw.princeton.edu/undergraduates
See “Help” tab on course website for additional information! 46
fi
Resources (ed tech)
Platform What
Ed discussion forum, precept exercises also use for communication with course staff
47
A typical week (but not this one!)
Assignment Assignment
Released Class Meeting Feedback
17 18
Assignment
48
QUIZ!
C.
cut-and-paste the error message and give context
Post a question on Ed Discussion. (but don’t post your code)
D. Email my preceptor.
use Ed for routine course
communications, not email
49
fi
fi
QUIZ!
A. Attend of ce hours.
D. Email my preceptor.
50
fi
Q&A
51