17-Sets_and_Multisets

17-Sets_and_Multisets - Associative Containers Data...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Data Retrieval Sequential Container – O(N) Binary Search Tree – O(logN) SLOW! How about constant time, O(1) ? HOW? Use associative containers (e.g. sets and maps that allow retrieving elements by key)! Associative Containers Associative Containers
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Definition: Set is an associative container representing a collections of unique objects. Example: {“apples”, “oranges”, “tomatoes”} Element uniqueness preservation: { “apples” , “oranges”, “tomatoes”} + {“apples”} = { “apples” , “oranges”, “tomatoes”} Because “apples” already was in the original set! Operations: Union {1, 2, 3} {4, 5} = {1, 2, 3, 4, 5} Intersection { 1 , 2, 3 } { 1 , 3 , 4, 5} = { 1 , 3 } Subset { 1 , 3 } { 1 , 2, 3 } is true Difference { 1 , 2, 3 } - { 1 , 3 } = {2} Sets Sets
Background image of page 2
#include <set> set<string> mySet; size() returns set size; begin() returns iterator to the first item in the set; inserts new element into the set;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

17-Sets_and_Multisets - Associative Containers Data...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online