0% found this document useful (0 votes)
609 views51 pages

Intro Cos 126

1. This document provides information about the COS 126 Computer Science course being offered at Princeton University in the fall of 2023. 2. The course will cover fundamental concepts in computer science including programming, algorithms, data structures, and the theory of computing. 3. Resources for the course include a website, lecture videos, and precept meetings for discussion and problem solving.

Uploaded by

lmtoan311
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)
609 views51 pages

Intro Cos 126

1. This document provides information about the COS 126 Computer Science course being offered at Princeton University in the fall of 2023. 2. The course will cover fundamental concepts in computer science including programming, algorithms, data structures, and the theory of computing. 3. Resources for the course include a website, lecture videos, and precept meetings for discussion and problem solving.

Uploaded by

lmtoan311
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/ 51

CO MPUTER

S CIENCE
126
Fall 2023

https://www.princeton.edu/~cos126

computer-generated music “On the Edge”


CO MPUTER
S CIENCE
126
Fall 2023

https://www.princeton.edu/~cos126

3-body simulation
computer-generated music “Stories from the Silk Road”
NOTICE

I will be recording class meetings to make them available


to students in Covid isolation.

Because of privacy, compliance, and legal considerations,


0
'2

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

raise your hand and ask ask on Ed


(use ❤ to upvote)

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

ematics 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

‣ digital revolution
algorithms, and data
can serve as the basis for
s of performance.

ctions, asymptotics, and


rmutations, trees, strings,
ications to the analysis of
onal infrastructure.

‣ 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

ourt, where he created


of research in the analysis
d of analytic combinatorics;
ysis of algorithms all over

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

Last updated on 9/7/23 1:07 PM


COS 126 course objectives

Goal 1. Read, write, and reason about computer programs.


Goal 2. Apply concepts to science, engineering, and beyond.
Goal 3. Build awareness of substantial intellectual underpinnings.
Goal 4. Demystify computer systems.

topic examples

elements of programming variables, loops, conditionals, arrays, I/O

functions user-de ned functions, modularity, recursion

object-oriented programming user-de ned data types, encapsulation, immutability

algorithms sorting, binary search, stacks, queues, BSTs

theory of computing universality, computability, intractability

design of computers machine language, boolean logic, circuits

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.
– …

・Innovation 1. You can program computers to process bits.


・Innovation 2. Devices use the Internet to send and receive bits.
・Innovation 3. Bits <—> (sensors, displays, actuators, etc.) <—> the world.

Claude Shannon
“The Bit Player” 10
Transforming the way we work and live…

Image 37. Time Magazine named the computer the


Magazine; used by permission]

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

‣ Computer Vision/Image Processing

‣ Entertainment and Games

‣ 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.

Computer Science is a basic skill

[ 99% of politicians agree ]


[ computer science education—a rare nonpartisan issue! ] 15
Use your new superpower responsibly!

Consider The Therac-25 Medical Linear Accelerator


・Designed to destroy tumors with minimal damage to
surrounding tissue
・Relied on software for safe operation
・Six known massive radiation overdoses 1985-1987
・Responsible for several deaths

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

links to videos and slides


Lecture videos (required). Watch studio-produced videos before precept.
on course schedule

adjust to desired speed

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

n Upgraded figures and code


n An all-new chapter introducing analytic combinatorics

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

Textbook readings (required). Computer Science: An Interdisciplinary Approach


earned his Ph.D from Stanford University under Donald E. Knuth.

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.

informit.com/aw | aofa.cs.princeton.edu An Interdisciplinary Approach

by R. Sedgewick and K. Wayne, Addison-Wesley Professional, 2016.


Cover design by Chuti Prasertsith
Cover illustration by

Text printed on recycled paper


ROBERT SEDGEWICK
$79.99 U.S. | $83.99 CANADA
K E V I N WAY N E

22
Precepts

Active learning. Discussion, problem solving, pair programming, …


・Bridge between lecture/reading and the assignments
・50-minute precepts. same content; different pace

・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)

NEW! For students who are interested in biology and medicine


・Meets Mon/Wed 11:00am.
・Same lectures and programming assignments.
・Examples will be presented from relevant biomedical applications, scenarios and datasets.
・Familiarity with or curiosity about fundamental concepts from biology is recommended but not required.
・Preceptor - Prof. Yuri Pritykin - https://pritykinlab.github.io

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

Purpose. Assignment overviews, debugging tutorial, exams, …


・We will use McCosh 50 and other rooms for exams
Participation. You are encouraged and expected to participate.
・ Raise your hand and ask a question. carpe diem!

・Ask a question (anonymously) in Ed Discussion.


course staff will monitor forum
(may answer in forum or share with class)

26
Programming assignments and Final Project

… are an essential part of the experience in learning CS.


・Illustrate a programming or general computer science concept.
・Highlight the role of computation in an important application.
・You solve the problem from scratch, on your own computer!
・Ten (10) programming assignments plus a nal Dean’s Date project

