Computing (Fun)damentals - Stanford...

191
Computing (Fun)damentals JULIA GONG && BEN NEWMAN 05.02.2019 SPLASH – FALL 2019

Transcript of Computing (Fun)damentals - Stanford...

Page 1: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computing (Fun)damentalsJULIA GONG && BEN NEWMAN05.02.2019SPLASH – FALL 2019

Page 2: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Who are we?

JULIA GONG BEN NEWMAN

Class of 2021

Mathematical and Computational Science

[email protected]

Class of 2021

Computer Science

[email protected]

Page 3: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 4: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 5: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 6: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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 !!!

Page 7: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Why 0s and 1s?

Page 8: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Why 0s and 1s? …I will now

multiply

these

numbers…

Page 9: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Why 0s and 1s? …I will now

multiply

these

numbers…

Page 10: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Why 0s and 1s? …00101100

010110101

011101001

01010100…

Page 11: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Why 0s and 1s? …00101100

010110101

011101001

01010100…

To perform computations

quickly, we have to speak fluent computer!

Page 12: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Boolean Algebra

Variables: store values!𝑋 = 0 “false”

𝑌 = 1 “true”

Page 13: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Boolean Algebra

Variables: store values!

Common operations on variables:

• NOT

𝑋 = 0 “false”

𝑌 = 1 “true”

ത𝑋 = 1

Page 14: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Boolean Algebra

Variables: store values!

Common operations on variables:

• NOT

• OR

𝑋 = 0 “false”

𝑌 = 1 “true”

ത𝑋 = 1

𝑋 + 𝑌 = 1

Page 15: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Boolean Algebra

Variables: store values!

Common operations on variables:

• NOT

• OR

• AND

𝑋 = 0 “false”

𝑌 = 1 “true”

ത𝑋 = 1

𝑋 + 𝑌 = 1

𝑋𝑌 = 0

Page 16: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Boolean Algebra

Variables: store values!

Common operations on variables:

• NOT

• OR

• AND

• XOR

𝑋 = 0 “false”

𝑌 = 1 “true”

ത𝑋 = 1

𝑋 + 𝑌 = 1

𝑋𝑌 = 0

𝑋⊕ 𝑌 = 1

Page 17: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Boolean Algebra

Variables: store values!

Common operations on variables:

• NOT

• OR

• AND

• XOR

𝑋 = 0 “false”

𝑌 = 1 “true”

ത𝑋 = 1

𝑋 + 𝑌 = 1

𝑋𝑌 = 0

𝑋⊕ 𝑌 = 1

(also = ത𝑋𝑌 + 𝑋ത𝑌)

Page 18: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 19: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 20: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 21: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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/

Page 22: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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/

Page 23: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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/

Page 24: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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/

Page 25: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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/

Page 26: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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/

Page 27: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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/

Page 28: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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/

Page 29: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computer Number Systems

We’re used to base 10 (decimal)! But there’s…

Page 30: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 31: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 32: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computer Number Systems

4 2 10

= 4 * 10 + 2 * 1

= 4 * 101 + 2 * 100

Page 33: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computer Number Systems

4 2 16

= 4 * 16 + 2 * 1

= 4 * 161 + 2 * 160

= 6610

Page 34: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computer Number Systems

4 2 8

= 4 * 8 + 2 * 1

= 4 * 81 + 2 * 80

= 3410

Page 35: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computer Number Systems

16110 = X8?

84 83 82 81 80

Page 36: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computer Number Systems

0 0 816110 = X8?

84 83 82 81 80

Page 37: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computer Number Systems

0 0 2 8

16110 = 2*82

16110 = X8?

84 83 82 81 80

Page 38: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computer Number Systems

0 0 2 4 8

16110 = 2*82 + 4*81

16110 = X8?

84 83 82 81 80

Page 39: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Computer Number Systems

0 0 2 4 1 8

16110 = 2*82 + 4*81 + 1*80

16110 = X8?

84 83 82 81 80

Page 40: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 41: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 42: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Page 43: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •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

Page 44: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

Page 45: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

10100

Page 46: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

10100

Page 47: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

1010

Page 48: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

01010

Page 49: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

01010

Page 50: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

01010

Page 51: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 52: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

10100

Page 53: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 54: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

01001

Page 55: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

01001

Page 56: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

1001

Page 57: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

001

Page 58: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

00100

Page 59: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Bit Shifting

Essentially operations on bits to go between numbers (really fast in a computer!)

Example:

(LSHIFT-2(LCIRC-2(RSHIFT-1 10100)))

00100YAY!

Page 60: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

Page 61: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

INFIX – what we’re used to!

X * (Y + Z)

Page 62: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

PREFIX (no parentheses!)

* X + Y Z

INFIX

X * (Y + Z)

Page 63: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

PREFIX (no parentheses!)

* X + Y Z

INFIX

X * (Y + Z)

Page 64: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

PREFIX (no parentheses!)

* X + Y Z

INFIX

X * (Y + Z)

