Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
Computing (Fun)damentalsJULIA GONG && BEN NEWMAN05.02.2019SPLASH – FALL 2019
Who are we?
JULIA GONG BEN NEWMAN
Class of 2021
Mathematical and Computational Science
Class of 2021
Computer Science
the plan
• Boolean Algebra
• Logic Gates
• Computer Number Systems
• Bit Shifting
• Prefix, Infix, Postfix
• LISP Expressions
• Assembly Language
• Recursive Functions
• Graph Theory
• Data Structures
• Interpreting Programs
the plan
• Boolean Algebra
• Logic Gates
• Computer Number Systems
• Bit Shifting
• Prefix, Infix, Postfix
• LISP Expressions
• Assembly Language
• Recursive Functions
• Graph Theory
• Data Structures
• Interpreting Programs
lower-level, systems
higher-level, algorithms
the plan
• Boolean Algebra
• Logic Gates
• Computer Number Systems
• Bit Shifting
• Prefix, Infix, Postfix
• LISP Expressions
• Assembly Language
• Recursive Functions
• Graph Theory
• Data Structures
• Interpreting Programs
lower-level, systems
higher-level, algorithms
the plan
• Boolean Algebra
• Logic Gates
• Computer Number Systems
• Bit Shifting
• Prefix, Infix, Postfix
• LISP Expressions
• Assembly Language
• Recursive Functions
• Graph Theory
• Data Structures
• Interpreting Programs
lower-level, systems
higher-level, algorithms
!!! WOW
CRASH
COURSE !!!
Why 0s and 1s?
Why 0s and 1s? …I will now
multiply
these
numbers…
Why 0s and 1s? …I will now
multiply
these
numbers…
Why 0s and 1s? …00101100
010110101
011101001
01010100…
Why 0s and 1s? …00101100
010110101
011101001
01010100…
To perform computations
quickly, we have to speak fluent computer!
Boolean Algebra
Variables: store values!𝑋 = 0 “false”
𝑌 = 1 “true”
Boolean Algebra
Variables: store values!
Common operations on variables:
• NOT
𝑋 = 0 “false”
𝑌 = 1 “true”
ത𝑋 = 1
Boolean Algebra
Variables: store values!
Common operations on variables:
• NOT
• OR
𝑋 = 0 “false”
𝑌 = 1 “true”
ത𝑋 = 1
𝑋 + 𝑌 = 1
Boolean Algebra
Variables: store values!
Common operations on variables:
• NOT
• OR
• AND
𝑋 = 0 “false”
𝑌 = 1 “true”
ത𝑋 = 1
𝑋 + 𝑌 = 1
𝑋𝑌 = 0
Boolean Algebra
Variables: store values!
Common operations on variables:
• NOT
• OR
• AND
• XOR
𝑋 = 0 “false”
𝑌 = 1 “true”
ത𝑋 = 1
𝑋 + 𝑌 = 1
𝑋𝑌 = 0
𝑋⊕ 𝑌 = 1
Boolean Algebra
Variables: store values!
Common operations on variables:
• NOT
• OR
• AND
• XOR
𝑋 = 0 “false”
𝑌 = 1 “true”
ത𝑋 = 1
𝑋 + 𝑌 = 1
𝑋𝑌 = 0
𝑋⊕ 𝑌 = 1
(also = ത𝑋𝑌 + 𝑋ത𝑌)
Boolean Algebra
Truth Tables! X Y ??
1 1 1
1 0 0
0 1 0
0 0 0
Meme credits: http://www.quickmeme.com/p/3vx72h
Boolean Algebra
Truth Tables! X Y XY
1 1 1
1 0 0
0 1 0
0 0 0
Meme credits: http://www.quickmeme.com/p/3vx72h
Boolean Algebra
Truth Tables!
De Morgan’s Laws!!
𝑋 + 𝑌 = ത𝑋ത𝑌
𝑋𝑌 = ത𝑋 + ത𝑌
X Y XY
1 1 1
1 0 0
0 1 0
0 0 0
Meme credits: http://www.quickmeme.com/p/3vx72h
Logic Gates (like Boolean Algebra, but visual!)
“Circuits”
input
variables
AND
ANDAND
OR
XOR
NOT
NOT
NOT
NOT
Circuit credits: https://drstienecker.com/tech-332/3-logic-circuits-boolean-algebra-and-truth-tables/
Logic Gates (like Boolean Algebra, but visual!)
“Circuits”
input
variables
AND
ANDAND
OR
XOR
NOT
NOT
NOT
Circuit credits: https://drstienecker.com/tech-332/3-logic-circuits-boolean-algebra-and-truth-tables/
Logic Gates (like Boolean Algebra, but visual!)
“Circuits”
input
variables
AND
ANDAND
OR
XOR
NOT
NOT
NOT
NOT
Circuit credits: https://drstienecker.com/tech-332/3-logic-circuits-boolean-algebra-and-truth-tables/
Logic Gates (like Boolean Algebra, but visual!)
“Circuits”
input
variables
AND
ANDAND
OR
XOR
NOT
NOT
NOT
NOT
Circuit credits: https://drstienecker.com/tech-332/3-logic-circuits-boolean-algebra-and-truth-tables/
Logic Gates (like Boolean Algebra, but visual!)
“Circuits”
input
variables
AND
ANDAND
OR
XOR
NOT
NOT
NOT
NOT
Circuit credits: https://drstienecker.com/tech-332/3-logic-circuits-boolean-algebra-and-truth-tables/
Logic Gates (like Boolean Algebra, but visual!)
“Circuits”
input
variables
AND
ANDAND
OR
XOR
NOT
NOT
NOT
NOT
Circuit credits: https://drstienecker.com/tech-332/3-logic-circuits-boolean-algebra-and-truth-tables/
Logic Gates (like Boolean Algebra, but visual!)
“Circuits”
input
variables
AND
ANDAND
OR
XOR
NOT
NOT
NOT
NOT
output
variable
Circuit credits: https://drstienecker.com/tech-332/3-logic-circuits-boolean-algebra-and-truth-tables/
Logic Gates (like Boolean Algebra, but visual!)
“Circuits”
input
variables
AND
ANDAND
OR
XOR
NOT
NOT
NOT
NOT
output
variable
𝑌 = ҧ𝐴𝐵𝐵𝐶 + (𝐵𝐵𝐶 ⊕ 𝐵𝐶)
Circuit credits: https://drstienecker.com/tech-332/3-logic-circuits-boolean-algebra-and-truth-tables/
Computer Number Systems
We’re used to base 10 (decimal)! But there’s…
Computer Number Systems
We’re used to base 10 (decimal)! But there’s…
Like base 2 (binary), 8 (octal), and 16 (hexadecimal)!
Meme credits: https://giphy.com/gifs/moments-part-11thnyggFkrmmc
Computer Number Systems
We’re used to base 10 (decimal)! But there’s…
Like base 2 (binary), 8 (octal), and 16 (hexadecimal)!
Fun fact: colors can be written as hexadecimals (#FFFFFF = white!)
Meme credits: https://giphy.com/gifs/moments-part-11thnyggFkrmmc
Computer Number Systems
4 2 10
= 4 * 10 + 2 * 1
= 4 * 101 + 2 * 100
Computer Number Systems
4 2 16
= 4 * 16 + 2 * 1
= 4 * 161 + 2 * 160
= 6610
Computer Number Systems
4 2 8
= 4 * 8 + 2 * 1
= 4 * 81 + 2 * 80
= 3410
Computer Number Systems
16110 = X8?
84 83 82 81 80
Computer Number Systems
0 0 816110 = X8?
84 83 82 81 80
Computer Number Systems
0 0 2 8
16110 = 2*82
16110 = X8?
84 83 82 81 80
Computer Number Systems
0 0 2 4 8
16110 = 2*82 + 4*81
16110 = X8?
84 83 82 81 80
Computer Number Systems
0 0 2 4 1 8
16110 = 2*82 + 4*81 + 1*80
16110 = X8?
84 83 82 81 80
Computer Number Systems
0 0 2 4 1 8
16110 = 2*82 + 4*81 + 1*80
16110 = X8?
84 83 82 81 80
Always go from big to small!
Computer Number Systems
0 0 2 4 1 8
16110 = 2*82 + 4*81 + 1*80
16110 = X8?
84 83 82 81 80
Always go from big to small!
That’s how things fit ☺Insightful picture credits: https://www.akindjourney.com/articles/big-rocks
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
12 << 2 = 1 * 2 * 2 = 1 * 22 = 4 = 1002
11 << 2 = 3 * 2 * 2 = 3 * 22 = 12 = 11002
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
10100
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
10100
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
1010
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
01010
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
01010
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
01010
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
1010
Circuit credits: http://clipart-library.com/clipart/angel-wings-clip-art-33.htm
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
10100
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
0100
Circuit credits: http://clipart-library.com/clipart/angel-wings-clip-art-33.htm
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
01001
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
01001
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
1001
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
001
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
00100
Bit Shifting
Essentially operations on bits to go between numbers (really fast in a computer!)
Example:
(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))
00100YAY!
Prefix, Infix, Postfix
Prefix, Infix, Postfix
INFIX – what we’re used to!
X * (Y + Z)
Prefix, Infix, Postfix
PREFIX (no parentheses!)
* X + Y Z
INFIX
X * (Y + Z)
Prefix, Infix, Postfix
PREFIX (no parentheses!)
* X + Y Z
INFIX
X * (Y + Z)
Prefix, Infix, Postfix
PREFIX (no parentheses!)
* X + Y Z
INFIX
X * (Y + Z)
Prefix, Infix, Postfix
PREFIX (no parentheses!)
* X + Y Z
INFIX
X * (Y + Z)
Y + Z
Prefix, Infix, Postfix
PREFIX (no parentheses!)
* X + Y Z
INFIX
X * (Y + Z)
X * (Y + Z)
Prefix, Infix, Postfix
PREFIX (no parentheses!)
* X + Y Z
INFIX
X * (Y + Z)
POSTFIX (also no parentheses!)
X Y Z + *
Prefix, Infix, Postfix
PREFIX (no parentheses!)
* X + Y Z
INFIX
X * (Y + Z)
POSTFIX (also no parentheses!)
X Y Z + *
Prefix, Infix, Postfix
PREFIX (no parentheses!)
* X + Y Z
INFIX
X * (Y + Z)
POSTFIX (also no parentheses!)
X Y Z + *
Recursive Functions
Recursive Functions
Recursive Functions
Recursive Functions
Recursive Functions
Recursive Functions
Recursive Functions
Recursive Functions
Recursive Functions Hope someone down
there knows the
solution!
Recursive Functions Hope someone down
there knows the
solution!
Hope someone down
there knows the
solution!
Recursive Functions Hope someone down
there knows the
solution!
Hope someone down
there knows the
solution!
Hope someone down
there knows the
solution!
Recursive Functions
Recursive Functions
DONE
Recursive Functions
DONE
I know what to do with
this already completed
thing!
Recursive Functions
Recursive Functions
Recursive Functions
DONE
Recursive Functions
DO
NE
DO
NE
Recursive Functions
DONE
Recursive Functions
Recursive FunctionsJust finished that off without
knowing what you all did.
Recursive Functions
PLOT TWIST
Just finished that off without
knowing what you all did.
Recursive Functions
They’re all the
same person,
just at different
times!
Just finished that off without
knowing what you all did.
Recursive Functions
1st recursive call2nd call3rdlast
Recursive Functions
How did we know to stop here?
1st recursive call2nd call3rdlast
Recursive Functions
RECUR-
SIVE
CASE
RECUR-
SIVE
CASE
RECUR-
SIVE
CASE
How did we know to stop here? The answer was basic!
BASE
CASE
1st recursive call2nd call3rdlast
Recursive Functions
RECURSIVE SUBSTRUCTURE
Strategy: Ask yourself, “what subproblem should I solve so that, if I knew the answer to that problem, I could solve the whole problem?”
Recursive Functions
RECURSIVE SUBSTRUCTURE
Strategy: Ask yourself, “what subproblem should I solve so that, if I knew the answer to that problem, I could solve the whole problem?”
Recursive Functions
Base case = the simplest “duh” case you know you can solve!
Usually just returning 0, 1, a concrete sum, an empty list, empty string, or something very simple!
Recursive case = oh dear, I have no idea how to solve this entire problem, but let me solve part of it and then get my friends to solve the rest, and then I can do my part.
Recursive Functions
Base case = the simplest “duh” case you know you can solve!
Usually just returning 0, 1, a concrete sum, an empty list, empty string, or something very simple!
Recursive case = oh dear, I have no idea how to solve this entire problem, but let me solve part of it and then get my friends to solve the rest, and then I can do my part. my later self
Recursive Functions
Base case = the simplest “duh” case you know you can solve!
Usually just returning 0, 1, a concrete sum, an empty list, empty string, or something very simple!
Recursive case = oh dear, I have no idea how to solve this entire problem, but let me solve part of it and then get my friends to solve the rest, and then I can do my part. #lifelessons my later self
Recursive Functions: Fibonacci Sequence
fibonacci | 1, 1, 2, 3, 5, 8, 13, 21, …
Recursive Functions: Fibonacci Sequence
fibonacci | 1, 1, 2, 3, 5, 8, 13, 21, …
n | 0, 1, 2, 3, 4, 5, 6, 7, …
Recursive Functions: Fibonacci Sequence
fibonacci(n) | 1, 1, 2, 3, 5, 8, 13, 21, …
n | 0, 1, 2, 3, 4, 5, 6, 7, …
Recursive Functions: Fibonacci Sequence
fibonacci(n) | 1, 1, 2, 3, 5, 8, 13, 21, …
n | 0, 1, 2, 3, 4, 5, 6, 7, …
def fibonacci(n):
if n == 0 or n == 1:
return 1
Recursive Functions: Fibonacci Sequence
fibonacci(n) | 1, 1, 2, 3, 5, 8, 13, 21, …
n | 0, 1, 2, 3, 4, 5, 6, 7, …
def fibonacci(n):
return 1
BASE
CASE
Recursive Functions: Fibonacci Sequence
fibonacci(n) | 1, 1, 2, 3, 5, 8, 13, 21, …
n | 0, 1, 2, 3, 4, 5, 6, 7, …
def fibonacci(n):
if n == 0 or n == 1:
return 1
return fibonacci(n-1) + fibonacci(n-2)
RECUR-
SIVE
CASE
Hope someone down
there knows the
solution!
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
…
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
…
def factorial(n): ?? ?? RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
Recursive Functions: Factorial
def factorial(n):
if ??:
??
else:
??
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
Recursive Functions: Factorial
def factorial(n):
if n == 0 or n == 1:
??
else:
??
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
Recursive Functions: Factorial
def factorial(n):
if n == 0 or n == 1:
return 1
else:
??
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
Recursive Functions: Factorial
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n – 1)
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
3!
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
3!
2!
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
3!
2!
1!
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
3!
2!
1!
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
3!
2!
1!
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
3!
2!
1!
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
3!
2!
1!
Recursive Functions: Factorial
0! = 1
1! = 1
2! = 2 * 1
3! = 3 * 2 * 1
4! = 4 * 3 * 2 * 1
RECUR-
SIVE
CASE
Hope you all can help
me figure out the
solution!
BASE
CASE
3!
2!
1!
Recursive Functions: Tower of Hanoi
move(disk, source, dest, spare):
disk 1
disk 2
disk 3
source spare destination
(initial state)
Recursive Functions: Tower of Hanoi
move(disk, source, dest, spare):
source spare destination
disk 1
disk 2
disk 3
(the goal)
Recursive Functions: Tower of Hanoi
move(disk, source, dest, spare):
if disk == 1:
move disk 1 from source to dest
else if disk > 1:
move(disk – 1, source, spare, dest)
move disk n from source to dest
move(disk – 1, spare, dest, source)
Graph Theory
Modeling systems with individual units and relationships between them
Graph Theory
Modeling systems with individual units and relationships between them
Graph G = (V, E)
V = vertices (nodes)
E = edges (relationship between nodes)
Graph Theory
Modeling systems with individual units and relationships between them• Social media!
nodes: people
edge relation:
“is friends with”
Meme credits: https://www.researchgate.net/figure/Graph-theory-analysis-in-social-network-Image-courtesy-of-5_fig1_321846685
Graph Theory
Modeling systems with individual units and relationships between them• Social media!
• The internet!
Meme credits: https://mathinsight.org/network_introduction
nodes: webpages
edge relation:
“links to”
(in 2004)
Graph Theory
Modeling systems with individual units and relationships between them• Social media!
• The internet!
• Maps (cities and roads)!
nodes: cities
edge relation:
“can be reached from”
Graph Theory
Modeling systems with individual units and relationships between them• Social media!
• The internet!
• Maps (cities and roads)!
• Relationships between words!
nodes: words
edge relation:
“appears in similar contexts as”
Graph Theory
Modeling systems with individual units and relationships between them• Social media!
• The internet!
• Maps (cities and roads)!
• Relationships between words!
• Task lists and dependencies!
nodes: tasks
edge relation:
“must be completed before”
Graph Theory
Modeling systems with individual units and relationships between them• Social media!
• The internet!
• Maps (cities and roads)!
• Relationships between words!
• Task lists and dependencies!
• Job requests on machines!
nodes: job requests
edge relation:
“has higher priority than”
Graph Theory
Modeling systems with individual units and relationships between them• Social media!
• The internet!
• Maps (cities and roads)!
• Relationships between words!
• Task lists and dependencies!
• Job requests on machines!
Graphs can be used for LOTS of things…• Finding shortest paths, longest paths, least costly paths
• Strongly connected components
• Bipartite graphs
• …and soooo much more!
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
AB
CD
E
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
AB
CD
E
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
AB
CD
E
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
AB
CD
E
Arrows = directed graph
No arrows = undirected graph
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
AB
CD
E
Arrows = directed graph
No arrows = undirected graph
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
AB
CD
E
“cycle”
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
Fun fact: this matrix has all paths
of length 1!
If you square this matrix, you get
all paths of length 2! If you
multiply it by itself n times, you
get all paths of length n!
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
And everything along the
diagonal denotes all cycles of
that length!
(“paths of length n from a node
to itself”)
Graph Theory
• Graphs can be represented in many ways! One way is an adjacency matrix:
A
B
C
D
E
A B C D E0 1 0 1 0
0 0 1 1 0
1 0 1 1 1
1 0 0 0 0
0 0 0 1 0
We only have one cycle of length 1, which makes sense!
AB
CD
E
Simple Data Structures
Stacks: first in, last out
Queues: last in, last out
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
1 “push”
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
1“push”
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
2
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
1
“push”
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
23
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
1
“push”
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
234
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
1
“push”
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
2345
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
1
“pop”
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
234
5
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
1
“pop”
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
234
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
1
etc.
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
234
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
on the other hand…
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
1
“enqueue”
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
1
“enqueue”
2
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
1
“enqueue”
2 3
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
1
“enqueue”
2 3 4
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
1
“enqueue”
2 3 4 5
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
1
“dequeue”
2 3 4 5
Simple Data Structures
Stacks: first in, last out (like a stack of plates at the cafeteria)
Queues: last in, last out (like the carpool line or grocery check-out)
Credits to the site that gave me a hand: http://www.clipartpanda.com/clipart_images/light-hand-print-clip-art-at-58133828
“dequeue”
2 3 4 5
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
“panda”, “blueberry”, “cat”
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
1, 2, 3, 4, 5, 6, 7, 8, 9, 100
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
1, 2, 3, 4, 5, 6, 7, 8, 9, 100
Order matters!
Index from 0 to 9, or 1 to 10
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
1, 2, 3, 4, 5, 6, 7, 8, 9, 100
Order matters!
Index from 0 to 9, or 1 to 10
Can be implemented as
stack or queue!
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
a
bc
d
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
a
bc
d
THERE’S NO ORDER!!
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
a
bc
d
THERE’S NO ORDER!!
And all elements are unique
(no duplicates) :’)Meme credits: https://www.memesmonkey.com/topic/unique#&gid=1&pid=7
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
“username”,
“password”,
“name“,
“fav color”
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
value
“username”,
“password”,
“name“,
“fav color”
“cs.is.cool”,
“cantguessthis”,
“brobot“,
“steel gray”
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
value
“username”,
“password”,
“name“,
“fav color”
“cs.is.cool”,
“cantguessthis”,
“brobot“,
“steel gray”
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
Long story, but TL;DR:
Use randomness to get
elements quickly!
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
root
1
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
root
1
0 5
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
root
1
0 5
-2 3½ 7
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
< root
root
1
0 5
-2 3½ 7
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
< root > root
root
1
0 5
-2 3½ 7
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
< root > root
root
1
0 5
-2 3½ 7
works for all nodes!
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
root
1
0 5
-2 3½ 7
2
where to put??
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
root
1
0 5
-2 3½ 7
2
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
root
1
0 5
-2 3½ 7
2
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
root
1
0 5
-2 3½ 7
2
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries
root
1
0 5
-2 3½ 7
2
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• Tries“self-balancing” binary search tree
with cool properties
Simple Data Structures
• LOTS of other cool stuff, including:
• Lists
• Sets
• Maps (dictionaries)
• Hash sets, hash maps, hash tables
• Binary search trees
• Red-black trees
• TriesLike binary search tree, but 3
branches per node
PHEW! And there’s so much more…
PHEW! And there’s so much more…
For some fun ACSL (American Computer Science League)-inspired questions to put the skills you learned to use:
https://web.stanford.edu/~jxgong/splash/computing-fundamentals/
PHEW! And there’s so much more…
But hopefully that gets you excited for the world of CS!!!
Hope you had fun, found this interesting, and are inspired to dig deeper into this awesome field of study ☺
PHEW! And there’s so much more…
But hopefully that gets you excited for the world of CS!!!
Hope you had fun, found this interesting, and are inspired to dig deeper into this awesome field of study ☺
Feel free to ping us with any questions, comments, concerns, good jokes, general advice questions, college advice questions, or anything that’s on your mind!!