algorithm

Find the shortest path in a graph which visits certain nodes.

I have a undirected graph with about 100 nodes and about 200 edges. One node is labelled 'start', one is 'end', and there's about a dozen labelled 'mustpass'. I need to find the shortest path through this graph that starts at 'start', ends at 'end', and passes through all of the 'mustpass' nodes (in any order). ( http://3e.org/local/m...

tf-idf and previously unseen terms

TF-IDF (term frequency - inverse document frequency) is a staple of information retrieval. It's not a proper model though, and it seems to break down when new terms are introduced into the corpus. How do people handle it when queries or new documents have new terms, especially if they are high frequency. Under traditional cosine match...

Check a string to see if all characters are hexadecimal values

What is the most efficient way in C# 2.0 to check each character in a string and return true if they are all valid hexadecimal characters and false otherwise. Example void Test() { OnlyHexInString("123ABC"); // returns true OnlyHexInString("123def"); // returns true OnlyHexInString("123g"); // returns false } bool OnlyHexIn...

Java: Efficient Equivalent to Removing while Iterating a Collection

Hello everyone. We all know you can't do this: for (Object i : l) if (condition(i)) l.remove(i); ConcurrentModificationException etc... this apparently works sometimes, but not always. Here's some specific code: public static void main(String[] args) { Collection<Integer> l = new ArrayList<Integer>(); for (int i=0; i < 1...

What would be a better implementation of all combinations in lexicographic order of a jagged list?

I was put in a position today in which I needed to enumerate all possible combinations of jagged list. For instance, a naive approach would be: for a in [1,2,3]: for b in [4,5,6,7,8,9]: for c in [1,2]: yield (a,b,c) This is functional, but not general in terms of the number of lists that can be used. Here is a ...

Removing Duplicate Images

We have a collection of photo images sizing a few hundred gigs. A large number of the photos are visually duplicates, but with differing filesizes, resolution, compression etc. Is it possible to use any specific image processing methods to search out and remove these duplicate images? ...

Scheduled Report(task) Monitor

I have to develop a system to monitor the generation/transmission of reports. System data will be stored in database tables (Sybase) Reports will be generated with different schedules ("mon-fri 10pm", "sat 5am", "1st day of the month", etc.) System will just monitor that the reports were created. It will not create the reports itself....

Resources for image distortion algorithms

Where can I find algorithms for image distortions? There are so much info of Blur and other classic algorithms but so little of more complex ones. In particular, I am interested in swirl effect image distortion algorithm. ...

Optimal Rectangle hatching algorithm

Hi, I am looking for an algorithm to hatch a rectangle with shortest overall line length, so that an object of given area can be passed through the hatching. For example given a rectangle of 5x3 cm, and I hatch using parallel lines 1cm across, the biggest object I can pass through the hatch is a square of 1cm side. I have used an overa...

Best way to reverse a string in C# 2.0

I've just had to write a string reverse function in C# 2.0 (i.e. LINQ not available) and came up with this: public string Reverse(string text) { char[] cArray = text.ToCharArray(); string reverse = String.Empty; for (int i = cArray.Length - 1; i > -1; i--) { reverse += cArray[i]; } return reverse; } Per...

On Path Finding: a detailed description for a layman of the D* algorithm

The large network (of small world graph type) I wish to deal with is dynamic in nature, new nodes are added and subtracted frequently. Presumably using D* over A* would be a better way to detect paths in this dynamic environment? How solid is D*? has it had any real world experience? like a cryptographic algorithm - is D* hardened by l...

Char.IsHex() in C#

Following on from this question what would be the best way to write a Char.IsHex() function in C#. So far I've got this but don't like it: bool CharIsHex(char c) { c = Char.ToLower(c); return (Char.IsDigit(c) || c == 'a' || c == 'b' || c == 'c' || c == 'd' || c == 'e' || c == 'f') } ...

Algorithm: Odometer / Brute force

I want to write a odometer-like method in a C#-style-language, but not just using 0-9 for characters, but any set of characters. It will act like a brute-force application, more or less. If I pass in a char-array of characters from 0 to J, and set length to 5, I want results like 00000, 00001, 00002... HJJJJ, IJJJJJ, JJJJJ. Here is the...

Double-metaphone errors

I'm using Lawrence Philips Double-Metaphone algorithm with great success, but I have found the odd "unexpected result" for some combinations. Does anyone else have additions or changes to the algorithm for other parts of it they wouldn't mind sharing, or just the combinations that they've found that do not work as expected. eg. I had i...

How would you write a non-recursive algorithm to calculate factorials?

How would you write a non-recursive algorithm to compute n!. ...

Knowing the plaintext, how to discover the encryption scheme used?

I have some char() fields in a DBF table that were left encrypted by a past developer in the project. However, I know the plaintext result of the decryption of several records. How can I determine the function/algorithm/scheme to decrypt the original data? These are some sample fields: For cryptext: b5 01 02 c1 e3 0d 0a plaintext s...

Tetris Piece Rotation Algorithm

What are the best algorithms (and explanations) for representing and rotating the pieces of a tetris game? I always find the piece rotation and representation schemes confusing. Most tetris games seem to use a naive "remake the array of blocks" at each rotation: http://www.codeplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=t...

Javascript Array.sort implementation?

Which algorithm does the JavaScript Array.sort() function use? I understand that it can take all manner of arguments and functions to perform different kinds of sorts, I'm simply interested in which algorithm the vanilla sort uses. ...

How does Google's In Quotes work?

I find Google's In Quotes a really nifty application, and as a CS guy, I have to understand how it works. How do you think it turns news articles into a list of quotes attributed to specific persons? Sure, there are some mistakes, but their algorithm seems to be smarter than just a simple heuristic or multiple regular expressions. For ex...

Friendship relations tracking algorithm

I'm thinking of an application that would try to prove the "Six degrees of separation" theory with a set of users that are part of a social network. I would have those elements: A couple of users for which I'd like to prove the six degrees theory For each user, I know the list of friends in the social network Which is the best algor...