Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... ·...

126
Welcome to CS106B! Three Handouts Today: Course Overview Where are We Going? Introduction to C++

Transcript of Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... ·...

Page 1: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Welcome to CS106B!

● Three Handouts● Today:

● Course Overview● Where are We Going?● Introduction to C++

Page 2: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Who's Here Today?● African Studies● Applied Physics● Bioengineering● Biology● Business Administration● Chemical Engineering● Chemistry● Classics● Civil and Environmental

Engineering● Computational and

Mathematical Engineering

● Computer Science● Creative Writing● East Asian Studies● Economics

● Mechanical Engineering

● Medicine● Management Science

and Engineering● Modern Language● Music● Neuroscience● Physics● Political Science● Psychology● Science, Technology,

and Society● Statistics● Symbolic Systems● Undeclared!

● Education● Electrical Engineering● Energy Resource

Engineering● English● Financial Mathematics● Film and Media Studies● French● History● International Relations● Japanese● Law● Materials Science and

Engineering● Mathematical and

Computational Sciences● Mathematics

Page 3: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Course Staff

Instructor: Keith Schwarz([email protected])

Head TA: Dawson Zhou([email protected])

The CS106B Section LeadersThe CS106B Course Helpers

Page 4: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

http://cs106b.stanford.edu

Course Website

Page 5: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Prerequisites

CS106A(or equivalent)

Page 6: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Required Reading

Page 7: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Grading Policies

Page 8: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Grading Policies

55% Assignments20% First Midterm20% Second Midterm5% Section Participation

Page 9: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Grading Policies

55% Assignments20% First Midterm20% Second Midterm5% Section ParticipationSeven Programming

Assignments

Page 10: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Grading Policies

55% Assignments20% First Midterm20% Second Midterm5% Section Participation

Page 11: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Grading Policies

55% Assignments20% First Midterm20% Second Midterm5% Section Participation

First Midterm Exam

Tuesday, May 77PM – 10PM

Page 12: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Grading Policies

55% Assignments20% First Midterm20% Second Midterm5% Section Participation

Page 13: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Grading Policies

55% Assignments20% First Midterm20% Second Midterm5% Section Participation

Second Midterm Exam

Tuesday, May 287PM – 10PM

Page 14: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Grading Policies

55% Assignments20% First Midterm20% Second Midterm5% Section Participation

Page 15: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Discussion Sections

● Weekly discussion sections.● Section attendance is required in CS106B.● Sign up between Thursday, April 4 at 5:00PM

and Sunday, April 7 at 5:00PM at

http://cs198.stanford.edu/section ● You don't need to (and shouldn't!) sign up for a

section on Axess; everything is handled through the above link.

Page 16: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

How Many Units?

Page 17: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

How Many Units?

int numUnits(bool isGrad, bool wantsFewerUnits) {

if (!isGrad) return 5; if (!wantsFewerUnits) return 5; if (reallyBusy()) {

return 3; } else {

return 4; }}

Page 18: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

How Many Units?

int numUnits(bool isGrad, bool wantsFewerUnits) {

if (!isGrad) return 5; if (!wantsFewerUnits) return 5; if (reallyBusy()) {

return 3; } else {

return 4; }}

Page 19: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

How Many Units?

int numUnits(bool isGrad, bool wantsFewerUnits) {

if (!isGrad) return 5; if (!wantsFewerUnits) return 5; if (reallyBusy()) {

return 3; } else {

return 4; }}

Page 20: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

How Many Units?

int numUnits(bool isGrad, bool wantsFewerUnits) {

if (!isGrad) return 5; if (!wantsFewerUnits) return 5; if (reallyBusy()) {

return 3; } else {

return 4; }}

Page 21: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

How Many Units?

int numUnits(bool isGrad, bool wantsFewerUnits) {

if (!isGrad) return 5; if (!wantsFewerUnits) return 5; if (reallyBusy()) {

return 3; } else {

return 4; }}

Page 22: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Getting Help

Page 23: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where
Page 24: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Getting Help

● LaIR Hours!● Sunday – Thursday, 6PM – Midnight● Starts next week.

● Dawson's Office Hours in Gates 160● Monday/Wednesday 11AM – Noon● Tuesday/Thursday 1PM – 2PM

● Keith's Office Hours in Gates 178● Tuesday / Thursday, 2PM – 4PM

Page 25: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

What's Next in Computer Science?

Page 26: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Goals for this Course

● Learn how to model and solve complex problems with computers.

● To that end:● Explore common abstractions for

representing problems.● Harness recursion and understand how to

think about problems recursively.● Quantitatively analyze different approaches

for solving problems.

Page 27: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Goals for this Course

Learn how to model and solve complex problems with computers.

To that end:● Explore common abstractions for

representing problems.

Harness recursion and understand how to think about problems recursively.

Quantitatively analyze different approaches for solving problems.

Page 28: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

http://www.publicdomainpictures.net/pictures/10000/velka/1-1265899974oKJ9.jpg

Page 29: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

http://www.publicdomainpictures.net/pictures/10000/velka/1-1265899974oKJ9.jpg

