Programmers waste enormous amounts of time thinking about, or - - PowerPoint PPT Presentation

programmers waste enormous amounts of time thinking about
SMART_READER_LITE
LIVE PREVIEW

Programmers waste enormous amounts of time thinking about, or - - PowerPoint PPT Presentation

Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at e ffi ciency actually have a strong negative impact when debugging and maintenance are


slide-1
SLIDE 1

“Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature

  • ptimization is the root of all evil. Yet we should not pass up our
  • pportunities in that critical 3%."

—Don Knuth

slide-2
SLIDE 2

Write the tabulation template for fjb

Name

(your response)

  • Th. 11/8
slide-3
SLIDE 3

make-change, infjnite coins

Given a value and a set of coins, what is the minimum number of coins required to sum to the value, assuming we have an infinite number of each coin?

slide-4
SLIDE 4

The longest-common substring of s1 and s2 is the longest string that is a non-consecutive substring of both s1 and s2.

longest-common substring (LCS)

lcs('x', 'y') == 0 lcs('x', '') == 0 lcs('', 'x') == 0 lcs('car', 'cat') == 2 lcs('human', 'chimpanzee') == 4

How similar are these strings?

slide-5
SLIDE 5

How many times does the platypus quack?

Tieoretical tools: code → math

for (int i=0; i<N; i++) { for (int j=0; j<N; j++) { platypus.quack() } }

slide-6
SLIDE 6

How many times does the platypus quack?

Tieoretical tools: code → math

for (int i=0; i<N; i++) { for j in range(N): platypus.quack() } }

slide-7
SLIDE 7

upper-bound


(inclusive)

lower-bound


(inclusive)

index

(implicit increment)

Tieoretical tools: code → math

summations

slide-8
SLIDE 8

summations

Tieoretical tools: code → math

for (int i=0; i<N; i++) { for j in range(N): platypus.quack() } }

N−1

X

j=0

1

slide-9
SLIDE 9

summations

Tieoretical tools: code → math

N−1

X

j=0

1

upper-bound
 (inclusive) lower-bound
 (inclusive) index (implicit increment)

j cost 1 1 1 2 1 3 1 … … N-2 1 N-1 1 N ∈O(N)

slide-10
SLIDE 10

summations

Tieoretical tools: code → math

i cost 1 1 2 1 3 1 4 1 … … N-1 1 N 1 N ∈O(N)

slide-11
SLIDE 11

summations

Tieoretical tools: code → math

i cost 1 N 2 N 3 N 4 N … … N-1 N N N N2 ∈O(N2)

slide-12
SLIDE 12

summations

Tieoretical tools: code → math

i cost 1 1 2 2 3 3 4 4 … … N-1 N-1 N N ∈O(N2)

slide-13
SLIDE 13

How many times does the platypus quack?

Tieoretical tools: code → math

sum 1,j=0 to N-1

code math Wolfram Alpha closed form asymptotic notation

N−1

X

j=0

1

N

O(N)

for j in range(N): platypus.quack()

slide-14
SLIDE 14

How many times does the platypus quack?

Tieoretical tools: code → math

for i in range(N): for j in range(N): platypus.quack() } }

slide-15
SLIDE 15

How many times does the platypus quack?

Tieoretical tools: code → math

N−1

X

i=0 N−1

X

j=0

1

sum (sum 1,j=0 to N-1),i=0 to N-1

N 2 O(N 2)

code math Wolfram Alpha closed form asymptotic notation

for i in range(N): for j in range(N): platypus.quack()

} }

slide-16
SLIDE 16

How many times does the platypus quack?

Tieoretical tools: code → math

for i in range(N): for j in range(i, N): platypus.quack() } }

slide-17
SLIDE 17

How many times does the platypus quack?

Tieoretical tools: code → math

for i in range(N): for j in range(i, N): platypus.quack() } }

sum (sum 1,j=i to N-1),i=0 to N-1

O(N 2)

code math Wolfram Alpha closed form asymptotic notation

N−1

X

i=0 N−1

X

j=i

1

N(N + 1) 2