Lecture 0
Lecture 0
Neel Guha Rachel Han Stanley Cao Trevor Carrell Zachary Chen
(TA) (TA) (TA) (TA) (TA)
https://cs103.stanford.edu
CS106B
Some problem sets will have small There aren't any math
coding components. We’ll also prerequisites for this course.
reference some concepts from High-school algebra should
CS106B, particularly recursion,
be enough!
throughout the quarter.
Another Option
CS154
CS154 is more appropriate if you
have a background in the topics
from the first half of this quarter
(set theory, proofwriting, discrete
math, formal logic, graphs, etc.)
Come talk to me after class if
you’re curious about this!
CS103 ACE
●
CS103 ACE is an optional, one-unit
companion course to CS103.
●
CS103 ACE meets Tuesdays, 3:00PM –
4:50PM and provides additional
practice with the course material in a
small group setting.
●
The first course meeting is this Friday,
and that meeting is open to everyone.
Elena Sierra
●
Interested? Apply online using (ACE Instructor)
this link.
●
The CS103 ACE materials are
available to everyone. You can pull
them up here.
Problem Set 0
●
Your first assignment, Problem Set 0,
goes out today. It’s due Friday at 1:00PM
Pacific.
●
This assignment requires you to set up
your development environment and to
get set up on GradeScope and EdStem.
●
There’s no coding involved, but it’s good
to start early in case you encounter any
technical issues.
Recommended Reading
Grading
Assignments
Midterm 1
Midterm 2
Final Exam
Participation
Completed individually or
in pairs.
Grading
Assignments
Midterm 1
Midterm 2
Final Exam
Participation
Assignments
Midterm 1
Midterm 2
Final Exam
Participation
Assignments
Midterm 1
Midterm 2
Final Exam
Participation
Final Exam
Assignments
Midterm 1
Midterm 2
Final Exam
Participation
Lecture Participation
“Cool people”
“The chemical elements”
“Cute animals”
“US coins”
, , ,
Set notation: Curly braces
with commas separating out
the elements
Set
This is a set
Ø with the empty {Ø}
set in it.
{ n | n ∈ ℕ and n is even }
where
n is a natural
number
and n is even
1 4
3 A
2 5
A B
A = { 1, 2, 3 }
B = { 3, 4, 5 }
Venn Diagrams
1 4
3 B
2 5
A B
A = { 1, 2, 3 }
B = { 3, 4, 5 }
Venn Diagrams
1 4
Union
3 A∪B
2 5 { 1, 2, 3, 4, 5 }
A B
A = { 1, 2, 3 }
B = { 3, 4, 5 }
Venn Diagrams
1 4
Intersection
3 A∩B
2 5 {3}
A B
A = { 1, 2, 3 }
B = { 3, 4, 5 }
Venn Diagrams
1 4
Difference
3 A–B
2 5 { 1, 2 }
A B
A = { 1, 2, 3 }
B = { 3, 4, 5 }
Venn Diagrams
1 4
Difference
3 A\B
2 5 { 1, 2 }
A B
A = { 1, 2, 3 }
B = { 3, 4, 5 }
Venn Diagrams
1 4 Symmetric
Difference
3 AΔB
2 5 { 1, 2, 4, 5 }
A B
A = { 1, 2, 3 }
B = { 3, 4, 5 }
Venn Diagrams
A B
AΔB
Subsets and Power Sets
Subsets
●
A set S is called a subset of a set T
(denoted S ⊆ T) when all elements of S
are also elements of T.
●
Examples:
●
{ 1, 2, 3 } ⊆ { 1, 2, 3, 4 }
●
{ b, c } ⊆ { a, b, c, d }
●
{ H, He, Li } ⊆ { H, He, Li }
●
ℕ ⊆ ℤ (every natural number is an integer)
●
ℤ ⊆ ℝ (every integer is a real number)
Subsets and Elements
Set S
{2}
2
S = { 2, , {2}, , }
Subsets and Elements
Set S
{2}
2
General intuition:
x ∈ S means you
can point at x {2} ∈ S
inside of S.
Subsets and Elements
Set S
{2}
2
{ , 2} ⊆ S
Subsets and Elements
Set S
{2}
2
{ , 2} ∉ S
Subsets and Elements
Set S
{2}
2
{ 2 }∈ S
Subsets and Elements
Set S
{2}
2
General intuition:
A ⊆ B if you can
form A by circling
elements of B. { 2 }⊆ S
Subsets and Elements
Set S
{2}
2
(Since 2
2 ⊆S isn't a set.)
Subsets and Elements
Set S
{2}
2
Ø ⊆ S
Subsets and Elements
Set S
{2}
2
Ø ∉ S
Subsets and Elements
●
We say that S ∈ T when, among the elements of T,
one of them is exactly the object S.
●
We say that S ⊆ T when S is a set and every
element of S is also an element of T. (S has to be a
set for the statement S ⊆ T to be true.)
●
Although these concepts are similar, they are not
the same! Not all elements of a set are subsets of
that set and vice-versa.
●
We have a resource on the course website, the
Guide to Elements and Subsets, that explores this
in more depth.
S= ,
℘(S) =
Ø, , , ,
This is the power set of S, the set of
all subsets of S. We write the power
set of S as ℘(S).
Formally, ℘(S) = { T | T ⊆ S }.
(Do you see why?)
What is ℘(Ø)?
Answer: {Ø}
, , ,
, , ,
Comparing Cardinalities
●
If S and T are sets, we say that |S| = |T|
when there is a way of pairing off the
elements of S and T without leaving
anything uncovered.
, , ,
, , ,
Comparing Cardinalities
●
If S and T are sets, we say |S| < |T| when,
no matter how you pair off the elements
of S and T, there’s always at least one
element of T left uncovered.
, ,
, , ,
Infinite Cardinalities
ℕ 0 1 2 3 4 5 6 7 8 ...
ℤ 0 -1 1 -2 2 -3 3 -4 4 ...
|ℕ| = |ℤ| = ℵ0
… … … … … … … …
...
|Programs| ≤ |Strings|
Strings and Problems
●
There is a connection between the number
of sets of strings and the number of
problems to solve.
●
Let S be any set of strings. This set S gives
rise to a problem to solve:
Given a string w, determine whether w ∈ S.
Strings and Problems
Given a string w, determine whether w ∈ S.
●
Suppose that S is the set
S = { "a", "b", "c", …, "z" }
●
From this set S, we get this problem:
Given a string w, determine whether
w is a single lower-case English letter.
Strings and Problems
Given a string w, determine whether w ∈ S.
●
Suppose that S is the set
S = { "0", "1", "2", …, "9", "10", "11", ... }
●
From this set S, we get this problem:
Given a string w, determine whether
w represents a natural number.
Strings and Problems
Given a string w, determine whether w ∈ S.
●
Suppose that S is the set
S = { p | p is a legal C++ program }
●
From this set S, we get this problem:
Given a string w, determine whether
w is a legal C++ program.
Strings and Problems
●
Every set of strings gives rise to a unique
problem to solve.
●
Other problems exist as well.
|℘(Strings)| ≤ |Problems|