Page 30: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Sentence

Subject Verb Phrase Object

CS106B

Adverb Verb Possessive Noun

totally rocks my socks

Noun

Page 31: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

http://www.virginia.gov/images/wholeexecbranch2.jpg

Page 32: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where
Page 33: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where
Page 34: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where
Page 35: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where
Page 36: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

http://en.wikipedia.org/wiki/File:Tree_of_life_SVG.svg

Hey, that's us!

Hey, that's us!

Page 37: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where
Page 38: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Building a vocabulary of abstractions makes it possible to represent and

solve a wider class of problems.

Page 39: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Goals for this Course

● Learn how to model and solve complex problems with computers.

● To that end:● Explore common abstractions for

representing problems.● Harness recursion and understand how to

think about problems recursively.● Quantitatively analyze different approaches

for solving problems.

Page 40: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Goals for this Course

Learn how to model and solve complex problems with computers.

To that end:

Explore common abstractions for representing problems.

● Harness recursion and understand how to think about problems recursively.

Quantitatively analyze different approaches for solving problems.

Page 41: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

http://www.marketoracle.co.uk/images/2010/Oct/fractal-tree2.jpg

Page 42: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

http://1.bp.blogspot.com/-Hwf-U9hRwEI/TX480ONoo6I/AAAAAAAAAcM/fyBi0I5HsUI/s1600/the_great_wave_off_kanagawa.jpg

Page 43: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where
Page 44: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

Page 45: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

Page 46: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

.

. .

Width 1

Width 2

Page 47: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

. . . . . . .

Page 48: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

. . . . . . .

Page 49: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

. . . . . . .

Page 50: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

. . . . . . .

Page 51: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

. . . . . . .

Page 52: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

. . . . . . .

Page 53: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

. . . . . . .

Page 54: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Finding the Midpoint

● If the width is 1, Karel is standing on the midpoint.

● If the width is 2, either position can be considered the midpoint.

● Otherwise:● Take two steps forward.● Find the midpoint of the rest of the world.● Take one step backward.

Page 55: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

A Surprisingly Short Solution

Page 56: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

A recursive solution is a solution that is defined in terms of itself.

Page 57: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Thinking recursively allows youto solve an enormous class of

problems cleanly and concisely.

Page 58: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Goals for this Course

● Learn how to model and solve complex problems with computers.

● To that end:● Explore common abstractions for

representing problems.● Harness recursion and understand how to

think about problems recursively.● Quantitatively analyze different approaches

for solving problems.

Page 59: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Goals for this Course

Learn how to model and solve complex problems with computers.

To that end:

Explore common abstractions for representing problems.

Harness recursion and understand how to think about problems recursively.

● Quantitatively analyze different approaches for solving problems.

Page 60: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

Page 61: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 62: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 63: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Travel Time: 13 + 15 + 17 + 14 + 11 + 9 + 12 = 91

Page 64: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 65: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Travel Time: 10 + 17 + 7 + 14 + 13 + 4 + 7 = 72

Page 66: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 67: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 68: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 69: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 70: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

In an n × n grid, there are at least 4n / n possible paths from one

corner to another.

If n = 154, this is approximately equal to the number of atoms in

the universe.

In an n × n grid, there are at least 4n / n possible paths from one

corner to another.

If n = 154, this is approximately equal to the number of atoms in

the universe.

Page 71: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

In an n × n grid, there are at least 4n / n possible paths from one

corner to another.

If n = 50, it would take the lifetime of the universe to list off all

possible paths.

In an n × n grid, there are at least 4n / n possible paths from one

corner to another.

If n = 50, it would take the lifetime of the universe to list off all

possible paths.

Page 72: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

In an n × n grid, there are at least 4n / n possible paths from one

corner to another.

If n = 50, it would take the lifetime of the universe to list off all

possible paths.

In an n × n grid, there are at least 4n / n possible paths from one

corner to another.

If n = 50, it would take the lifetime of the universe to list off all

possible paths.

Page 73: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 74: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

010 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 75: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

010 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 76: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10?

13?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 77: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10?

13?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

10?

Page 78: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

13?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 79: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

17?13?

27?10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 80: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

17?13?

27?10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

13?

Page 81: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

17?13

27?10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 82: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

17?13

27?

28?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 83: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

17?13

27?

28?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

17?

Page 84: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

27?

28?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 85: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

27?

28?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

27?

Page 86: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

27?

22?

28? 27?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 87: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

27?

22

28? 27?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 88: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25?

40?22

28? 27? 29?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 89: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25

40?22

28? 27? 29?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 90: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32?

40?22

28? 27? 29?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 91: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32?

40?22

28? 27 29?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 92: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32?

40?22

28? 27

40?

29?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 93: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32?

40?22

28 27

40?

29?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 94: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32?

40?22

28 27

40?45?

29?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 95: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32?

40?22

28 27

40?45?

29

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 96: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32?

40?22

28 27

40?45?

29 36?

38?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 97: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

40?22

28 27

40?45?

29 36?

38?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 98: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

