lecture10-11algorithmsanddatastructures

Upload: arijit-basu

Post on 02-Jun-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    1/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    2/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Figure: Venn diagram illustrating the basic set operations.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    3/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Figure: Object class hierarchy.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    4/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: Set interface.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    5/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: AbstractSet class.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    6/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: SetAsArray fields.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    7/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: SetAsArray class constructor, insert, withdraw, andisMember methods.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    8/37

    LECTURELECTURE1 01 0--1 11 1..

    S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: SetAsArray class

    union, intersection and

    difference methods.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    9/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: SetAsArray

    class isEQ and isSubset

    methods.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    10/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: SetAsBitVector fields.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    11/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: SetAsBitVectorclass constructor,

    insert, withdraw, and

    isMember methods.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    12/37

    LECTURELECTURE1 01 0--1 11 1..

    S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: SetAsBitVector class

    union, intersection and

    difference methods.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    13/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: Multiset interface.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    14/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: MultisetAsArray class.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    15/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program:

    MultisetAsArray

    class

    constructor,insert, withdraw,

    and isMember

    methods.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    16/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s ,

    M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: MultisetAsArray classunion, intersection and

    difference methods.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    17/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    18/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: MultisetAsLinkedList fields.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    19/37

    LECTURELECTURE1 01 0--1 11 1..

    S e t s ,S e t s , M u l t i s e t s M u l t i s e t s ,,

    a n d Pa r t i t i o n s a n d Pa r t i t i o n s

    Program:

    MultisetAsLinkedList

    class union method.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    20/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program:

    MultisetAsLinkedListclass intersection

    method.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    21/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    22/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: Partition interface.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    23/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Figure: Representing a partition as a forest.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    24/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Figure: Finding the elements of a partition.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    25/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: PartitionAsForest and PartitionTree fields.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    26/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: PartitionAsForest constructors.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    27/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: PartitionAsForest class find method.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    28/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Figure: Alternatives for joining elements of a partition.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    29/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: PartitionAsForest class simple join method.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    30/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Figure: A degenerate tree.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    31/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: PartitionAsForest class collapsing find method.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    32/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Figure: Example of collapsing find.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    33/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: PartitionAsForest class union-by-size join method.

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    34/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    35/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    36/37

    LECTURELECTURE1 01 0--1 11 1.. S e t s ,S e t s , M u l t i s e t s M u l t i s e t s , a n d, a n d

    P a r t i t i o n s P a r t i t i o n s

    Program: PartitionAsForest class union-by-rank join method.

    LECTURELECTURE 1 01 0 1 11 1

  • 8/11/2019 Lecture10-11AlgorithmsAndDataStructures

    37/37

    LECTURELECTURE1 01 0--1 11 1..

    S e t s ,S e t s , M u l t i s e t s M u l t i s e t s ,,

    a n d Pa r t i t i o n s a n d Pa r t i t i o n s

    Program: Application of

    disjoint sets--finding

    equivalence classes.