Given a randomly distributed set of keys, with each key mapped to a set of values, how would you transform it into multiple trees?
Example Data Set
NB2 => {NC2 ND2}
ND1 => {NG1 NH1}
NA1 => {NB1}
NB1 => {NC1 ND1 NE1}
NA2 => {NB2}
NC1 => {NF1}
NE1 => {NI1 NJ1 NK1}
Resulting Tree for NA1
NA1
`-- NB1
|-- NC1
| `-- NF1
|-...
I have a linear list of zeros and ones and I need to match multiple simple patterns and find the first occurrence. For example, I might need to find 0001101101, 01010100100, OR 10100100010 within a list of length 8 million. I only need to find the first occurrence of either, and then return the index at which it occurs. However, doing...
Hello,
I need to solve a job affectation problem and I would like to find preferably efficient algorithms to solve this problem.
Let's say there are some workers that can do several kind of tasks. We also have a pool of tasks which must be done every week. Each task takes some time. Each task must be taken by someone. Each worker must...
Am a C# rookie trying to help a friend programatically take a group of twenty people (labelled 1 - 20) and spilt them into five subgroups of four each based upon expressed preferences of who those people wish to be with. Each person in the group of 20 could express 0, 1, 2, 3, or 4 preferences. For example, person 1 could select 0 (no ...
If you're looking at an array of pixels, in either 0,1,2,3, or even N dimensions, it's easy to tell if a certain pixel falls on a square or rectangular grid line within it by using an indicator function like so (I'll use imperative pseudocode to make what I'm talking about clear but I'm really only interested in the constraints and the c...
I'm writing a language interpreter in C, and my string type contains a length attribute, like so:
struct String
{
char* characters;
size_t length;
};
Because of this, I have to spend a lot of time in my interpreter handling this kind of string manually since C doesn't include built-in support for it. I've considered switching...
I have this situation that I need to let users define decisions based on the number of given conditions. For example my program needs to automatically generate a matrix as below given that there are two conditions (IsMale and IsSmoker):
IsMale: YES YES NO NO
IsSmoker: YES NO YES NO
And the deicsion is defined by user, therefore an...
Is there a simple calculation I can do which will convert km into a value which I can add to a lat or lon float to calculate a bounding box for searches? It doesn't need to be completely accurate.
For instance: if I were given a lat/lon for London, England (51.5001524, -0.1262362) and I wanted calculate what the lat would be 25km east/w...
Do I need special book to learn about string algorithms, or it will be enough to pick up a chapter from general books (e.g."Introduction to Algorithms")?
I prefer more code and less theory, and language doesn`t matter. It seems to me that many books on algorithms are outdated. Is it true?
...
I have the following problem - made abstract to bring out the key issues.
I have 10 points each which is some distance from the other. I want to
be able to find the center of the cluster i.e. the point for which the pairwise distance to each other point is minimised,
let p(j) ~ p(k) represent the pairwise distance beteen points j a...
i am looking for a specific data structure, but i forgot its name. if i knew the name it would be trivial, i would just look it up in wikipedia :)
basically, it is like a set - except you cannot iterate it.
you put some values in it, lets say 80k zip codes.
then you can test if a given string is definately NOT a zip code, but you will...
I searched the web for different solutions to the n-queens problem in Haskell but couldn't find any that could check for unsafe positions in O(1) time, like that one that you keep an array for the / diagonals and one for the \ diagonals.
Most solutions I found just checked each new queen against all the previous ones. Something like thi...
Possible Duplicate:
The Art of Computer Programming - What Can I Get From Reading the Lot?
I'm an experienced developer that is trying to buy books that will help her become a better programmer and aid her in solving complex problems.
I'm considering The Art of Computer Programming by Knuth (the first 4 volumes). I know that th...
So a recent question made me aware of the rather cool apriori algorithm. I can see why it works, but what I'm not sure about is practical uses. Presumably the main reason to compute related sets of items is to be able to provide recommendations for someone based on their own purchases (or owned items, etcetera). But how do you go from a ...
I am trying to use boost string algorithms for case insensitive search.
total newbie here.
if I am using it this way, I get an error.
std::string str1("Hello world");
std::string str2("hello");
if ( boost::ifind_first(str1, str2) ) some code;
Converting to char pointers resolves the problem.
boost::ifind_first( (char*)str1.c_str(), ...
Given x number of arrays, each with a possibly different number of elements, how can I iterate through all combinations where I select one item from each array?
Example:
[ ] [ ] [ ]
foo cat 1
bar dog 2
baz 3
4
Returns
[foo] [cat] [ 1 ]
[foo] [cat] [ 2 ]
...
[baz...
I am looking for an algorithm that will take numbers or words and find all possible variations of them together and also let me define how many values to look for together.
Example lets say the string or array is:
cat
dog
fish
then the results for a value of 2 could be:
cat dog
cat fish
dog cat
dog fish
fish cat
fish dog
SO the r...
I have a directed graph with weighted edges (weights are all positive).
Now, I'm looking for an efficient algorithm or code (specifically, C#) to find the longest path between two given vertices.
...
i am going through the above topic from CLRS(CORMEN) (page 834) and I got stuck at this point.
Can anybody please explain how the following expression,
A(x)=A^{[0]}(x^2) +xA^{[1]}(x^2)
follows from,
n-1 `
Σ a_j x^j
j=0
Where,
A^{[0]} = a_0 + a_2x + a_4a^x ... a_{n-2}x^{\frac{n}{2-1}}
A^{[1]} = a_1 + a_3x + ...
over the last few days I've been desperately trying to find a working floodfill algorithm. Of the many algorithms i've tried only the 'recursive line fill' one behaves exactly as it should with the major caveat that it occasionally blows the stack. :(
I have tried many non-recursive implementations I've found on various websites and the...