academic integrity - university of virginia

35
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

Upload: others

Post on 14-Apr-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Academic Integrity - University of Virginia

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

Page 2: Academic Integrity - University of Virginia

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

Page 3: Academic Integrity - University of Virginia

Exams

β€’ No exams

Page 4: Academic Integrity - University of Virginia

Regrades

β€’ Conducted using the submission system:

– Submit within 5 days of receiving your grade

– Request a regrade if the rubric was misapplied

Page 5: Academic Integrity - University of Virginia

Course webpage

β€’ www.cs.virginia.edu/~njb2b/cs4102/su20

Page 6: Academic Integrity - University of Virginia

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

Page 7: Academic Integrity - University of Virginia

Warm up

Can you cover an 8 Γ— 8 grid with 1 square missing using β€œtrominoes?”

Can you cover this?

With these?

CS4102 Algorithms Fall 2020

Page 8: Academic Integrity - University of Virginia

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?

Page 9: Academic Integrity - University of Virginia

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)

3. Count the number of strands crossing the piles

4. If the count is even, pile A contains the end, else pile B does

Repeat on pile with end

Page 10: Academic Integrity - University of Virginia

How efficient is it?

β€’ 𝑇 𝑛 = π‘π‘œπ‘’π‘›π‘‘(𝑛) + 𝑇𝑛

2

β€’ 𝑇 𝑛 = 5 + 𝑇𝑛

2

β€’ Base case: 𝑇 1 = 1

Page 11: Academic Integrity - University of Virginia

Let’s solve the recurrence!

𝑇 𝑛 = 5 + 𝑇(𝑛 2 )

𝑇 1 = 1

5 + 𝑇(𝑛 4 )

5 + 𝑇(𝑛 8 )

1

log2 𝑛

𝑇 𝑛 = 5

log2𝑛

𝑖=0

+ 1 = 5 log2 𝑛 + 1

Page 12: Academic Integrity - University of Virginia

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?

Page 13: Academic Integrity - University of Virginia

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 > 0s.t. βˆ€π‘› > 𝑛0, 𝑓 𝑛 β‰₯ 𝑐 β‹… 𝑔(𝑛)}

β€’ Θ 𝑔 𝑛 – β€œTightly” within constant of 𝑔 for large 𝑛

– Ξ© 𝑔 𝑛 ∩ 𝑂(𝑔 𝑛 )

*CLRS Chapter 3

Page 14: Academic Integrity - University of Virginia

𝑓(𝑛) = 𝑂(𝑔 𝑛 )

𝑓(𝑛) = Θ(𝑔 𝑛 )

𝑓(𝑛) = Ξ©(𝑔 𝑛 )

Page 15: Academic Integrity - University of Virginia

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, 𝑓 𝑛 > 𝑐 β‹… 𝑔(𝑛)}

β€’ πœƒ 𝑔 𝑛 ?

– π‘œ(𝑔 𝑛 ) ∩ πœ”(𝑔 𝑛 ) = βˆ…

Page 16: Academic Integrity - University of Virginia

Asymptotic Notation Example

β€’ Show: 𝑛 log 𝑛 ∈ 𝑂 𝑛2

Page 17: Academic Integrity - University of Virginia

Asymptotic Notation Example

β€’ To Show: 𝑛 log 𝑛 ∈ 𝑂 𝑛2

– Technique: Find 𝑐, 𝑛0 > 0 s.t. βˆ€π‘› > 𝑛0, 𝑛 log 𝑛 ≀ 𝑐 β‹… 𝑛2

– Proof: Let 𝑐 = 1, 𝑛0 = 1. Then, 𝑛0 log 𝑛0 = 1 log 1 = 0, 𝑐 𝑛0

2 = 1 β‹… 12 = 1, 0 ≀ 1. βˆ€π‘› β‰₯ 1, log 𝑛 < 𝑛 β‡’ 𝑛 log 𝑛 ≀ 𝑛2 β–‘

Direct Proof!

Page 18: Academic Integrity - University of Virginia

Asymptotic Notation Example

β€’ Show: 𝑛2 βˆ‰ 𝑂 𝑛

Page 19: Academic Integrity - University of Virginia

Asymptotic Notation Example

β€’ To Show: 𝑛2 βˆ‰ 𝑂 𝑛

– 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 βˆ‰ 𝑂 𝑛 . β–‘

Proof by Contradiction!

Page 20: Academic Integrity - University of Virginia

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 𝑛

𝑛< 𝑐

– For a given 𝑐, select any value of 𝑛0 such that log 𝑛

𝑛< 𝑐

Page 21: Academic Integrity - University of Virginia

Trominoes Puzzle Solution

What about larger boards?

2𝑛

2𝑛

Page 22: Academic Integrity - University of Virginia

Trominoes Puzzle Solution

Divide the board into quadrants

Page 23: Academic Integrity - University of Virginia

Trominoes Puzzle Solution

Place a tromino to occupy the three quadrants without the missing piece

Page 24: Academic Integrity - University of Virginia

Trominoes Puzzle Solution

Each quadrant is now a smaller subproblem

Page 25: Academic Integrity - University of Virginia

Trominoes Puzzle Solution

Solve Recursively

Page 26: Academic Integrity - University of Virginia

Divide and Conquer

Our first algorithmic technique!

Page 27: Academic Integrity - University of Virginia

Trominoes Puzzle Solution

Page 28: Academic Integrity - University of Virginia

Divide and Conquer*

β€’ 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

When is this a good strategy?

Page 29: Academic Integrity - University of Virginia

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: – 𝑇 𝑛 = 𝐷 𝑛 + 𝑇(𝑠) + 𝐢(𝑛)

Page 30: Academic Integrity - University of Virginia

Recurrence Solving Techniques

Tree

Guess/Check

β€œCookbook”

30

?

Page 31: Academic Integrity - University of Virginia

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

Page 32: Academic Integrity - University of Virginia

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

𝑂(𝑛)

Page 33: Academic Integrity - University of Virginia

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

Page 34: Academic Integrity - University of Virginia

Recurrence Solving Techniques

Tree

Guess/Check

β€œCookbook”

34

?

Page 35: Academic Integrity - University of Virginia

Tree method

35

𝑛 total / level

log2 𝑛 levels of recursion

𝑛

𝑇 𝑛 = 2𝑇(𝑛

2 ) + 𝑛

𝑇 𝑛 = 𝑛

log2 𝑛

𝑖=1

= 𝑛 log2 𝑛

𝑛 2 𝑛 2

𝑛 4 𝑛 4 𝑛 4 𝑛 4

…

…

…

…

1 1 1 … 1 1 1

𝑛

𝑛

2

𝑛

2

𝑛

4

𝑛

4

𝑛

4

𝑛

4

1 1 1 1 1 1