• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about efficient data structure for my problem

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

Iam developing a complete application for the first time. It is a document processor giving out word counts, Words with more than 'x' characters in length, frequency of words in a document, word search(tells if a word is available or not and if available then gives its frequency).

My question is how do I decide the best data structure to be used for this problem.I believe as words are involved, speed would be a critical issue for large documents. Can someone suggest candidate datastructures and why one might be better than the rest for this problem.Or is it better to use more than 1 data structure?

Thanks
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Pandu.

Given that you're trying to relate word counts, the first thing I'd suggest is a Map object, keyed by the word of interest, and containing a Integer or Long as the value.

Maps are generally the most efficient way to store data when you need quick access by key. You can probably find a faster method with Google, but the sort of speedup you might gain will be counteracted by much greater complexity.

Jeremy
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would also suggest a Map. Use the words as the keys and the store the other details in data object(which could have the frequency etc.). If it's just the frequency you can have the frequency as the value in Map.
[ July 09, 2007: Message edited by: Anupam Sinha ]
 
pandu chinnu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the suggestion, however I am not too familiar with maps.I was thinking of using Lists. Can you guide me if List would be fine or direct me where I can learn basics about maps.(Urls or other resources)
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are a few possible resources:

The sun documentation (J2SE 5.0) for the Map interface.

The sun documentation (J2SE 5.0) for the HashMap class.

Some example code using HashMap and TreeMap.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic