Hash function f(a, b) = f(b,a) [closed] - algorithm

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
I need simple hash function that takes two parameters, with the following parameters:
a,b,c,d are different strings (approximately 30 characters)
f(a,b) = f(b,a)
f(a,c) ≠ f(a,d)
f(c,b) ≠ f(d,b)

Sort and concatenate the two parameters (to ensure that f(a,b) equals f(b,a). Since there are only two items to sort the result will be either ab or ba.
If the strings have the property that ab may equal cd (for example strong + hearted and strongheart + ed) you may want to "salt" the string by prepending it with the length of the first string coded in a fixed number of bytes.
Then apply a string hash on the result. There are numerous examples online.
Note that there is no guarantee that two different strings won't result in the same hash value, but a good hash algorithm will reduce the probability.

Related

Using FFT to find all possible sum [closed]

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 2 years ago.
Improve this question
Given array A[] and B[], to find how frequently each possible sums A[i] + B[j] appears we can use FFT
For example
A = [1,2,3], B = [2,4].
The sum 3 can be obtained in 1 way, sum 4 : 1 way, sum 5 : 2 ways, sum 6 : 1 way, sum 7 : 1 way
The way we can do this is to construct two polynomials, P and Q with their power corresponding to the element of the array. And apply the regular FFT.
So is there an efficient way of backtracking the numbers that forms the above. To elaborate, we know 3 can be formed in 1 way. But how do we know which two numbers form it?
One way to do it would be the classic two sum algorithm, i.e given an array and a target sum. Find the pairs that create the sum. Which is O(n)
Given we can have N different targets, the resulting algorithm is O(n^2). But I want to keep it under O(nlogn).

Possible Array combinations based on constraints [closed]

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
How many unique arrays of m elements exist such that they contain numbers in the range [1,n] and there exists atleast one subsequence {1,2,3,4....n}?
Constraints: m > n
I thought of combinations approach. But there will be repetitions.
In my approach, I first lay out all the numbers from 1 to n.
For example, if m=n+1, answer is n^2. (n spots available, each number in range [1,n])
Now, I think there might be a DP relation for further calculation, but I am not being able to figure it out.
Here's an example for n=3 and m=5. The green squares are the subsequence. The subsequence consists of the first 1 in the array, the first 2 that's after the first 1, etc. Squares that aren't part of the subsequence can either take n values if they are after the end of the subsequence, or n-1 values otherwise.
So the answer to this example is 1*9 + 3*6 + 6*4 = 51, which is easily verified by brute force. The coefficients 1,3,6 appear to be related to Pascal's triangle. The rest is left to the reader.

Number of passwords [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I've read this interesting problem:
how many different passwords made up of a upper case letters, b lower case letters, c digits and d characters from this set {'$','%','!','&','#'} exist?
This could be used to suggest strong passwords.
This is a basic combinatorics problem.
First of all, you have two base 26 numbers of lengths a and b, a base 10 number of length c and a base 5 number of length d. You have to multiply the number of these numbers to the number of ways you can arrange them, so you get:

Map N integers to [1,N] [closed]

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 7 years ago.
Improve this question
I'm looking for an efficient way to map a N integers to [1,N].
The N integers are actually entries of a sorted array A with no redundancies, and my goal is to be able to simply access the index of every entry of the array.
Example :
For a given array A of integers, sorted and without redundancies, but with gaps and possibly very large numbers (you could have 1000 integers ranging from 25 to 10^6), I need a way of finding the index of every entry in an efficient way. For example if A[15] = 1546, I need to be able to do index(1546) = 15.
My problem is that I need to do this in Fortran, and as far as I know, there are no real hash table libraries.
I think, you can use a binary search for solve your problem. It is simple for code.
Look this page [Binary search in array issue using Fortran
Using binary search you get the inverse index of the given number.

What is the professional term for the combination of the selection in n out of the total m elements? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I know the number of combinations is called nCr, but what about all the exact outcomes?
For example:
I have 3 elements a,b,c and for the param 2, I will have outcomes
ab
ac
ba
bc
ca
cb
I want to search different implementations of this. but I don't know what term should I input in google.
Just realized your question is basically wrong.
You are speaking about combinations yet you are expecting results like "ab" and "ba". A basic property of combinations is the fact they are unordered, that is, for a set {a, b, c}, 2-combinations will be {ab}, {ac}, {bc}, nothing else.
The term you are looking for is a variation or partial permutation. For variations, the order of elements matters.

Resources