40?22

28 27

40?45?

29 36?

38?

46?10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 99: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

40?22

28 27

40?45?

29 36

38?

46?10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 100: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

38?22

28 27

40?45?

29 36

50?38?

46?

56?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 101: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

38?22

28 27

40?45?

29 36

50?38

46?

56?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 102: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

38?22

28 27

40?45?

29 36

47?38

46?

56?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 103: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

40?45?

29 36

47?38

46?

56?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 104: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

40?45?

29 36

47?38

46?

42?

56?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 105: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045?

29 36

47?38

46?

42?

56?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 106: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045?

29 36

47?38

46?

42

56?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 107: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045?

29 36

47?38

46?

42

46?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 108: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

47?38

46?

42

46?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 109: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

47?38

46?

42

46

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 110: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

47?38

46?

42

46

53?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 111: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

47?38

46

42

46

53?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 112: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

4738

46

42

46

53?

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 113: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

4738

46

42

46

53

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 114: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

4738

46

42

46

53

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

Page 115: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

4738

46

42

46

53

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

This approach is calledDijkstra's Algorithm.

Google Maps uses a slightly modified version of this algorithm.

For an n × n grid, it requires (roughly speaking) n log n

operations to find the shortest path.

This approach is calledDijkstra's Algorithm.

Google Maps uses a slightly modified version of this algorithm.

For an n × n grid, it requires (roughly speaking) n log n

operations to find the shortest path.

Page 116: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

4738

46

42

46

53

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

This approach is calledDijkstra's Algorithm.

Google Maps uses a slightly modified version of this algorithm.

For an n × n grid, it requires (roughly speaking) n log n

operations to find the shortest path.

This approach is calledDijkstra's Algorithm.

Google Maps uses a slightly modified version of this algorithm.

For an n × n grid, it requires (roughly speaking) n log n

operations to find the shortest path.

Page 117: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

0 10

1713

25 32

3822

28 27

4045

29 36

4738

46

42

46

53

10 717 14

6

14

5

5 18 4

11 9 12

8 7 20

13

15

17

7 37 9 13

7

7

9

10 2

14

4

713

from    

    to

This approach is calledDijkstra's Algorithm.

Google Maps uses a slightly modified version of this algorithm.

For an n × n grid, it requires some multiple of n2 log n operations to

find the shortest path.

This approach is calledDijkstra's Algorithm.

Google Maps uses a slightly modified version of this algorithm.

For an n × n grid, it requires some multiple of n2 log n operations to

find the shortest path.

Page 118: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Goals for this Course

● Learn how to model and solve complex problems with computers.

● To that end:● Explore common abstractions for

representing problems.● Harness recursion and understand how to

think about problems recursively.● Quantitatively analyze different approaches

for solving problems.

Page 119: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Who's Here Today?● African Studies● Applied Physics● Bioengineering● Biology● Business Administration● Chemical Engineering● Chemistry● Classics● Civil and Environmental

Engineering● Computational and

Mathematical Engineering

● Computer Science● Creative Writing● East Asian Studies● Economics

● Mechanical Engineering

● Medicine● Management Science

and Engineering● Modern Language● Music● Neuroscience● Physics● Political Science● Psychology● Science, Technology,

and Society● Statistics● Symbolic Systems● Undeclared!

● Education● Electrical Engineering● Energy Resource

Engineering● English● Financial Mathematics● Film and Media Studies● French● History● International Relations● Japanese● Law● Materials Science and

Engineering● Mathematical and

Computational Sciences● Mathematics

Page 120: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

One more detail...

Page 121: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

C + +

Page 122: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

What is C++?

● Programming language developed in 1983 by Bjarne Stroustrup.

● Widely used for general programming when performance is important.

● Supports a variety of programming styles.

Page 123: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

/* File: hello-world.cpp * * A canonical Hello, world! program * in C++. */

#include <iostream>using namespace std;

int main() { cout << "Hello, world!" << endl;}

Page 124: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

/* File: retain-evens.cpp * * A program to filter out odd numbers from a list. */#include <iostream>#include "vector.h"using namespace std;

Vector<int> retainEvens(Vector<int> values) { Vector<int> result; for (int i = 0; i < values.size(); i++) { if (values[i] % 2 == 0) result += values[i]; } return result;}

int main() { Vector<int> values; values += 1, 2, 3, 4, 5;

Vector<int> processed = retainEvens(values);

for (int i = 0; i < processed.size(); i++) { cout << processed[i] << endl; }}

Page 125: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

CS106L

● Optional, one-unit companion course to CS106B.

● In-depth treatment of C++'s libraries and language features.

● Excellent complement to the material from CS106B; highly recommended!

● Not a replacement for section; it's purely an add-on.

Page 126: Welcome to CS106B! - Stanford Universityweb.stanford.edu/class/archive/cs/cs106b/cs106b.1136/... · 2013. 4. 2. · Welcome to CS106B! Three Handouts Today: Course Overview Where

Next Time

● Welcome to C++!● Defining functions.● Reference parameters.● Introduction to recursion.