algorithm

Algorithm for finding all combinations of k elements from stack of n "randomly"

Hello, I have a problem resembling the one described here: http://stackoverflow.com/questions/127704/algorithm-to-return-all-combinations-of-k-elements-from-n I am looking for something similar that covers all possible combinations of k from n. However, I need a subset to vary a lot from the one drawn previously. For example, if I wer...

Are there any other uses for Perlin Noise besides the obvious?

I have been looking into different algorithms lately and have read quite alot about perlin noise. It seems like the only thing people use it for is to generate textures (clouds/wood grain) or to distribute trees. What else can Perlin Noise be used for? ...

Graphs: find a sink in less than O(|V|) - or show it can't be done

I have a graph with n nodes as an adjacency matrix. Is it possible to detect a sink in less than O(n) time? If yes, how? If no, can you prove it? Sink: a node that has incoming edges from all other nodes and no outgoing edges. ...

Algorithm for generating a software stack diagram

I'm looking for ideas for an algorithm that generates a diagram similar to the following, given a set of acyclic dependencies (I'm using this image to show that the dependencies can be complex) ...

sed optimization question (large file modification based on smaller dataset)

Hi all, I do have to deal with very large plain text files (over 10 gigabytes, yeah I know it depends what we should call large), with very long lines. My most recent task involves some line editing based on data from another file. The data file (which should be modified) contains 1500000 lines, each of them are e.g. 800 chars long. ...

Determining the worst-case complexity of an algorithm

Can someone please explain to me how one can determine the worst-case complexity of an algorithm. I know that the we need to use the equation W(n) = max{t(I)|I element of D), where D is the set of inputs of size n. Do I calculate the number of operations performed for each element I and then take its max? What easier way is there to acco...

Multi-threaded algorithm for solving sudoku?

I have a homework assignment to write a multi-threaded sudoku solver, which finds all solutions to a given puzzle. I have previously written a very fast single-threaded backtracking sudoku solver, so I don't need any help with the sudoku solving aspect. My problem is probably related to not really grokking concurrency, but I don't se...

Faster way to sum a list of numbers than with a for-loop?

Is there a way to sum up a list of numbers faster than with a for-loop, perhaps in the Python library? Or is that something really only multi-threading / vector processing can do efficiently? Edit: Just to clarify, it could be a list of any numbers, unsorted, just input from the user. ...

c4.5 algorithm implementation on unix/mac os

I am trying to compile and execute the c4.5 algorithm on my mac os machine (have a red hat enterprise linux 4.6 machine too), but have not been able to get anywhere with the same. Is there any one who has tried this and succeed on getting the same to compile and execute on their machines? If, so, please can you share the steps? ...

Calculating all possible sub-sequences of a given length (C#)

If I have a sequence as follows (let's say it's an IEnumerable<T>): [A, B, C, D, E] Then what's the cleanest way to compute all possible (continuous and non-continuous) sub-sequences of a given length? Ordering of the output isn't important, but it shouldn't include duplicates. e.g. If I want to compute all possible sub-sequences of...

Adding a separator to a list of items for display

I have a list of items that I wish to display with a separator between them in C#. Using a normal iterator I would end up with an extra separator at the beginning or the end: string[] sa = {"one", "two", "three", "four"}; string ns = ""; foreach(string s in sa) { ns += s + " * "; } // ns has a trailing *: // one * two * three * four...

Best clustering algorithm? (simply explained)

Hello! Imagine the following problem: You have a database containing about 20,000 texts in a table called "articles" You want to connect the related ones using a clustering algorithm in order to display related articles together The algorithm should do flat clustering (not hierarchical) The related articles should be inserted into the...

Best match between two strings when the order or number of times a word appears is not important?

What is the best algorithm to match or compute the distance between two strings in C# when the order or number of times a word appears is not important? Best means: Would mostly agree with a human match Elegant Efficient Scalable, so that an input string could be matched to a potentially large collection of other strings Related que...

Does a hash function output need to be bounded less than the number of buckets?

I was reading about this person's interview "at a well-known search company". http://asserttrue.blogspot.com/2009/05/one-of-toughest-job-interview-questions.html He was asked a question which led to him implementing a hash table. He said the following: HASH = INITIAL_VALUE; FOR EACH ( CHAR IN WORD ) { HASH *= MAGIC_NUMBER HASH ^= CHAR...

equality of matrices of m * n

What is the most efficient way for checking for equality of two m * n matrices and more importantly the [i][j] index (or indices) which caused the two matrices to be unequal. In my case, 'm' is relatively small (<=4) and n is relatively large (<=512). Context of the problem : I have an Active Standby setup for my application. Whenever ...

How can I improve this square root method?

I know this sounds like a homework assignment, but it isn't. Lately I've been interested in algorithms used to perform certain mathematical operations, such as sine, square root, etc. At the moment, I'm trying to write the Babylonian method of computing square roots in C#. So far, I have this: public static double SquareRoot(double x) ...

Selecting a Unique Identifier in C for an Embedded Application

I am currently trying to implement an algorithm to select a unique (16-bit) identifier. The challenge is to do this in an fast way that doesn't use too much memory. The list of currently used identifiers is determined through scanning an external Flash device via a sequence of SPI transactions and is therefore a relatively slow process...

Implementing Licencing mechanism for a Software

I am thinking of implementing a good licensing mechanism that has a good resistance against piracy. The required mechanism should not use an internet connection at each and every time the software is used. I am thinking of a mechanism based on hardware IDs etc. Do you guys have any better suggestions? What are the parameters/algorithms/c...

Question on Levenshtein distance

1) Why do we add 1 on these line? d[i-1, j] + 1, // deletion d[i, j-1] + 1, // insertion The line if s[i] = t[j] then cost := 0 else cost := 1 should take into account deleted/lower word lengths, or am I missing something? 2) Also, the comments state deletion and insertion. Am I right in thinking that it's chec...

diplomacy game judge algorithm

I am writing a server for playing the great diplomacy game online. Does anyone know an algorithm for the judge, that will calculate all moves/supports/convoys on the map at the end at each round? For implementing the protocol I use twisted, for db-access django ...