assignment info -...

35
Assignment Info A2 marks will be out before Wed From 235 submissions: Average: 65.84, Median: 71 ~29% got [80-100], with ~13% got > 90, 3 perfect score ~22% got [0-49] A3 due tomorrow 23:59, grace period until Wed 13:00 Save as draft in wattle, if you want to update until the last minute. The last version you save will automatically become your submission

Upload: others

Post on 29-Sep-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Assignment Info• A2 marks will be out before Wed• From 235 submissions:• Average: 65.84, Median: 71• ~29% got [80-100], with ~13% got > 90, 3 perfect score• ~22% got [0-49]

• A3 due tomorrow 23:59, grace period until Wed 13:00• Save as draft in wattle, if you want to update until

the last minute. The last version you save will automatically become your submission

Page 2: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Exam Info• All materials covered except for MDP • You can bring: 1 A4 page, hand-written on both side• 7 November, 9am, 2 hours, 7-11 Barry Drive• Please recheck time & location in ANU timetable• Tips:• You will have 15 min to read the questions first. Use this time

to roughly understand the question, see the points, and strategise which questions you’ll do first

• Do questions with higher points and you can do them first• Try to answer all questions. If you have some writing even if

it’s wrong, we’ll give 10% for writing marks. If it’s empty, it’s 0

Page 3: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

To help prepare for exam• This Wed, 23 Oct, usual Q&A session

(Coombs): Recap of the materials•Wed, 30 Oct, 4pm-5pm, in Copland Lecture

Theatre: We’ll cover Part A of assignments• Friday, 1 Nov, 10am-12am, in Copland

Lecture Theatre: Drop in session, a couple of tutors would be available

Page 4: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

COMP3600/6466 – Algorithms Hash Tables[CLRS] ch. 11

Hanna Kurniawati

https://cs.anu.edu.au/courses/comp3600/

Page 5: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

TodayüWhat is a hash table?üHashing with ChainingüHashing functions:üSimple uniform hashingüUniversal hashing

üOpen addressing• Perfect hashing

Page 6: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Perfect hashing• Assume: The problem is static (i.e., no insert /

delete)• Idea: 2-level hashing• Each slot points to another hash table• Use universal hashing in both levels• Properties:• Polynomial build time with high probability• O(1) search time in the worst case• O(n) space is worst case

Page 7: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

How to build a perfect hashing?1. Pick a universal hash function ℎ" ∈ 𝐻 and set 𝑚 =

Θ 𝑛 , usually 𝑚 is set to be prime2. If ∑*+,-."𝑛*/ > 𝑐𝑛, for a selected constant 𝑐, redo 13. If there’s ni elements in slot-i, construct a hash-table

with size ni2 slots, and choose a universal hash

function ℎ/,* ∈ 𝐻 to be the hash function for this 2nd

level hash table4. As long as there’s ℎ/,*(𝑘) = ℎ/,*(𝑘′) for any 𝑘 ≠ 𝑘′,

pick a different ℎ/,* and rehash those elements in 𝑛*

Page 8: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:
Page 9: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Perfect Hashing• Once the hash table is built, it’s

guaranteed there’s no collision in search. Hence, it’s guaranteed to have O(1) search time.• The question is how many times do we

need to repeat finding the hash function (step 2 and step 3)?

