TRENDING NEWS

POPULAR NEWS

How To Calculate Hamming Distance Between Two Strings C

How do you find what distance two strings should be?

at the top of their arc, they have no vertical motion, so have only horizontal motion of 7,8cos26 m/s

since there are no horizontal forces acting on the system, the total horizontal momentum is conserved

this means that the total horizontal momentum after pushing equals the total horizontal momentum before pushing

therefore, the total momentum before pushing (horizontally) was 2 m (7,8 cos 26) where m is the mass of each person, the one person moving horizontally has this same momentum after pushing, which means he or she has double the horizontal speed after pushing as before

now, since nothing has been done to effect the vertical motion, the time it will take to return to their original level will be the same as the time it took to reach max height

in this time, the second person is moving twice as fast horizontally and so will cover a distance twice as great in the same time

so calculate the time to reach max height (7.8 sin 26/g)...calculate the horizontal distance traveled in this time; 3 times this distance is the separation of the two swings

alternately, you could solve this as a center of mass problem, knowing the motion of the center of mass is unchanged

if there were no pushing involved, they would each travel a distance D given by the range equation

and this will be the distance traveled by the center of mass; one person will only travel a distance D/2, so the other person must travel 3D/2 so that the center of mass travels a distance D

therefore, the two swings should be 3/2 the range, or 3/2 x v0^2 sin(2*theta)/g = 7.33m

How do I efficiently check whether two strings have edit distance D or not?

One easy way to do so is to calculate the edit distance and just compare it. You can do that using Dynamic Programming and achieve a time complexity of O(n^2) and space complexity of O(n).But, you probably already know that :)So, maybe what you are looking for is Ukkonen's optimization which can get you a time complexity of O(n + d^2). Although I'm not aware of a free version available online of the original paper, this articles may help you:Hal Berghel and David Roach, An Extension of Ukkonen\'s Enhanced Dynamic Programming ASM Algorithmhttp://citeseerx.ist.psu.edu/vie...

Fuzzy String Comparison: Can you explain how Monge Elkan distance is caluculated?

The input string are broken into tokens. The best matching token are compared to get the monge-elkan score.Ex: Input string 1: "paul johnson"Input string 2 : "johson paule" Score : 0.94The algorithm uses  a similarity function (Example: Jaro-Winkler or Levenshtein score)  as inner function.The inner function to compute the scores of the best matching token.Ex: jaro_winkler("paul","johson") = 0jaro_winkler("paul","paule") = 0.96jaro_winkler("johnson","paule") = 0.0jaro_winkler("johnson","johson") = 0.92Monge_elkan = final_score = 1/2*(0.92+0.96) = 0.94

When to use Hamming distance and Levenshtein's distance?

I think it depends on two things:1) The application - what kind of similarity between the strings do you want to measure?2) Complexity- Hamming distance is much, much faster than Levenshtein as a distance metric for sequences of longer length.No, you cannot use Hamming Distance for strings of unequal length. A possible solution might be padding.

What is the time complexity of std::string::find in C++?

Perhaps surprisingly, the standard doesn’t put constraints on the complexity of std::string::find. A common implementation delegates the actual work to std::search (although recently Clang and GCC implementations were tuned to do a little better than that), which is [math]O(m \times n)[/math] where [math]m[/math] and [math]n[/math] are the number of characters in each string. That’s a worst-case bound, however: Usually, the number of character comparisons and iterator updates is closer to the number of elements in the base string (because, typically, the first character of the searched-for string will not match most characters in the base string).The standard library also includes std::boyer_moore_searcher and std::boyer_moore_horspool_searcher, which implement searching algorithms that are potentially faster. However, they’re usually only worthwhile for less common input conditions.

What is the time complexity of printing all the interleaving of two string?

If the strings are length m and n and printing takes constant time, the whole job can be done in [math]O(\binom{m+n}{n})[/math] because there are [math]\binom{m+n}{n}[/math] different interleavings in the case that all characters in the strings are distinct.

