Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2005 Week 7 Lectures Set Abstract Data Type.

Similar presentations


Presentation on theme: "CS2005 Week 7 Lectures Set Abstract Data Type."— Presentation transcript:

1 CS2005 Week 7 Lectures Set Abstract Data Type

2 Aims Describe the Set Abstract Data Type
CS2005 Aims Describe the Set Abstract Data Type Illustrate different implementations of the Set ADT Describe the Java Iterator concept

3 Learning Outcomes specify the Set ADT
CS2005 Learning Outcomes specify the Set ADT write a Java program using one of the java.util set classes use an iterator recall the main points of Watt & Brown chapter 9.

4 CS2005 The Set ADT A set is a collection of elements, without any imposed order

5 Set Concepts Null set (empty set) Universal set Disjoint sets Subset
CS2005 Set Concepts Null set (empty set) Universal set Disjoint sets Subset Equality

6 Set ADT Essential Operations create:  Set add: Element  Set  Set
CS2005 Set ADT Essential Operations create:  Set add: Element  Set  Set contains: Element  Set  Boolean remove: Element  Set  Set isEmpty: Set  Boolean

7 Set ADT (ii) Other Operations size: Set  Integer
CS2005 Set ADT (ii) Other Operations size: Set  Integer equals: Set  Set  Boolean copy: Set  Set areDisjoint: Set  Set  Boolean isSubset: Set  Set  Boolean union: Set  Set  Set intersection : Set  Set  Set difference : Set  Set  Set

8 Set Implementations Bitmap e.g. to represent the set { ‘C’, ‘X’ }
CS2005 Set Implementations Bitmap e.g. to represent the set { ‘C’, ‘X’ } see java.util.BitSet class

9 Set Implementations (ii)
CS2005 Set Implementations (ii) Array e.g. to represent the set { “baker”, “butcher”, “grocer” }

10 Set Implementations (iii)
CS2005 Set Implementations (iii) Linked List Binary Search Tree Hash Table

11 Sets in Java Collection Classes
CS2005 Sets in Java Collection Classes HashSet TreeSet addAll, retainAll, removeAll operations

12 Iterators need for following concept for sets
CS2005 Iterators need for following concept for sets 1. for every member, m, of the set s 1.1 process m Iterator used to solve this problem public interface Iterator { public abstract boolean hasNext(); public abstract Object next(); public abstract void remove(); }

13 Using an Iterator java.util.Iterator i;
CS2005 Using an Iterator java.util.Iterator i; for (i = s.iterator(); i.hasNext(); ) { Object obj = i.next(); // the following code processes obj … }

14 CS2005 Sample code ArraySet TestArraySet HTML file


Download ppt "CS2005 Week 7 Lectures Set Abstract Data Type."

Similar presentations


Ads by Google