Page 10: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Bound on P[#collisions in 2nd level]

Page 11: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Additional Bounds on Time • E[#trials] ≤ 2 and #trials = O(log n) with high

probability• Total time spent in step-3 & step-4: O(n log2n)• Total time spent in step-1 & step-2: O(n log n)

Not included for exam

Page 12: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Bound on the space requirement• Bound on E[∑*+,-." 𝑛*/]

Page 13: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:
Page 14: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

TodayüWhat is a hash table?üHashing with ChainingüHashing functions:üSimple uniform hashingüUniversal hashing

üOpen addressingüPerfect hashing

Page 15: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

COMP3600/6466 – Algorithms Complexity Class

[CLRS] ch. 34 Intro

Hanna Kurniawati

https://cs.anu.edu.au/courses/comp3600/

Page 16: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Today• Complexity classes: P & NP• Examples• Showing a problem is P / NP• Other complexity classes

Page 17: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Complexity Classes• So far, we’ve discussed computational

complexity of algorithms• Now, we want to discuss computational

complexity of problems• Why bother?• To know what kind of problem we are dealing with. • Imagine someone wants to hire you to solve a problem.

If you know many smart people have tried to solve equivalent problem for decades with no results, perhaps you need to be really careful with this project!

Page 18: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Complexity Classes• P: The set of decision problems solvable in polynomial

time• Decision problems: Problems where the answer is yes or no• NP: The set of decision problems solvable in non-

deterministic polynomial time• Non-deterministic polynomial time: Solvable in polynomial

time by a non-deterministic Turing machine• Non-deterministic Turing machine: • Can explore multiple possibilities at once• Can guess one out of polynomially many options in O(1).

If any guess lead to a Yes answer, then we get such a guess

Page 19: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:
Page 20: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Complexity Classes• NP is also defined as the set of problems with

polynomial size certificate and polynomial time verifiers for Yes inputs

Page 21: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

NP-Complete• A problem X is NP-complete if X ∈ NP and X ∈ NP-

hard• X is NP-hard if every problem Y ∈NP reduces to X• A problem A reduces to B whenever there’s a polynomial time

algorithm that converts A’s input to equivalent input for B• Equivalent means it has the same Yes/No answer • If A ∈ P, then B ∈ P. If A ∈ NP, then B ∈ NP• B is at least as hard as A

• X ∉ P unless P = NP

Page 22: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:
Page 23: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

TodayüComplexity classes: P & NP• Examples• Showing a problem is P / NP• Other complexity classes

Page 24: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Hamiltonian Cycle• Given a directed graph G(V, E), a Hamiltonian

cycle is a simple cycle that contains all vertices in V. • Cycle: A path that starts and ends at the same vertex• Simple cycle: The only repeating vertex in the cycle

is the start and ending vertex • Deciding whether G has a Hamiltonian cycle or

not is NP-complete

Page 25: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

3-SAT (SAT: satisfiability)• Given Boolean formula in the form of AND of

ORs, where each clause has 3 literals, the formula is satisfiable when for some values of the literals, the formula is True• E.g.: (𝐴 ∨ 𝐵 ∨ �̅�) ∧ (𝐴 ∨ @𝐵 ∨ 𝐷)• Deciding whether a boolean formula of AND

of ORs, where each clause has 3 literals is satisfiable or not is NP-complete

Page 26: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:
Page 27: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

TodayüComplexity classes: P & NPüExamples• Showing a problem is P / NP• Other complexity classes

Page 28: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Showing a Problem is in NP• Proof by construction by providing:• Polynomial length certificate • Polynomial time algorithm to verify the certificate

Page 29: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Showing a Problem is in NP-Complete• Show the problem is NP +• Show the problem is NP-hard• Use Karp-reduction: Show that an NP-hard

problem can be reduced to the problem in question in polynomial time

Page 30: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

Example • Show that deciding whether a directed

graph G(V, E) has a Hamiltonian Path is NP-complete• Hamiltonian Path: Given a directed graph G(V,

E), are there any path in G that visits each vertex in V exactly once?

Page 31: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:
Page 32: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

TodayüComplexity classes: P & NPüExamplesüShowing a problem is P / NP• Other complexity classes

Page 33: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

There’s much more complexity classes• Co-NP: Similar to NP, but for No answer• If x is in NP, then its complement is in co-NP• PSPACE: The set of decision problems

that can be solved using polynomial space• EXP (also known as EXP-TIME): The set

of decision problems solvable in exponential time

Page 34: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

TodayüComplexity classes: P & NPüExamplesüShowing a problem is P / NPüOther complexity classes

Page 35: Assignment Info - courses.cecs.anu.edu.aucourses.cecs.anu.edu.au/...hashTablesCont-complexityClass-aftClas… · Assignment Info •A2 marks will be out before Wed •From 235 submissions:

That’s all for this semester!!!

Wed: Recap