How do I group anagrams together from an array of string?

One strategy could be based on letter position. For instance make groups of all the strings that have the same letter at the 1st position. Another group for the strings that have the same letter at the 2nd position and so on. You need to take a call on what to do if there is a tie. For instance what if the groups 1 and 2 have common words. Which group would such a string belong to?Another approach could be using what is called the Minimum Edit Distance. That is to say, the minimum number of operations required to transform one string into the other. Say you have n-strings. Select one string. Compute the edit distance with respect to all the other (n-1) strings. Group all the strings that have the same edit distance with respect to the selected string. Do the same for all the other strings. This approach will result in strings being part of multiple groups.Then you also have Hamming Distance that can be used for grouping. The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. Group the strings that have the same hamming distanceAffinity Propagation is one more way of grouping stringsLook up Jaro Winkler Distance and Lee Distance tooLongest Common Substring distance: Minimum number of symbols that have to be removed in both strings until resulting substrings are identicalQ-grams are typically used in approximate string matching by “sliding” a window of length q over the characters of a string to create a number of 'q' length grams for matching a match is then rated as number of q-gram matches within the second string over possible q-grams.Cosine Similarity is also one possible way of doing this

Given a long sequence of binary strings, how can I efficiently compute the minimum Hamming distance?

I believe that this is equivalent to the Closest pair of points problem and so the optimal algorithm runs in linearithmic time in the number of strings (assuming the strings have constant length).The algorithm is a generalization of the divide and conquer CPoP algorithm to d dimensions (where d is the length of the strings). The algorithm is actually exponential in d. You’ll have to check whether the alternative of checking all pairs mightn’t be faster given the data you have to work with. (It will certainly be faster when n is small, e.g. when you’ve already recursed several times the divide and conquer algorithm.)Here are some slides explaining the optimal algorithm in d dimensions: http://www.cs.ucsb.edu/~suri/cs2...

Assembly Programming Question?

Alright, so you have two strings stored in variables and you want to find their hamming distance.

This is the approach I would take:

You know that the maximum string length is 255, but you only need to worry about the length of the shortest string. So I would find the length of the two strings and whichever was shorter, use that as the sentinel for my loop.

Since you mentioned ASCII, I will assume that your string is comprised of bytes -- 8 bit quantities. Therefore, inside the loop you will want to work with the data on a byte level (e.g. al instead of eax, ax, etc.)

Take the byte in string A and XOR it with the corresponding byte in string B. The result will have 1 set in the bit positions where the bytes differ. Now you need to figure out how many 1's there are in the result -- there are many ways to do this. One of the easiest is to use a progressive bit-mask, testing for one in each position, keeping a count. In other words, you will need another sub-loop that iterates through the 8 bits for each byte.

Keep the totals as you march through the string. When the outer loop is exhausted you are done.

Good luck.

What is the difference between the Kolmogorov complexity with and without the string length given?

The definition of Komolgrov complexity for a given string S and for a given programming language L is the shortest program P such that P - when presented with no inputs - will generate S. However, it might be the case that the value n = |S| is provided as an additional input and comes "free of cost" with respect to the length of the program P.Gilad Tsur suggests then that the maximal difference is O(log(n)) because you could after all, just generate n as a binary number and then proceed from there with the rest of the program. This at least, is one interpretation of the problem statement.Another interpretation - and this will depend on the context in which you are presented the problem statement - is that you are interested in discovering the Komolgrov complexity for a class of strings C such that there is some predicate C-pred where S is a member of the class C if and only if C-pred accepts S. In this case, you might ask about the maximal complexity for any string in the class, or the expectation on the complexity, etc. In this case, the presentation of the length n is simply part of the predicate: limit your class of strings C to only those where you include the condition that |S| = n.Gilad Tsur's interpretation is usually more common, but you may encounter the other interpretation as well.

TRENDING NEWS