academic integrity
play

Academic Integrity Collaboration Encouraged! Groups of up to 5 per - PowerPoint PPT Presentation

Academic Integrity Collaboration Encouraged! Groups of up to 5 per assignment (you + 4) List your collaborators (by UVA computing ID) Write-ups/code written independently DO NOT share written notes / pictures / code DO NOT


  1. Academic Integrity • Collaboration Encouraged! – Groups of up to 5 per assignment (you + 4) – List your collaborators (by UVA computing ID) • Write-ups/code written independently – DO NOT share written notes / pictures / code – DO NOT share documents (ex: Overleaf) • Be able to explain any solution you submit! • DO NOT seek published solutions online

  2. Late Policy • By default, late submissions not accepted • If something comes up that prevents you from submitting quality work on time, let me know what’s going on

  3. Exams • No exams

  4. Regrades • Conducted using the submission system: – Submit within 5 days of receiving your grade – Request a regrade if the rubric was misapplied

  5. Course webpage • www.cs.virginia.edu/~njb2b/cs4102/su20

  6. Extra “credit” • Given for extraordinary acts of engagement – Good questions/comments – Quality discussions – Analysis of current events – References to arts and music – Extra credit projects – Slide corrections – Etc. Just ask! • Submit to me via email • Will be used for qualitative grade adjustments

  7. CS4102 Algorithms Fall 2020 Warm up Can you cover an 8 × 8 grid with 1 Can you cover this? square missing using “ trominoes ?” With these?

  8. Where does it end? • I have a pile of string • I have one end of the string in my hand • I need to find the other end • How can I do this efficiently?

  9. Rope End Finding 1. Set aside the already obtained end 2. Separate the pile of rope into 2 piles, note which connects to the known end (call it pile A, the other pile B) Repeat on pile with end 3. Count the number of strands crossing the piles 4. If the count is even, pile A contains the end, else pile B does

  10. How efficient is it? 𝑜 • 𝑈 𝑜 = 𝑑𝑝𝑣𝑜𝑢(𝑜) + 𝑈 2 𝑜 • 𝑈 𝑜 = 5 + 𝑈 2 • Base case: 𝑈 1 = 1

  11. Let’s solve the recurrence! 𝑈 1 = 1 𝑈 𝑜 = 5 + 𝑈(𝑜 2 ) 5 + 𝑈(𝑜 4 ) log 2 𝑜 5 + 𝑈(𝑜 8 ) 1 log 2 𝑜 𝑈 𝑜 = 5 + 1 = 5 log 2 𝑜 + 1 𝑗=0

  12. Algorithm Running Times • We can’t just measure running time with a number • Why shouldn’t we say: “The running time of this algorithm is 8.”? • Units: 8 what? Seconds? • What if the input is large? • Algorithm running times are functions – Domain: “sizes” of the algorithm’s input – Co- Domain: “counts” of operations • We want to be able to say “algorithm 1 is faster than algorithm 2” • How can we compare functions?

  13. Asymptotic Notation* • 𝑃(𝑕 𝑜 ) – At most within constant of 𝑕 for large 𝑜 – { functions 𝑔|∃ constants 𝑑, 𝑜 0 > 0 s.t. ∀𝑜 > 𝑜 0 , 𝑔 𝑜 ≤ 𝑑 ⋅ 𝑕(𝑜)} • Ω(𝑕 𝑜 ) – At least within constant of 𝑕 for large 𝑜 – { functions 𝑔|∃ constants 𝑑, 𝑜 0 > 0 s.t. ∀𝑜 > 𝑜 0 , 𝑔 𝑜 ≥ 𝑑 ⋅ 𝑕(𝑜)} • Θ 𝑕 𝑜 – “ Tightly ” within constant of 𝑕 for large 𝑜 – Ω 𝑕 𝑜 ∩ 𝑃(𝑕 𝑜 ) *CLRS Chapter 3

  14. 𝑔(𝑜) = 𝑃(𝑕 𝑜 ) 𝑔(𝑜) = Θ(𝑕 𝑜 ) 𝑔(𝑜) = Ω(𝑕 𝑜 )

  15. Asymptotic Notation • 𝑝(𝑕 𝑜 ) – Below any constant of 𝑕 for large 𝑜 – { functions 𝑔|∀ constants 𝑑, ∃𝑜 0 s.t. ∀𝑜 > 𝑜 0 , 𝑔 𝑜 < 𝑑 ⋅ 𝑕(𝑜)} • 𝜕(𝑕 𝑜 ) – Above any constant of 𝑕 for large 𝑜 – { functions 𝑔|∀ constants 𝑑, ∃𝑜 0 s.t. ∀𝑜 > 𝑜 0 , 𝑔 𝑜 > 𝑑 ⋅ 𝑕(𝑜)} • 𝜄 𝑕 𝑜 ? – 𝑝(𝑕 𝑜 ) ∩ 𝜕(𝑕 𝑜 ) = ∅

  16. Asymptotic Notation Example • Show: 𝑜 log 𝑜 ∈ 𝑃 𝑜 2

  17. Asymptotic Notation Example • To Show: 𝑜 log 𝑜 ∈ 𝑃 𝑜 2 Direct Proof! – Technique: Find 𝑑, 𝑜 0 > 0 s.t. ∀𝑜 > 𝑜 0 , 𝑜 log 𝑜 ≤ 𝑑 ⋅ 𝑜 2 – Proof: Let 𝑑 = 1, 𝑜 0 = 1 . Then, 𝑜 0 log 𝑜 0 = 1 log 1 = 0 , 2 = 1 ⋅ 1 2 = 1, 𝑑 𝑜 0 0 ≤ 1 . ∀𝑜 ≥ 1, log 𝑜 < 𝑜 ⇒ 𝑜 log 𝑜 ≤ 𝑜 2 □

  18. Asymptotic Notation Example • Show: 𝑜 2 ∉ 𝑃 𝑜

  19. Asymptotic Notation Example • To Show: 𝑜 2 ∉ 𝑃 𝑜 Proof by Contradiction! – Technique: Contradiction – Proof: Assume 𝑜 2 ∈ 𝑃 𝑜 . Then ∃𝑑, 𝑜 0 > 0 s. t. ∀𝑜 > 𝑜 0 , 𝑜 2 ≤ 𝑑𝑜 Let us derive constant 𝑑 . For all 𝑜 > 𝑜 0 > 0 , we know: 𝑑𝑜 ≥ 𝑜 2 , 𝑑 ≥ 𝑜. Since 𝑑 is lower bounded by 𝑜 , it is not a constant. Contradiction. Therefore 𝑜 2 ∉ 𝑃 𝑜 . □

  20. Asymptotic Notation Example • 𝑝 𝑕 𝑜 = { functions 𝑔 ∶ ∀ constants 𝑑 > 0, ∃𝑜 0 s.t. ∀𝑜 > 𝑜 0 , 𝑔 𝑜 < 𝑑 ⋅ 𝑕(𝑜)} • Show: 𝑜 log 𝑜 ∈ 𝑝 𝑜 2 – given any 𝑑 find a 𝑜 0 > 0 s.t. ∀𝑜 > 𝑜 0 , 𝑜 log 𝑜 < 𝑑 ⋅ 𝑜 2 – Find a value of 𝑜 in terms of 𝑑 : • 𝑜 log 𝑜 < 𝑑 ⋅ 𝑜 2 • log 𝑜 < 𝑑 ⋅ 𝑜 log 𝑜 < 𝑑 • 𝑜 log 𝑜 – For a given 𝑑 , select any value of 𝑜 0 such that < 𝑑 𝑜

  21. Trominoes Puzzle Solution 2 𝑜 2 𝑜 What about larger boards?

  22. Trominoes Puzzle Solution Divide the board into quadrants

  23. Trominoes Puzzle Solution Place a tromino to occupy the three quadrants without the missing piece

  24. Trominoes Puzzle Solution Each quadrant is now a smaller subproblem

  25. Trominoes Puzzle Solution Solve Recursively

  26. Divide and Conquer Our first algorithmic technique!

  27. Trominoes Puzzle Solution

  28. Divide and Conquer* When is this a good strategy? • Divide: – Break the problem into multiple subproblems, each smaller instances of the original • Conquer: – If the suproblems are “large”: • Solve each subproblem recursively – If the subproblems are “small”: • Solve them directly (base case) • Combine: – Merge together solutions to subproblems *CLRS Chapter 4

  29. Analyzing Divide and Conquer 1. Break into smaller subproblems 2. Use recurrence relation to express recursive running time 3. Use asymptotic notation to simplify • Divide: 𝐸(𝑜) time, • Conquer: recurse on small problems, size 𝑡 • Combine: C(𝑜) time • Recurrence: – 𝑈 𝑜 = 𝐸 𝑜 + 𝑈(𝑡) + 𝐷(𝑜)

  30. Recurrence Solving Techniques Tree ? Guess/Check “Cookbook” 30

  31. Merge Sort • Divide: – Break 𝑜 -element list into two lists of 𝑜 2 elements • Conquer: – If 𝑜 > 1 : • Sort each sublist recursively – If 𝑜 = 1 : • List is already sorted (base case) • Combine: – Merge together sorted sublists into one sorted list 31

  32. Merge • Combine: Merge sorted sublists into one sorted list • We have: – 2 sorted lists ( 𝑀 1 , 𝑀 2 ) – 1 output list ( 𝑀 𝑝𝑣𝑢 ) While ( 𝑀 1 and 𝑀 2 not empty): If 𝑀 1 0 ≤ 𝑀 2 [0] : 𝑀 𝑝𝑣𝑢 .append( 𝑀 1 .pop()) Else: 𝑀 𝑝𝑣𝑢 .append( 𝑀 2 .pop()) 𝑀 𝑝𝑣𝑢 .append( 𝑀 1 ) 𝑃(𝑜) 𝑀 𝑝𝑣𝑢 .append( 𝑀 2 ) 32

  33. Analyzing Merge Sort 1. Break into smaller subproblems 2. Use recurrence relation to express recursive running time 3. Use asymptotic notation to simplify • Divide: 0 comparisons • Conquer: recurse on 2 small subproblems, size 𝑜 2 • Combine: 𝑜 comparisons • Recurrence: 𝑜 – 𝑈 𝑜 = 2 𝑈 2 + 𝑜 33

  34. Recurrence Solving Techniques Tree ? Guess/Check “Cookbook” 34

  35. Tree method 𝑈 𝑜 = 2𝑈(𝑜 2 ) + 𝑜 𝑜 𝑜  𝑜 total / level 𝑜 𝑜 𝑜 2 𝑜 2 2 2 log 2 𝑜 levels 𝑜 𝑜 𝑜 𝑜 𝑜 4 𝑜 4 𝑜 4 𝑜 4 4 4 4 4 of recursion … … … … … 1 1 1 1 1 1 1 1 1 1 1 1 log 2 𝑜 𝑈 𝑜 = 𝑜 = 𝑜 log 2 𝑜 𝑗=1 35

Recommend


More recommend