Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 410 Applied Algorithms Applied Algorithms Lecture #6 Arithmetic and Algebra.

Similar presentations


Presentation on theme: "CS 410 Applied Algorithms Applied Algorithms Lecture #6 Arithmetic and Algebra."— Presentation transcript:

1 CS 410 Applied Algorithms Applied Algorithms Lecture #6 Arithmetic and Algebra

2 CS 410 Applied Algorithms 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 CS 410 Applied Algorithms Crypt Kicker the quick brown fox … xnm cecob lrtzv ita … abcdefghijklmnopqrstuvwxyz ntx plain line table length

4 CS 410 Applied Algorithms 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 CS 410 Applied Algorithms Vitos Family |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 592021446880

6 CS 410 Applied Algorithms Partial sums from left and right 592021446880 514345599167247 24223321319214880

7 CS 410 Applied Algorithms 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 #include void qsort(void *base, size_t nel, size_t width, int(*compare)(const void *,const void *));

8 CS 410 Applied Algorithms Shoemaker don't think that a simple sort by duration within penalty descending works in all cases. For example duration penalty 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 by my calculation, 1*9 + (1+30)*9 = 288.

9 CS 410 Applied Algorithms 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 CS 410 Applied Algorithms 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.


Download ppt "CS 410 Applied Algorithms Applied Algorithms Lecture #6 Arithmetic and Algebra."

Similar presentations


Ads by Google