Page 65: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

PREFIX (no parentheses!)

* X + Y Z

INFIX

X * (Y + Z)

Y + Z

Page 66: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

PREFIX (no parentheses!)

* X + Y Z

INFIX

X * (Y + Z)

X * (Y + Z)

Page 67: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

PREFIX (no parentheses!)

* X + Y Z

INFIX

X * (Y + Z)

POSTFIX (also no parentheses!)

X Y Z + *

Page 68: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

PREFIX (no parentheses!)

* X + Y Z

INFIX

X * (Y + Z)

POSTFIX (also no parentheses!)

X Y Z + *

Page 69: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Prefix, Infix, Postfix

PREFIX (no parentheses!)

* X + Y Z

INFIX

X * (Y + Z)

POSTFIX (also no parentheses!)

X Y Z + *

Page 70: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 71: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 72: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 73: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 74: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 75: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 76: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 77: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 78: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions Hope someone down

there knows the

solution!

Page 79: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions Hope someone down

there knows the

solution!

Hope someone down

there knows the

solution!

Page 80: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions Hope someone down

there knows the

solution!

Hope someone down

there knows the

solution!

Hope someone down

there knows the

solution!

Page 81: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 82: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

DONE

Page 83: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

DONE

I know what to do with

this already completed

thing!

Page 84: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 85: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 86: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

DONE

Page 87: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

DO

NE

DO

NE

Page 88: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

DONE

Page 89: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

Page 90: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive FunctionsJust finished that off without

knowing what you all did.

Page 91: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

PLOT TWIST

Just finished that off without

knowing what you all did.

Page 92: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

They’re all the

same person,

just at different

times!

Just finished that off without

knowing what you all did.

Page 93: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

1st recursive call2nd call3rdlast

Page 94: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions

How did we know to stop here?

1st recursive call2nd call3rdlast

Page 95: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 96: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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?”

Page 97: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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?”

Page 98: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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.

Page 99: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 100: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 101: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions: Fibonacci Sequence

fibonacci | 1, 1, 2, 3, 5, 8, 13, 21, …

Page 102: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions: Fibonacci Sequence

fibonacci | 1, 1, 2, 3, 5, 8, 13, 21, …

n | 0, 1, 2, 3, 4, 5, 6, 7, …

Page 103: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions: Fibonacci Sequence

fibonacci(n) | 1, 1, 2, 3, 5, 8, 13, 21, …

n | 0, 1, 2, 3, 4, 5, 6, 7, …

Page 104: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 105: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 106: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 107: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions: Factorial

0! = 1

1! = 1

2! = 2 * 1

3! = 3 * 2 * 1

4! = 4 * 3 * 2 * 1

Page 108: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 109: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions: Factorial

def factorial(n):

if ??:

??

else:

??

RECUR-

SIVE

CASE

Hope you all can help

me figure out the

solution!

BASE

CASE

Page 110: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 111: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 112: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 113: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 114: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 115: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 116: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 117: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 118: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 119: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 120: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 121: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions: Tower of Hanoi

move(disk, source, dest, spare):

disk 1

disk 2

disk 3

source spare destination

(initial state)

Page 122: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Recursive Functions: Tower of Hanoi

move(disk, source, dest, spare):

source spare destination

disk 1

disk 2

disk 3

(the goal)

Page 123: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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)

Page 124: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Graph Theory

Modeling systems with individual units and relationships between them

Page 125: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Graph Theory

Modeling systems with individual units and relationships between them

Graph G = (V, E)

V = vertices (nodes)

E = edges (relationship between nodes)

Page 126: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 127: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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)

Page 128: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 129: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 130: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 131: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 132: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 133: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Graph Theory

• Graphs can be represented in many ways! One way is an adjacency matrix:

Page 134: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 135: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 136: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 137: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 138: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 139: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 140: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 141: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 142: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 143: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 144: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Simple Data Structures

Stacks: first in, last out

Queues: last in, last out

Page 145: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

Simple Data Structures

Stacks: first in, last out (like a stack of plates at the cafeteria)

Queues: last in, last out

Page 146: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 147: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 148: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 149: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 150: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 151: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 152: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 153: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 154: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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…

Page 155: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 156: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 157: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 158: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 159: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 160: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 161: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 162: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 163: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 164: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 165: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 166: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 167: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 168: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!!

Page 169: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 170: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 171: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 172: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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”

Page 173: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 174: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 175: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 176: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 177: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 178: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 179: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!

Page 180: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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??

Page 181: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 182: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 183: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 184: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 185: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 186: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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

Page 187: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

PHEW! And there’s so much more…

Page 188: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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/

Page 189: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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 ☺

Page 190: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer

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!!

[email protected] + [email protected]

Page 191: Computing (Fun)damentals - Stanford Universityweb.stanford.edu/~jxgong/splash/computing-fundamentals/... · 2019. 11. 19. · the plan •Boolean Algebra •Logic Gates •Computer