Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sequences 11/12/2018 5:23 AM Sets Sets.

Similar presentations


Presentation on theme: "Sequences 11/12/2018 5:23 AM Sets Sets."— Presentation transcript:

1 Sequences 11/12/2018 5:23 AM Sets Sets

2 Definitions A set is an unordered collection of elements, without duplicates that typically supports efficient membership tests. Elements of a set are like keys of a map, but without any auxiliary values. A multiset (also known as a bag) is a set-like container that allows duplicates. A multimap is similar to a traditional map, in that it associates values with keys; however, in a multimap the same key can be mapped to multiple values. For example, the index of a book maps a given term to one or more locations at which the term occurs. Sets

3 Set ADT Sets

4 Boolean Set Operations
Sets

5 Set Update Operations Sets

6 Nodes storing set elements in order
Storing a Set in a List We can implement a set with a list Elements are stored sorted according to some canonical ordering The space used is O(n) Nodes storing set elements in order List Set elements Sets

7 Generic Merging Generalized merge of two sorted lists A and B
Template method genericMerge Auxiliary methods aIsLess bIsLess bothAreEqual Runs in O(nA + nB) time provided the auxiliary methods run in O(1) time Algorithm genericMerge(A, B) S  empty sequence while A.isEmpty()  B.isEmpty() a  A.first().element(); b  B.first().element() if a < b aIsLess(a, S); A.remove(A.first()) else if b < a bIsLess(b, S); B.remove(B.first()) else { b = a } bothAreEqual(a, b, S) A.remove(A.first()); B.remove(B.first()) while A.isEmpty() while B.isEmpty() return S Sets

8 Using Generic Merge for Set Operations
Any of the set operations can be implemented using a generic merge For example: For intersection: only copy elements that are duplicated in both list For union: copy every element from both lists except for the duplicates All methods run in linear time Sets

9 Assignment #10 R-10.9 Draw the 11-entry hash table that results from using the hash function, h(i) = (3i+5) mod 11, to hash the keys 12, 44, 13, 88, 23, 94, 11, 39, 20, 16, and 5, assuming collisions are handled by chaining. Sets

10 R Draw the 11-entry hash table that results from using the hash function, h(i) = (3i+5) mod 11, to hash the keys 12, 44, 13, 88, 23, 94, 11, 39, 20, 16, and 5,, assuming collisions are handled by linear probing? Sets

11 Mimic the style of the figures in the book
R Draw an example skip list S that results from performing the following series of operations on the skip list shown in Figure 10.13: del S[38], S[48] = x , S[24] = y , del S[55]. Record your coin flips, as well. Mimic the style of the figures in the book Sets


Download ppt "Sequences 11/12/2018 5:23 AM Sets Sets."

Similar presentations


Ads by Google