Results 1 to 5 of 5
Thread: Which data structure to use?
- 04-04-2011, 03:06 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 24
- Rep Power
- 0
Which data structure to use?
Hello,
I need a data structure which:
1) I will be able to remove an item (without knowing the index of that item)
2) I can draw an item randomly (normally in an array, I generate a random number and draw that item in that index.. data structures that use keys -hashtables, hashmaps vs need an iterator to go through the items)
3) I will be able to add an item (the adding order does not matter)
Which data structure gives faster solutions?
Thanks..
- 04-04-2011, 04:36 PM #2
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
HashSet can do all of those things. For #2, you have to use the toArray() method, though.
- 04-05-2011, 11:02 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 24
- Rep Power
- 0
Good idea. Have you got any idea about the performance of converting a HashSet to an array?
Thanks for the reply.
- 04-05-2011, 12:03 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
I'm sorry, I don't know the answer to that. I'm guessing it would be O(N), since you have to move the elements one by one. But I'm not sure.
- 04-05-2011, 04:41 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Which data structure to choose ?
By lumpy in forum New To JavaReplies: 2Last Post: 02-20-2010, 04:43 AM -
data structure and data base??
By ahmed13 in forum Advanced JavaReplies: 8Last Post: 03-27-2009, 05:48 AM -
data file structure
By Nicholas Jordan in forum Advanced JavaReplies: 2Last Post: 01-07-2009, 04:16 AM -
Queue data structure
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:35 PM -
data structure code
By vgvt in forum New To JavaReplies: 1Last Post: 01-17-2008, 02:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks