algorithm

Can diff be beaten at its own game?

I'm looking for the appropriate algorithm to use to compare two files. I think I can do better than diff due to some added constraints. What I have are two text files each containing a list of files. They are snapshots of all the files on a system taken at two different times. I want to figure out which files have been added or deleted ...

How does STL algorithm work independent of Iterator type?

How does STL algorithm work independent of Iterator type? ...

Parallel algorithms and data structures

Inkeeping with my interests in algorithms (see here), I would like to know if there are (contrary to my previous question), algorithms and data structures that are mainstream in parallel programming. It is probably early to ask about mainstream parallel algos and ds, but some of the gurus here may have had good experiences/bad experience...

How to make a circle on a grid?

I'm making a game where all movement is grid based. I also wan't to make entities that can travel around in a circle. So does anyone have any suggestions for creating a circle out of a grid of squares (like the way MS Paint uses the circle tool to make a circle out of square pixels). ...

Sorting strings containing numbers in a user friendly way

Being used to the standard way of sorting strings, I was surprised when I noticed that Windows sorts files by their names in a kind of advanced way. Let me give you an example: Track1.mp3 Track2.mp3 Track10.mp3 Track20.mp3 I think that those names are compared (during sorting) based on letters and by numbers separately. On the other h...

Generating Ordered (Weighted) Combinations of Arbitrary Length in PHP

Given a list of common words, sorted in order of prevalence of use, is it possible to form word combinations of an arbitrary length (any desired number of words) in order of the 'most common' sequences. For example,if the most common words are 'a, b, c' then for combinations of length two, the following would be generated: aa ab ba bb a...

Calculating phi(k) for 1<k<N

Given a large N, I need to iterate through all phi(k) such that 1 < k < N quickly. Since the values of N will be around 1012, it is important that the memory complexity is sub O(n). Is it possible? If so, how? ...

Get Bytes from an int to avoid bit shifting fun - Java (Median Filtering)

Hi All, I'm trying to perform a Median filter on an image in Java but it's terribly slow. Firstly, if any of you know of a standalone implementation I could use it would be fantastic if you could let me know. I'm implementing on Android, trying to replicate a small part of the JAI. In my method I take each pixel, extract the R,G & B va...

How to compute a 3D Morton number (interleave the bits of 3 ints)

I'm looking for a fast way to compute a 3D Morton number. This site has a magic-number based trick for doing it for 2D Morton numbers, but it doesn't seem obvious how to extend it to 3D: http://www-graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN So basically I have 3 10-bit numbers that I want to interleave into a single 30 b...

Compare three-dimensional structures

I need to evaluate if two sets of 3d points are the same (ignoring translations and rotations) by finding and comparing a proper geometric hash. I did some paper research on geometric hashing techniques, and I found a couple of algorithms, that however tend to be complicated by "vision requirements" (eg. 2d to 3d, occlusions, shadows, et...

Popularity Algorithm

Hi, I'm making a digg-like website that is going to have a homepage with different categories. I want to display the most popular submissions. Our rating system is simply "likes", like "I like this" and whatnot. We basically want to display the submissions with the highest number of "likes" per time. We want to have three categories: ...

Calculate missing date ranges and overlapping date ranges between two dates

I have the following set of dates (dd/MM/yyyy) matching events in my database: eventId startDate endDate 1 02/05/2009 10/05/2009 2 08/05/2009 12/05/2009 3 10/05/2009 12/05/2009 4 21/05/2009 21/05/2009 5 25/05/2009 NULL 6 01/06/2009 03/06/2009 The ev...

What common algorithms are used for C's rand()?

I understand that the C specification does not give any specification about the specific implementation of rand(). What different algorithms are commonly used on different major platforms? How do they differ? ...

How to convert a byte array to its numeric value (Java)?

Hi everyone, I have an 8 byte array and I want to convert it to its corresponding numeric value. e.g. byte[] by = new byte[8]; // the byte array is stored in 'by' // CONVERSION OPERATION // return the numeric value I want a method that will perform the above conversion operation. ...

Comparison method for sorting that shuffles equal elements randomly

Here's a puzzle for you. I want to change the following comparison method, so that when two items are considered equal, they will be shuffled randomly. myList.Sort( (x, y) => x.Score.CompareTo(y.Score) ); I could imagine that this scenario would be useful when ordering search results if you didn't want to give preference to one resul...

Begin+End given - how many "transactions" at the same time

I have couple of data, which includes the beginning of a transaction and its end in a DateTime format. I want to figure out how many transaction are running at the same time. Is there any algorithm that could solve my problem? ...

Long running methods from Java SDK for testing purposes

I'm working through some tutorials and examples of java.util.concurrent package. Usually example authors put a placeholder marked with a comment 'long running task'. Since these examples are about concurrent programming I'm not keen of using Thread.sleep(long), surrounded by try-catch blocks. What do you use in these circumstances? To ...

Job queue optimization algorithms

We have an application that requires assignment of jobs to resources. The resources have a number of attributes that define their suitability to a particular job -- some are preferences, some are hard constraints (all of the membership variety, e.g. "resource A is suited to jobs with color X, Y, or Z". Resources have a cost associated w...

Enumerating all strings meeting given restrictions

I'm looking for the name of the following class of problem, so that I can google for effective algorithms and more information. I have an alphabet with three characters {-1, 0, 1}. I need to effectively generate all strings of length 24 which are mostly {0} but have zero to eight {1,-1} characters distributed in certain patterns. (The...

Good datastructure for look up of an id mapping to set of elements (c++)

No boost, just plain STL please. I have a class Foo* mapping to a set of pointers of class ID. and I need to map a pointer to an instance of ID to a FOO class. say I have this function: void FindXXX(const ID* pID) { /*find the containing FOO class quickly, but not at expense of an ugly code*/ } right now I map each ID* to FOO...