1 / 12

Applied Algorithms

Applied Algorithms. Lecture #8 Number Theory. Exam Today. Write Name in bluebook Only 1 page of notes allowed 90 minutes allocated for exam. The Step problem. Step from 7 to 21 The sequence 7, 8, 10, 12, 15, 18, 20, 21 1 2 2 3 3 2 1 The deltas (size of the steps).

aprill
Télécharger la présentation

Applied Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Applied Algorithms Lecture #8 Number Theory

  2. Exam Today • Write Name in bluebook • Only 1 page of notes allowed • 90 minutes allocated for exam

  3. The Step problem • Step from 7 to 21 • The sequence • 7, 8, 10, 12, 15, 18, 20, 21 • 1 2 2 3 3 2 1 • The deltas (size of the steps)

  4. Note 7, 8, 10, 12, 15, 18, 20, 21 1 2 2 3 3 2 1 • Another problem where (end-start) 21-7 =14 will use the same deltas. • The deltas form an ascending, and then descending sequence.

  5. Experiment 0 [] 1 [1] 2 [1,1] 3 [1,1,1] 4 [1,2,1] 5 [1,1,2,1] 6 [1,2,2,1] 7 [1,1,2,2,1] 8 [1,2,2,2,1] 9 [1,2,3,2,1] 10 [1,1,2,3,2,1] 11 [1,2,2,3,2,1] 12 [1,2,3,3,2,1] 13 [1,1,2,3,3,2,1] 14 [1,2,2,3,3,2,1] 15 [1,2,3,3,3,2,1] 16 [1,2,3,4,3,2,1] What’s the pattern here?

  6. There are three kinds of deltas • [1,2,3,4,3,2,1] • [1,2,3,4,4,3,2,1] • [1,2,2,3,2,1] Pyramid Plateau step

  7. Properties • Pyramids span a distance that is a perfect square (n2) • Plateaus span a distance expressed as n2+n • Steps span distances between these two

  8. 0 [] 1 [1] -- perfect square n=1 2 [1,1] 3 [1,1,1] 4 [1,2,1] -- perfect square n=2 5 [1,1,2,1] 6 [1,2,2,1] ** plateau n=2 7 [1,1,2,2,1] 8 [1,2,2,2,1] 9 [1,2,3,2,1] -- perfect square n=3 10 [1,1,2,3,2,1] 11 [1,2,2,3,2,1] 12 [1,2,3,3,2,1] ** plateua n=3 13 [1,1,2,3,3,2,1] 14 [1,2,2,3,3,2,1] 15 [1,2,3,3,3,2,1] 16 [1,2,3,4,3,2,1] -- perfect square n=4 17 [1,1,2,3,4,3,2,1] 18 [1,2,2,3,4,3,2,1] 19 [1,2,3,3,4,3,2,1] 20 [1,2,3,4,4,3,2,1] ** plateau n=4 21 [1,1,2,3,4,4,3,2,1] 22 [1,2,2,3,4,4,3,2,1] 23 [1,2,3,3,4,4,3,2,1] 24 [1,2,3,4,4,4,3,2,1] 25 [1,2,3,4,5,4,3,2,1] -- perfect square n=5 26 [1,1,2,3,4,5,4,3,2,1] 27 [1,2,2,3,4,5,4,3,2,1] 28 [1,2,3,3,4,5,4,3,2,1] 29 [1,2,3,4,4,5,4,3,2,1] 30 [1,2,3,4,5,5,4,3,2,1] ** plateau n=5 31 [1,1,2,3,4,5,5,4,3,2,1] 32 [1,2,2,3,4,5,5,4,3,2,1] 33 [1,2,3,3,4,5,5,4,3,2,1] 34 [1,2,3,4,4,5,5,4,3,2,1] 35 [1,2,3,4,5,5,5,4,3,2,1] 36 [1,2,3,4,5,6,5,4,3,2,1] -- perfect square n=6 Note how the length changes only at pyramid and plateau points.

  9. Given distance d between endpoints • n = floor(sqrt d) • (n*n)==d we’re at a pyramid point • (n*n)+n ==d we’re at a plateau point • Otherwise we’re at a step point

  10. length d | (n*n)==d = 2*n-1 | d<=(n*n)+n = 2*n | otherwise = 2*n + 1 where n = floor(sqrt d)

  11. In Class Problems • Euclid Problem 7.6.3 • Page 159 of the text • We will write this together as a class

  12. Today’s Assignments Read for next time Chapter 8 of the text. pp 167-188 Be prepared to answer questions in class next Friday from the reading. Programming assignment • 7.6.5 Summation of Four Primes • Page 161 • Write a solution Submit your solution (until you get it right) Hand in both your program, and the judge output. Those who volunteer to discuss their program get class participation points. Email me solutions before noon on Friday, May 6.

More Related