Sets and Multimaps 9/9/2017 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Merge Sort1 7 2  9 4   2  2 79  4   72  29  94  4.
Advertisements

Goodrich, Tamassia Sorting, Sets and Selection1 Merge Sort 7 2  9 4   2  2 79  4   72  29  94  4.
© 2004 Goodrich, Tamassia Merge Sort1 7 2  9 4   2  2 79  4   72  29  94  4.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
Merge Sort 4/15/2017 4:30 PM Merge Sort 7 2   7  2  2 7
Merge Sort1 Part-G1 Merge Sort 7 2  9 4   2  2 79  4   72  29  94  4.
Merge Sort1 7 2  9 4   2  2 79  4   72  29  94  4.
© 2004 Goodrich, Tamassia Sets1. © 2004 Goodrich, Tamassia Sets2 Set Operations (§ 10.6) We represent a set by the sorted sequence of its elements By.
CSC 213 Lecture 15: Sets, Union/Find, and the Selection Problem.
Maps, Hash Tables, Skip Lists, Sets last Update: Nov 4, 2014 EECS2011: Maps, Hash Tables, Skip Lists, Sets1.
© 2014 Goodrich, Tamassia, Goldwasser Singly Linked Lists1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
Arrays1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich,
1 More Merge Sort Java implementation Time complexity Generic merging and sets.
1 Merge Sort 7 2  9 4   2  2 79  4   72  29  94  4.
Towers of Hanoi Move n (4) disks from pole A to pole B such that a larger disk is never put on a smaller disk A BC ABC.
1 COMP9024: Data Structures and Algorithms Week Eight: Sortings and Sets Hui Wu Session 1, 2016
Stacks Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Merge Sort 1/12/2018 5:48 AM Merge Sort 7 2   7  2  2 7
Advanced Sorting 7 2  9 4   2   4   7
Merge Sort 1/12/2018 9:39 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Merge Sort 1/12/2018 9:44 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Maps 1/28/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Sorting With Priority Queue In-place Extra O(N) space
Sorting Lower Bound 4/25/2018 8:49 PM
Lists and Iterators 5/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Sets and Multimaps 5/9/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Skip Lists 5/10/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Queues 5/11/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
Binary Search Trees < > =
Graphs 5/14/ :46 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Vectors 5/31/2018 9:25 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Binary Search Trees < > =
Sequences 6/3/2018 9:11 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Doubly Linked Lists 6/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Bucket-Sort and Radix-Sort
B-Trees 7/5/2018 4:26 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
COMP9024: Data Structures and Algorithms
COMP9024: Data Structures and Algorithms
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
Heaps 8/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Chapter 10.1 Binary Search Trees
Quick-Sort 9/12/2018 3:26 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Hash Tables 3/25/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
structures and their relationships." - Linus Torvalds
Objectives Introduce different known sorting algorithms
Priority Queues © 2014 Goodrich, Tamassia, Goldwasser Priority Queues
Sequences 11/12/2018 5:23 AM Sets Sets.
Lists and Iterators 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Associative Structures
Priority Queues 4/6/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
© 2013 Goodrich, Tamassia, Goldwasser
Merge Sort 12/4/ :32 AM Merge Sort 7 2   7  2   4  4 9
Ch. 8 Priority Queues And Heaps
Ordered Maps & Dictionaries
Queues 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Recall What is a Data Structure Very Fundamental Data Structures
Binary Search Trees < > =
CH 9 : Maps And Dictionary
Merge Sort 2/23/ :15 PM Merge Sort 7 2   7  2   4  4 9
Merge Sort 2/24/2019 6:07 PM Merge Sort 7 2   7  2  2 7
Copyright © Aiman Hanna All rights reserved
Binary Search Trees < > =
Sequences 4/10/2019 4:55 AM Sets Sets.
Merge Sort 4/10/ :25 AM Merge Sort 7 2   7  2   4  4 9
Maps 4/25/2019 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Priority Queues © 2010 Goodrich, Tamassia Priority Queues
Merge Sort 5/30/2019 7:52 AM Merge Sort 7 2   7  2  2 7
Abstract Data Types Abstraction is to distill a system to its most fundamental parts. Applying the abstraction paradigm to the design of data structures.
structures and their relationships." - Linus Torvalds
Chapter 11 Sets, and Selection
Presentation transcript:

Sets and Multimaps 9/9/2017 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Sets and Multimaps Sets and Multimaps

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 and Multimaps

Set ADT Sets and Multimaps

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 and Multimaps

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 and Multimaps

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 and Multimaps

Multimap A multimap is similar to a map, except that it can store multiple entries with the same key We can implement a multimap M by means of a map M’ For every key k in M, let E(k) be the list of entries of M with key k The entries of M’ are the pairs (k, E(k)) Sets and Multimaps

Mulitmaps Sets and Multimaps

Java Implementation Sets and Multimaps

Java Implementation, 2 Sets and Multimaps

Java Implementation, 3 Sets and Multimaps