1 / 55

Review for Quiz 2

Review for Quiz 2. Starring. Starring Bonzo Jr… (251 student). and Lucky (the turtle who introduced the magic square). Disclaimer.

hedya
Download Presentation

Review for Quiz 2

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. Review for Quiz 2

  2. Starring Starring Bonzo Jr… (251 student) and Lucky (the turtle who introduced the magic square)

  3. Disclaimer • This set of lecture slides is intended as an OVERVIEW of the things you should know; it is insufficient to simply glance over these slides 10 minutes before the quiz. • Moreover, this quiz review is NOT a substitute for the lectures; if you missed any lecture, watching the video is highly recommended.

  4. Administrative Stuff • First, a quick review of the administrative stuff. • 50 minutes long • Divided into 4 conceptual sections • Practice quizzes have been/will be uploaded.

  5. Section 1: Repeat After me This section contains about 6-8 questions based on quick facts covered in lecture. If you went to each lecture and paid attention, you should be fine. It is recommended that you skim over the lecture notes before the quiz to refresh your memory on the subject matter. Yay! Free points just for going to lecture and skimming over the notes

  6. Section 2: Reading Solutions You are expected to read the given solutions to all homework and recitation problems - this section is comprised of one or two questions that are literally identical to questions that we've given you before. Note that the problems we ask can come from any previous assignment. (its even possible that we'll ask for the same problem's solution on all three quizzes).

  7. Section 3: Basic Techniques These problems are based on techniques taught during class, and practiced in HWs/recitations. If you practice the ideas taught in lecture, you should have very little trouble with this section (problems vary only slightly from results derived in lecture). HINT: Look at the stuff from Monday’s recitation and the practice quizzes.

  8. Section 4: A Moment’s Thought These problems are similar to problems given on homework assignments, albeit easier. If you do well on homework assignments, you shouldn't have too much trouble with this section. Who named this section…?

  9. Time management Don’t forget about time management! The first two sections are designed to be able to be completed relatively quickly - don’t spend all your time on a Repeat After Me question that is worth only 5 points!

  10. Beginning of Material Review Enough; I know all this! What’s going to be on the quiz?

  11. Stuff on quiz The new material for Quiz 2 is from Lecture 9: Counting IIIto Lecture 17: On Time and Input Size. We are assuming that you already have an understanding of the material from lectures 1-8. While we won’t explicitly test on that, you may need the knowledge you’ve learned from those lectures in answering the questions.

  12. Key Areas • The following areas are rated as very likely to appear on your quiz. • Finite State Machines (DFAs). • Counting and Binomials. • Matchings (including the TMA). • GCDs and Continued Fractions • Fibonacci and Fibonacci-like series. • Asymptotic notation and runtime analysis.

  13. Table of contents • Finite State Machines (DFAs). • Counting and Binomials. • Matchings (including the TMA). • GCDs and Continued Fractions • Fibonacci and Fibonacci-like series. • Asymptotic notation and runtime analysis.

  14. Finite Automaton – quick review

  15. Pumping Lemma In simple terms, the pumping lemma says that for any string that’s long enough, there’s a part of it we can repeat as many times as we want (or even delete, if we let i = 0), and still get a string that’s accepted.

  16. Formal definition of pumping lemma • The pumping lemma states that if there exists a DFA accepting a certain language, then • there is a positive integer k (called the pumping length) so that any string s whose length • is greater than or equal to k can be split up into three strings, u, v, and w, with certain properties: 1. v is not empty; 2. |uv| £ k, and 3. The string uviwis also accepted by the DFA.

  17. Regular Expressions • What strings are accepted by the following regexes? • Ø • ε • 1001 • 10*1 • (0+10+110+111)* • 1(0+1)*0(0+1)*1

  18. Important Concepts • Can you do the following? • - Construct a DFA that accepts all strings with a length that is a multiple of 2 or 3. • Prove that the language of palindromes is not regular (use of pumping lemma is sufficient but not necessary). • Convert a simple regex to a DFA and vice versa?

  19. Table of contents • Finite State Machines (DFAs). • Counting and Binomials. • Matchings (including the TMA). • GCDs and Continued Fractions • Fibonacci and Fibonacci-like series. • Asymptotic notation and runtime analysis.

  20. 1 1 1 1 X X X X 1 X 1 X 1 X Choice tree for terms of (1+X)3 X2 X2 X3 X X X2 X 1 Combine like terms to get 1 + 3X + 3X2 + X3

  21. The Binomial Formula Binomial Coefficients binomial expression

  22. The Binomial Formula Be sure you can handle variants on this (remember the problem from Monday’s recitation)

  23. Pascal’s Triangle 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 So very many properties…

  24. 0 0 j’th Street k’th Avenue 1 1 2 2 3 3 4 4 Manhattan

  25. Table of contents • Finite State Machines (DFAs). • Counting and Binomials. • Matchings (including the TMA). • GCDs and Continued Fractions • Fibonacci and Fibonacci-like series. • Asymptotic notation and runtime analysis.

  26. Rogue Couples • Suppose we pair off all the boys and girls. Now suppose that some boy and some girl prefer each other to the people to whom they are paired. They will be called a rogue couple.

  27. 1,3,4,2,5 3,2,5,1,4 4,3,2,1,5 1,2,4,5,3 3,5,2,1,4 1,2,5,3,4 1 3 5 1 2 4 5,2,1,4,3 2 4,3,5,1,2 3 1,2,3,4,5 4 2,3,4,1,5 5 Stable Pairings • A pairing of boys and girls is called stable if it contains no rogue couples.

  28. Traditional Marriage Algorithm • For each day that some boy gets a “No” do: • Morning • Each girl stands on her balcony • Each boy proposes under the balcony of the best girl whom he has not yet crossed off • Afternoon (for those girls with at least one suitor) • To today’s best suitor: “Maybe, come back tomorrow” • To any others: “No, I will never marry you” • Evening • Any rejected boy crosses the girl off his list • Each girl marries the boy to whom she just said “maybe”

  29. Opinion Poll Who is better off in traditional dating, the boys or the girls?

  30. Table of contents • Finite State Machines (DFAs). • Counting and Binomials. • Matchings (including the TMA). • GCDs and Continued Fractions • Fibonacci and Fibonacci-like series. • Asymptotic notation and runtime analysis.

  31. Euclid’s GCD Formula • Euclid(A,B) // requires AB0 • If B=0 then return A • else return Euclid(B, A mod B) • Note: GCD(67, 29) = 1 • Euclid(67,29) 67 mod 29 = 9 • Euclid(29,9) 29 mod 9 = 2 • Euclid(9,2) 9 mod 2 = 1 • Euclid(2,1) 2 mod 1 = 0 • Euclid(1,0) outputs 1

  32. Extended GCD Algorithm The lecture also covered Euclid’s Extended GCD Algorithm – that might be something you should take a look at.

  33. The multiplicative inverse of x ≡ Zn* is the unique y є Zn*such that x *n y ≡n 1. TO QUICKLY COMPUTE Y FROM X: Run Extended_Euclid(x,n). It returns a,b, and d such that ax+bn = d But d = GCD(x,n) = 1, so ax + bn = 1 Hence MODULO n: ax = 1 (mod n) Thus, a is the multiplicative inverse of x.

  34. A (Simple) Continued Fraction Is Any Expression Of The Form: where a, b, c, … are whole numbers.

  35. A Finite Continued Fraction Denoted by [2,3,4,2,0,0,0,…]

  36. An Infinite Continued Fraction Denoted by [1,2,2,2,…]

  37. An infinite continued fraction

  38. Phi! Φ

  39. Table of contents • Finite State Machines (DFAs). • Counting and Binomials. • Matchings (including the TMA). • GCDs and Continued Fractions • Fibonacci and Fibonacci-like series. • Asymptotic notation and runtime analysis.

  40. Check HW/Recitation The best way to review for this particular section is to look over the Fibonacci homework. Also, the recitation problems from Monday on Fibonacci are EXCELLENT practice.

  41. Beginning of Material Review How did we get the closed form for Fibonacci-like series?

  42. A technique to derive the formula for the Fibonacci numbers • Fn is defined by two conditions: • Base condition: F0=0, F1=1 • Inductive condition: Fn=Fn-1+Fn-2

  43. Forget the base condition and concentrate on satisfying the inductive condition • Inductive condition: Fn=Fn-1+Fn-2 • Consider solutions of the form: • Fn= cn for some complex constant c • C must satisfy: • cn - cn-1 - cn-2 = 0

  44. cn - cn-1 - cn-2 = 0 • iff cn-2(c2 - c1 - 1) = 0 • iff c=0 or c2 - c1 - 1= 0 • Iff c = 0, c = , or c = -(1/)

  45. c = 0, c = , or c = -(1/) • So for all these values of c the inductive condition is satisfied: • cn - cn-1 - cn-2 = 0 • Do any of them happen to satisfy the base condition as well? c0=0 and c1=1? ROTTEN LUCK

  46. Insight: if 2 functions g(n) and h(n) satisfy the inductive condition then so does a g(n) + b h(n) for all complex a and b • (a g(n) + b h(n)) + (a g(n-1) + b h(n-1)) + (a g(n-2) + b h(n-2)) = 0

  47. a,b a n + b (-1/ )nsatisfies the inductive condition • Set a and b to fit the base conditions. • n=0 : a + b = 0 • n=1 : a 1 + b (-1/ )1 = 1 • Two equalities in two unknowns (a and b). • Now solve for a and b: • this gives a = 1/5 b = -1/5

  48. Table of contents • Finite State Machines (DFAs). • Counting and Binomials. • Matchings (including the TMA). • GCDs and Continued Fractions • Fibonacci and Fibonacci-like series. • Asymptotic notation and runtime analysis.

  49. Useful notation to discuss growth rates • For any two monotonic functions f and g from the positive integers to the positive integers, we say “f = O(g)” or “f is O(g)” • if • Some constant times g eventually dominates f • [Formally: there exists a constant c such that for all sufficiently large n: f(n) ≤ c g(n) ]

  50. O(n) graph f = O(g) means that there is some constant c such that c g(n) stays abovef(n) from some point on. 1.5g time g f # of bits in numbers

More Related