Maximum Contiguous Subsequence Sum After todays class you will be - - PowerPoint PPT Presentation

maximum contiguous subsequence sum
SMART_READER_LITE
LIVE PREVIEW

Maximum Contiguous Subsequence Sum After todays class you will be - - PowerPoint PPT Presentation

Tie Day #1. Log your bonus points in Moodle Maximum Contiguous Subsequence Sum After todays class you will be able to: state and solve the MCSS problem on small arrays by observation find the exact runtimes of the naive MCSS algorithms


slide-1
SLIDE 1

Maximum Contiguous Subsequence Sum

After today’s class you will be able to:

state and solve the MCSS problem on small arrays by observation find the exact runtimes of the naive MCSS algorithms

Tie Day #1. Log your bonus points in Moodle

https://openclipart.org/image/2400px/svg_to_png/169467/bow_tie.png

slide-2
SLIDE 2

 Consider the limit  What does it say about asymptotic relationship

between f and g if this limit is…

  • 0?
  • finite and non-zero?
  • infinite?

) ( ) (

lim

n g n f n  

Q12, day 2

slide-3
SLIDE 3
  • 1. n and n2
  • 2. log n and n (on these questions and solutions

ONLY, let log n mean natural log)

  • 3. n log n and n2
  • 4. logan and logbn (a < b)
  • 5. na and an (a > 1)
  • 6. an and bn (a < b)

Recall l’Hôpital’s rule: under appropriate conditions,

Q13-15

slide-4
SLIDE 4

A deceptively deep problem with a surprising solution. {-3, 4, 2, 1, -8, -6, 4, 5, -2}

Q1

slide-5
SLIDE 5

 It’s interesting  Analyzing the obvious solution is instructive  We can make the program more efficient

slide-6
SLIDE 6

 Proble

blem: Given a sequence of numbers, find the maximum sum of a contiguous subsequence.

 Consider

der:

  • What if all the numbers were positive?
  • What if they all were negative?
  • What if we left out “contiguous”?
slide-7
SLIDE 7

 Quiz questions:

  • In {-2, 11, -4, 13, -5, 2}, S2,4 = ?
  • In {1, -3, 4, -2, -1, 6}, what is MCSS?
  • If every element is negative, what’s the MCSS?

1-based indexing. We’ll use when analyzing b/c easier

Q2 Q2-4

slide-8
SLIDE 8
  • Must be easy to explain
  • Efficiency doesn’t matter.
  • 3 minutes

 Examples to consider:

  • {-3, 4, 2, 1, -8, -6, 4, 5, -2}
  • {5, 6, -3, 2, 8, 4, -12, 7, 2}

Q5 Q5

slide-9
SLIDE 9

Where will this algorithm spend the most time?

How many times (exactly, as a function of N = a.length) will that statement execute?

i: beginni nning ng of subseque uenc nce j: end of subseque uenc nce k: steps throug ugh h each h element ent of subsequenc uence

Find d the sums ms of all subse bsequ quence ces

slide-10
SLIDE 10

 What statement is executed the most often?  How many times?  How many triples, (i,j,k) with 1≤i≤k≤j≤n ? Outer numbers could be 0 and n – 1, and we'd still get the same answer.

slide-11
SLIDE 11

 By hand  Using Maple

slide-12
SLIDE 12

 How many triples, (i,j,k) with 1≤i≤k≤j≤n ?  What is that as a summation?

  • Can also just get from code

 Let’s solve it by hand to practice with sums

Q6, Q7

slide-13
SLIDE 13

 When it gets down to “just Algebra”, Maple is

  • ur friend
slide-14
SLIDE 14
slide-15
SLIDE 15
slide-16
SLIDE 16
slide-17
SLIDE 17

 Computer Science is no more about

computers than astronomy is about . Donald Knuth

slide-18
SLIDE 18

 Computer Science is no more about

computers than astronomy is about telescopes. Donald Knuth

slide-19
SLIDE 19

Observe that

𝑜(𝑜+1)(𝑜+2) 6

= 𝑜 + 2 3 , from basic counting/probability

 The textbook makes use of this in a curious

way to find the sum more easily. Fun, but not required for class.

slide-20
SLIDE 20

 We showed MCSS is O(n3).

  • Showing that a problem is O(g(n)) is relatively easy – just

analyze a known algorithm.

 Is MCSS W(n3)?

  • Showing that a problem is W (g(n)) is much tougher. How do

you prove that it is impossible to solve a problem more quickly than you already can?

  • Or maybe we can find

a faster algorithm?

slide-21
SLIDE 21

 The performance is bad!

slide-22
SLIDE 22

This is Θ(?)

slide-23
SLIDE 23

 Is MCSS W(n2)?

  • Showing that a problem is W (g(n)) is much tougher. How do

you prove that it is impossible to solve a problem more quickly than you already can?

  • Can we find a yet faster algorithm?
slide-24
SLIDE 24

Tune in next time for the exciting conclusion!

http://www.etsu.edu/math/gardner/batman

Q8 Q8, Q9