1 / 10

Applied Algorithms

Applied Algorithms. Lecture #6 Arithmetic and Algebra. Quiz. We have a 10 minute quiz today on the reading – Chapter 5. We will continue to have quizzes until the class gets an average score high enough to convince me that people are doing the reading. a. b. c. d. e. f. g. h. i. j.

Download Presentation

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 #6 Arithmetic and Algebra

  2. Quiz • We have a 10 minute quiz today on the reading – Chapter 5. • We will continue to have quizzes until the class gets an average score high enough to convince me that people are doing the reading.

  3. a b c d e f g h i j k l m n o p q r s t u v w x y z n t x Crypt Kicker the quick brown fox … xnm cecob lrtzv ita … length table plain line

  4. Make a substitution Bool test(int length, char line[]) { int i; char c; char target; if (strlen(line)!=length) return False; for (i=0; i<length; i++) { c = line[i]; ; target = plain[i]; ; if (table[c]=='?') table[c]=target; ; if (table[c]!=target) return False; } return True; } Exits as soon as we can’t extend the subsitution

  5. Vitos Family 5 9 20 21 44 68 80 • |x-5| + |x-9| + |x-20| + |x-21| + |x-44| + |x-68| + |x-80| • Suppose x is between 21 and 44 • (x-5)+ (x-9) + (x-20) + (x-21) + (44-x) + (68-x) + (80-x) • 4x – (5+9+20+21) + (44+68+80) -3x

  6. Partial sums from left and right 5 9 20 21 44 68 80 5 14 34 55 99 167 247 247 242 233 213 192 148 80

  7. In class Assignment • Using this idea • Goto the class web page and upload • VitosFamilySkeleton.c • Modify this program to use these facts • Use the sorting algorithm in <stdlib.h> #include <stdlib.h> void qsort(void *base, size_t nel, size_t width, int(*compare)(const void *,const void *));

  8. Shoemaker don't think that a simple sort by duration within penalty descending works in all cases.  For example duration        penalty 30              9 30              9 1               8 is in the right order and gives, by my calculation, 30*9 + (30+30)*8 = 510, where putting the short duration first is: duration        penalty 1               8 30              9 30              9  by my calculation, 1*9 + (1+30)*9 = 288.

  9. In Class Problems • Primary Arithmetic 5.9.1 • Page 119 of the text • We will write this together as a class • Reverse and Add 5.92 • Page 120 of the text • Keeping in mind today’s lecture. • Pairs of two

  10. Today’s Assignments Read for next time Chapter 6 of the text. pp 129-146 Be prepared to answer questions in class next Friday from the reading. Programming assignment • 5.9.8 Pairsumonius Numbers • Page 127 • 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