Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP 103 Course Review. 2 Menu  A final word on hash collisions in Open Addressing / Probing  Course Summary  What we have covered  What you should.

Similar presentations


Presentation on theme: "COMP 103 Course Review. 2 Menu  A final word on hash collisions in Open Addressing / Probing  Course Summary  What we have covered  What you should."— Presentation transcript:

1 COMP 103 Course Review

2 2 Menu  A final word on hash collisions in Open Addressing / Probing  Course Summary  What we have covered  What you should have learnt  The exam  Structure, emphasis, how to do well!

3 3 Quadratic Probing  Make the sequence of probes have increasing steps:  runs don’t join up so fast h, h+1, h+4, h+9, h+16, … p=h, p+=1, p+=3, p+=5, p+= 7, p+= 9, ….  In general, quadratic probing uses a quadratic formula: probe i = hash + a  i + b  i 2 ( b  0)  Eg: with a=b=½, the step sizes become 1,2,3… instead of 1,3,5… “ eel ”“ kea ”“ ant ”“ cat ”“ fox ”“ dog ”“ hen ”“ bee ”“ owl ”

4 4 Hash Table with Probing: remove  Inserted: Stu (2) Sven (5) Sam (4) Steve (2) Sun (4)  Now remove: Sam (4)  What’s the problem?  contains(Sun) will return false!  To remove, need to leave a marker (not null, not a value !) public void remove() { throw new UnsupportedOperationException(); } 0123456 SamSteveStigStuSvenSun insert a "tombstone" key instead

5 5 Iterator  Iterating through hash table is not simple:  there will be nulls to skip over  the order that items are returned appears random (and may change when the array is doubled!)  At each call to next(), Iterator must advance the index to the next non-null cell. “ eel ”“ kea ”“ ant ”“ cat ”“ bee ”“ fox ”“ dog ”

6 6 Other Probing Techniques  Quadratic probing:  Step sizes 1,2,3…  still suffers from “secondary clustering”  Double hashing:  use a second hash function, to compute next probe index: p = hash2(value, p);  less clustering, but more expensive  Cuckoo hashing...  Use two hash functions.  Try both indexes.  If both are full, kick out one of the values, and put it in its alternate place (kicking out a value if necessary,….) the new hash depends on the value as well (unlike with probing)

7 7 Course Summary  Different kinds of Collections:  Lists, Sets, Bags, Maps, Stacks, Queues, Priority Queues, Trees, Graphs  What are their properties?  When are they appropriate?  Using collections  Using generic types: List drawing = new ArrayList ();  Programming with collections Choosing appropriate collection types for applications Writing code that uses collections

8 8 Course Summary  Implementing collections  arrays, linked lists, BSTs, POTs/heaps, bitsets, hash tables  sorted vs unsorted  iterators, comparators  linear search vs binary search  hashing: chaining (buckets) vs open addressing (probing)  Understanding different ways of representing collections  Basic algorithms for accessing and updating different kinds of structures  How the data structure affects the costs of operations

9 9  Sorting algorithms  Slow sorts: insertion, selection  Fast sorts: mergesort, quicksort, treesort, heapsort  Cost of algorithms  Big-O (asymptotic cost)  Simple loops, nested loops, recursion, and traversal  Measuring performance Course Summary

10 10 Course Summary  Trees of several different kinds:  Trees for tree-structured data Binary trees vs general trees  Trees for efficient linear collections: BSTs, POTs/heaps  Algorithms on trees:  Constructing & traversing trees Depth first (pre-, in-, post-order) vs Breadth First Recursive vs Iterative  search, add, and remove in BST’s  add, and remove in POT’s/heaps

11 11 The Exam (Example) answer all questions 180 minutes for 180 marks Calculators & non-electronic dictionaries are OK

12 12 The Exam  Read the question carefully and make sure you know what is being asked.  Write your answer clearly!  Use extra pages for rough work or for answers  Cross out what you don’t want marked  Say where your answer is if not on same page!  For coding questions:  There’s more than one way...  If it’s complicated, start with the pseudocode  DON’T PANIC!!!

13 13 The Exam  There is a link on the 103 homepage to this:   “Assessment archive” http://ecs.victoria.ac.nz/Main/ExamArchiveCOMP103 http://ecs.victoria.ac.nz/Main/ExamArchiveCOMP103  Do your best without the answers  Then check against the answers


Download ppt "COMP 103 Course Review. 2 Menu  A final word on hash collisions in Open Addressing / Probing  Course Summary  What we have covered  What you should."

Similar presentations


Ads by Google