Partners allowed and encouraged!

[ assignment logos by Kathleen Ma ’18, Ilene E ’21 and Ethan Sontarp ’24 ] 27
fi
Recursive Graphics

Sierpinski Triangles

"Lorax Trees" by Jonathan Zhang (Fall 2014)

"Piet Mondrian Rectangles" by Laura Herman (Fall 2015)

28
Recursive Graphics

Sierpinski Triangles

Warning: Video contains ashing lights/images!


29
fl
Guitar Hero

Simulate plucking a guitar string using the Karplus–Strong algorithm.

[ performed by Kevin Wayne in 2013 on a MacBook Pro ]

30
N-Body Simulation

Simulate the motion of n particles, subject to Newton’s laws of gravity.

two colliding galaxies (30M bodies)

our Solar System (5 bodies)


31
Submitting assignments

When? Due Sundays at 11:59pm ET.


How? Upload les via TigerFile.
Where is the TigerFile link for the current assignment? On the speci c assignment page - Submit to TigerFile
What does Download Project mean? Stay tuned!

32
fi
fi
Submitting assignments

Preliminary feedback? Click “Check Submitted Files” button.


Resubmit or unsubmit? Yes.

33
Submitting assignments

DEMO
34
Submitting assignments

Preliminary feedback? Click “Check Submitted Files”


button.
Resubmit or unsubmit? Yes.
All done? Submit acknowledgments.txt le.
but we won’t start
grading until after deadline

Passing test cases? This is very good indicator for


correctness; however, style, readme.txt, etc. also counts!

Submitting late? 10% penalty per (partial) day.


we waive rst 4 late days automatically
(after that, only with recommendation of residential college dean

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

Goal. Quickly write a short program.


・First programming exam is primarily for practice (2%).
・Second programming exam is for demonstrating your new skills (13%).
・On your laptop
・We provide some previous programming exams. Open course materials!
– Caveat - not every semester is identical!

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

Goal. Demonstrate your understanding of programming and non-programming concepts.


・Format: COS 126 WRITTEN EXAM 1, SPRING 2017 3
– Matching.
– Short answer. 2. Java basics. (8 points)
Suppose that the variables a, b, c are of type int.
– Fill-in-the-blank.
(a) Complete the following code fragment so that, after the last statement, the variable max
– Multiple choice. contains the largest of the three values.
In each blank, write one of a, b, c, or max. You may use each variable name once, more
– … than once, or not at all.

・On paper! int max = a;


・WE1 - 15% if ( > ) = ;
・WE2 - 15% if ( > ) = ;

・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 (40%). Assigned weekly.

Final project (10%). A larger and more challenging programming project.

Exams (45%). Participation

・Two written exams (15% each). during class meetings


(5%)

・Two programming exams (2% and 13%). (mark your calendars)

Programming
Assignments
Participation (5%). Attend and participate in precepts.
(40%)
Exams
Typical grade
(45%)
Course grades. Uncurved. distribution

grade percentage

A 93.0 Final Project


A– 90.0 (10%)

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.

See “Resources” tab on course website for additional information! https://introcs.cs.princeton.edu


45
Help (people)

Ed Discussion forum. Intro COS Lab.


・Quick questions. ・Staffed by undergraduates happy to help you.
・Mark post private only when necessary. ・For help with debugging code.
・Please use Ed, not email. ・introlab.cs.princeton.edu
・NEVER POST SOLUTION CODE HERE.

Of ce hours.
・ Longer discussions. protip: attend!

・See course website → Schedule.


Pulkit Singh

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

IntelliJ Java IDE

TigerFile assignment submissions

codePost assignment feedback

Gradescope exam feedback

Canvas check grades

hopefully, not needed!


Zoom
(except for makeup precept)

47
A typical week (but not this one!)

introduce new material

Sun Mon Tue Wed Thu Fri Sat


35 4 5 6 7 8 9

10 Video 11 Precept 12 Video 13 Precept 14 15 16

Assignment Assignment
Released Class Meeting Feedback
17 18

Assignment

YOU ARE HERE READ THIS


content based on support lecture videos & reading/
assignment overview;
week’s material prepare for assignment
exams

48
QUIZ!

If I don’t understand a TigerFile test my code is failing, what should I do?

A. Attend of ce hours. why wait until then?


(but a ne option if we can’t resolve it via Ed)
B. Get help from a lab TA.

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

E. Drop the course.

49
fi
fi
QUIZ!

If I don’t understand a key programming concept, what should I do?

A. Attend of ce hours.

B. Get help from a lab TA. intended for debugging questions

C. Post a question on Ed Discussion. best for short, non-interactive, questions

D. Email my preceptor.

E. Copy a classmate’s solution.

50
fi
Q&A

raise your hand and ask ask on Ed


(use ❤ to upvote)

51

You might also like