Results 1 to 4 of 4
Thread: Sets Question
- 07-22-2013, 01:28 PM #1
Member
- Join Date
- Jun 2013
- Posts
- 62
- Rep Power
- 0
Sets Question
Sets of things from small domains can be efficiently represented as bitmaps. So, for example, if we know that our set can contain just numbers between 0 and 9 then we can represent as a bitmap of length ten where a 1 at position i indicates that i is a member of the set. So, for example, the set: {1,2,5} can be represented by the bitmap: 0110010000.
Write a class, called BitMapSet, that implements the Set interface. Write BitMapSet so that it can b e used to represent sets of numbers between zero and 99. To make the coding easier use an array of Boolean to represent the bitmap.
So here's the Set interface:
Java Code:public interface Set<T>{ /** Adds an element to the set. Attempts to add duplicates result in no Change to the set. @param val The value to be added. **/ public void add(T val); /** Remvoves an element from the set. Does nothing if element is not present. @param val The value to be removed. **/ public void remove(T val); /** Returns true if val is member of the set. @param val The value to be searched for. @return true if the val is in the set. **/ public boolean contains(T val); /** Returns an array representation of the set. @return an array representation of the set. **/ public Object[] toArray(); /** Returns true if the set is empty. **/ public boolean empty(); }
How do I write BitMapSet so that it can be used to represent sets of numbers between 0 and 99? Means I were to create a Set that only allow int from 0 - 99?
use an boolean array to present the bitmap : from what I understand it's storing trues and falses in an array. So I were to supposed that true is 1 and false is 0. with this boolean array, I can then come up with something like 01000101. That's what I think.
Any comments to solve this?
- 07-22-2013, 06:44 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,170
- Rep Power
- 12
Re: Sets Question
Since the Set interface is a generic type you just implement it using the formal type parameter T. So then if you have say MySet you can inovke:
Set<Integer> set = new BitMapSet<Integer>();
According to the instructions, my interpretation is that the bit map set maintains a boolean array of an arbitrary size and unlike the JDK implementations may contain duplicates (containing some number of true or false values). But I encourage you to discuss this with your instructor.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 07-22-2013, 06:53 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,421
- Blog Entries
- 7
- Rep Power
- 26
- 07-22-2013, 07:15 PM #4
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,170
- Rep Power
- 12
Re: Sets Question
I see what you mean. There is no implied or well defined linear relationship in an array of Strings so it wouldn't really make sense.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
Maps and Sets
By darkblue24 in forum New To JavaReplies: 19Last Post: 03-25-2010, 06:13 PM -
Maps and Sets
By RedKMan in forum New To JavaReplies: 3Last Post: 02-16-2010, 09:36 AM -
Duplicates in more than two sets
By JavaJ in forum New To JavaReplies: 8Last Post: 12-03-2009, 04:07 PM
Bookmarks