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 7 years ago.
Improve this question
consider the following Strings:
he llo
goodbye
hello
= (goodbye)
(he)(llo)
good bye
helium
I'm trying to sort these in such a way that similar words comes together, I know
alphanumerical sorting is not an option
removing special chars ",-_ and etc then comparing is certainly helpful but results won't be as good as I hope for.
NOTE :
there might be few different desired ouput for this, one of which is :
DESIRED OUTPUT:
hello
he llo
(he)(llo)
helium
goodbye
good bye
= (goodbye)
so my question is that if there is a java package that compares strings and ultimately sort them based on it .
I've heard of terms such as n-gram and skip-gram but didn't quite understand them. I'm not even sure if they can be useful for me at all.
UPDATE:
finding similarities is certainly part of my question but the main problem is the sorting part.
Here's one possible approach.
Calculate the edit distance/Levenshtein distance between each pair of strings and then you use view the strings as a complete graph where the edge weights come from the edit distance. Choose a threshold for those weights and remove all the weights that to high. Then find the cliques in this graph. If your threshold is fairly low perhaps even finding connected components would be an option.
Note:
Perhaps it would be better to substitute some edit distance with one of the similarity measures in the link that #dognose posted.
Also, note that finding cliques will be very slow if you have a large numbers of strings
Related
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 1 year ago.
Improve this question
I'm trying to learn Java. My current assignment is to build a simple four function calculator..... this would be easy given if/else and/ or switch statements, but I'm supposed to build this using methods.
The original input has to be put in as a single string, so, in my mind, I'm going to have to take the single string and create substrings, then somehow convert these substrings into double values, while deleting whatever whitespace could possibly be between characters. My current idea is to somehow identify the "+,-,*, or /" within the string and divide into substrings before and after these values, using the appropriate defined method for whichever operator to do the calculations....
The problem is that I can't see a good way to divide these up into substrings or how to convert the numbers involved into double values. Anyone got any advice for me? Keep in mind, what we have gone through is pretty limited and I feel like I'm missing something REALLY simple out there.
You can split a string based on a particular character using str.split("\\+"), for example. You can convert the split pieces of the string to doubles by using Double.parseDouble(str);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I created a same sized - stack based simple calculator for adding 2 operands. I want to know whether my addition becomes incorrect when specific (valid) values are entered. The 2 stacks take integer values and are having the same number of digits (i.e. 400 [3 digits] and 900 [3 digits]).
It depends on the algorithm you're using. From the question it is not clear, but let's assume your calculator can perform basic arithmetic. First off, you want to test each operation separately, because they have different equivalence classes of their inputs. For example, for multiplication it would be: 0, 1, minimum and maximum values, and their negations. Testing almost always will not be exhaustive, but using equivalence classes, you can pick one value from each class to make sure that each class is covered with a test.
Back to your question, you may use min/max values, and anything that you think may break your code.
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 6 years ago.
Improve this question
Right now I have implemented following algorithm in java for determining all possible candidate keys which is working fine. The link is below:-
http://shubhamshoundic.blogspot.com/2012/08/an-algorithm-to-find-all-possible.html
But in worst case, i.e., if all attributes are present on both sides of the FD (as in case M defined in above link), the number of FD which can be handled are reduced to 12 or 13 .
Reason is limited heap space in java. Following error is being thrown:-
OutOfMemoryError
My request is to help me is in implementing such algorithm which will have simpler complexity (Right now its exponential) to improve the number of FD being handled to at least 20.
Should I try to calculate it using multiprocessing or should I shift to another language rather than java.
It is known from 1978, and presented in all good books on databases, that the problem of finding all the keys requires an algorithm which has an exponential complexity in the worst case (see for instance: Lucchesi, C. and Osborn, S. (1978). Candidate keys for relations. Journal of Computer and System Sciences, 17(2):270–280). Moreover, the problem of finding if an attribute is prime is NP Complete.
This is due to the fact that the number of possible keys is itself exponential with the number of attributes or factorial with the number of functional dependencies.
So, it is impossible to find an algorithm polynomial with the number of attributes or of the functional dependencies.
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 6 years ago.
Improve this question
As we have many Sorting algorithms,I wanted to select the proper sorting algorithm for my case.
For Ex:Insertion sort is best for Small case of numbers ,whereas Merge sort is best suited for Large case of numbers.
I dont know what is that small range of numbers means .i.e 1-100 or 1-1000 or so.
Probably what is the best case for sorting a list of numbers where the same set of numbers are present present repeatedly.I am planning to store it in a hash and then store the elements accordingly .
Whether doing in through hash is a better way or Using some sorting algorithm is the best way
But as here it contains the same data again and again
If you add some elements to already sorted array(list), then you have only small number of inversions. In this case insertion sort will work rather fast.
Alternatives - natural merge sort or TimSort(if implementation is available for your language) - these ones will behave good in all cases, including unsorted arrays.
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 9 years ago.
Improve this question
I'm working on a calculator, it should receive the input as a String and then perform the calculation, outputting the result.
For example, the input could be
((23+17) mod 7 × 4 AND 13
and the output would be 4, as expected.
How can I parse the input, to extract all the operands and perform the calculation ?
The other answers are just "how to set a variable to this result" but if you're actually looking to parse input, you should refer to this:
Equation (expression) parser with precedence?
There are a number of ways to go about solving this kind of problem, and a number of algorithms for doing so. Some of them are stack based, some perform a descent of the "tree", and I can even think of a (somewhat) convoluted way to OOP-ize it. I would start with the link above.
You can use regular expressions to parse the string.
http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html
First you have to look for the most important arguments like [() - parentheses], then less [*/] and [+-]. You have to divide the whole string into parts.
Examples:
Simple calculator (bottom of the page)
Another calculator
Both in Java.
see this page for your reference.
http://www.tutorialspoint.com/java/java_basic_operators.htm
all operators in java are explained very clearly.