This question already has answers here:
Trie data structures - Java [closed]
(3 answers)
Closed 9 years ago.
I need to create a trie in Java for my Boggle game. I have tried searching for this site for help before hand but only got answers for C or Python but nothing on Java.
Anyways to keep it short, I was wondering how one would go about storing a dictionary (so like a text file of words; around 100k words) into a trie. I've read up about the trie and found it hard to visualize code for it.
Specifically I'm looking for steps to follow when programming (so like what methods I should include and what they do).
Any help would be appreciated!
Have you looked at TrieST? I really suggest you do. Otherwise, I suggest reading this article. Maybe also this one.
Related
This question already has answers here:
Playing an arbitrary tone with Android
(10 answers)
Closed 3 years ago.
So I'm trying to find out if its possible to create some sound waves that I can then manipulate using java, more specifically for the android platform. The Idea is to get integer values and using that, dynamically change pitch/pulse based on user input. I've looked into the soundpool class and it seems that that only handles sampled audio, I'm wondering if there is any way to actually generate it using code.
I'm assuming that if so, each wave generated would have to use it's own thread in order to manipulate them independently. Can someone confirm this?
Any help in the right direction is appreciated.
So I found this question whose highest voted answer is pretty much exactly what I was looking for. In any case, here's the link for reference:
Playing an arbitrary tone with Android
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Using a general-purpose programming language like Java, what is the most efficient way to search through a ~20 page document to replace a set of 5000+ strings with some predetermined replacement string? The program should not replace any strings that have already been replaced. What data structure would be optimal to store the 5000+ strings and each of their replacements - two arrays, a dictionary, or something else?
Here are some of the options that I have considered so far:
Iterate through the entire .txt document once time per string using string.replace. The problem is that the algorithm must iterate through the entire .txt document an extra time for each string stored.
Iterate through the .txt once while replacing string as necessary while creating a new string by appending replacements. This seems more efficient, but each step would still require checking the entire set of 5000+ strings for any strings to replace.
Is there a more optimized means of solving this problem, or is one of the above attempts already optimal?
Also, would it be possible to run this algorithm more efficiently in a lower-level language like C?
You want to replace some string in 5000 strings and you want to make it optimal ... Now my question to you is: How will you know if you have to replace a string if you dont read the string? It's not possible, you have to read everything. And the shortest way to do that is to go line by line and replace immediatly. And somebody can correct me if i'm wrong, but reading a file is one of the most basic operations there is so using a library for that besides what is available by default in the programming language seems total overkill to me. Furthermore, every language has basic io and if it doesn't then don't use it.
To store strings, it all depends what you want to do with them. Different data structures have different purposes and some are better suited in some situations then others. If you just need to store them then a simple array is fine. However, if you need more advanced functions then you need to consider your options. But again it's all up to what you want to do with them later.
And there is the memory issue, you need to calculate how much memory your 5000+ strings will take, because you might run out of memory. Then you need to think if it's worth it to use all that memory. check this link
Finally your question about C, ofcourse it will be more efficient. Java runs in a virtual machine that adds considerable overhead. So basically your Java program runs in another Java program and if you know that there is a cost for every single operation then you understand that C will be more efficient then Java in terms of performance.
I would use the commons-lang library, which I think has exactly what you are looking for. Basically you create one array with all the strings you want to substitute and another array with the substitutions. See http://commons.apache.org/proper/commons-lang/javadocs/api-release/index.html for details on the StringUtils#replaceEach method.
This question already has answers here:
How to determine the size of an object in Java
(28 answers)
Closed 8 years ago.
Yes , this question is little bit vague and any serious programmer would laugh about it ! Although java does not tell about the sizes it assigns to the varibles ,i mean it can give more memory or less memory depending on the situation( that way it is abstracted !)i know that stuff! but what i am asking is ,is there any technique that i can know about the runtime variable size ? i want to find the addresses of the variables too ! This question does not want any answers like ,see java docs it does not provide those functionality you have asked , i want some kind of hack to do this kind of stuff!
Well, There is no such direct way to get accurate size consumed by each object in JVM. Although you can you use JCONSOLE or other similar monitoring tool to get footprints of the objects dynamically. Again, this is more towards monitoring and performance tuning.
Thanks, Anil
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Rule of thumb for choosing an implementation of a Java Collection?
I am looking for a 'Summary' list of all the Java collections detailing the pros and cons of each. I am particularly interested in things like
Which provide faster iteration
Which provide faster search
Which provide slower iteration
Which provide faster insertion or removal
I have seen some sites by searching on Google but i am looking for just a summary preferable in table format.
Thanks in advance.
Take a look at the Collections tutorial, particularly the section on implementations, which includes (in subsections) a discussion of performance characteristics for the various predefined classes. The collections framework is so large, I think, that it would be difficult to summarize everything in a single table.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to determine if an unknown 5 or 6 letter string is a valid word, i.e. is in the dictionary. I could submit the string/word to an online dictionary, but I need to check this string/word, which will be different each time, for about 100 to 150 times. This seems to be a bit time consuming.
My next thought would be to try to get a dictionary program of my own. It would need to be in Java as my program is written in Java. Does the Java API already have a class for doing this? Can I get a descent one that someone has already coded, and all I have to do is submit the string/word to it?
My program is not being used for spell checking. I want to write a program for unscrambling the Jumbled Word Puzzles when I get stuck on a scrambled word. Thanks for your suggestions.
You could use one of the open source dictionaries and load it into a database: ftp://ftp.cerias.purdue.edu/pub/dict/ and ftp://ftp.ox.ac.uk/pub/wordlists/
For scrambled words, you might want to look at the Jumble algorithm, an implementation of which is seen here.
If you don't need spell checking this would be really easy. Just load all your words into a HashSet and then check to see if that set contains the word you want to test. There are tons of word lists available.
If you do need a spell checker, then check out aspell or other free APIs.
aspell and its associated word lists and dictionaries might be the answer.
I think aspell has a Java version.
edit: actually it looks like you might do better with this aspell spinoff called Jazzy.
Maybe you can check some wordlist:
http://wordlist.sourceforge.net/
This page has some word lists in text format, so you can process in Java yourself, most easily using a HashSet. You need to use more efficient data structures if efficiency is important.
Maybe you could try Peter Norvig's spelling checker. I think it's an elegant way to get 80-90% accuracy.