algorithm

RFC calculation in Java need help with algorithm

The RFC for a Java class is set of all methods that can be invoked in response to a message to an object of the class or by some method in the class. RFC = M + R where M = Number of methods in the class. R = Total number of other methods directly invoked from the M. Thinking C is the .class and J is the .java file of which we need to ...

How to maintain a recursive invariant in a MySQL database?

I have a tree encoded in a MySQL database as edges: CREATE TABLE items ( num INT, tot INT, PRIMARY KEY (num) ); CREATE TABLE tree ( orig INT, term INT FOREIGN KEY (orig,term) REFERENCES items (num,num) ) For each leaf in the tree, items.tot is set by someone. For interior nodes, items.tot needs to be th...

Red-Black Trees

I've seen binary trees and binary searching mentioned in several books I've read lately, but as I'm still at the beginning of my studies in Computer Science, I've yet to take a class that's really dealt with algorithms and data structures in a serious way. I've checked around the typical sources (Wikipedia, Google) and most descriptions...

Calculating a cutting list with the least amount of off cut waste.

I am working on a project where I produce an aluminium extrusion cutting list. The aluminium extrusions come in lengths of 5m. I have a list of smaller lengths that need to be cut from the 5m lengths of aluminium extrusions. The smaller lengths need to be cut in the order that produces the least amount of off cut waste from the 5m len...

How do I find the Excel column name that corresponds to a given integer?

How would you determine the column name (e.g. "AQ" or "BH") of the nth column in Excel? Edit: A language-agnostic algorithm to determine this is the main goal here. ...

Prime factors

What is the best approach to calculating the largest prime factor of a number? I'm thinking the most efficient would be the following: Find lowest prime number that divides cleanly Check if result of division is prime If not, find next lowest Go to 2. I'm basing this assumption on it being easier to calculate the small prime factors...

Calculating Distance Between 2 Cities

How do you calculate the distance between 2 cities? ...

Factorial Algorithms in different languages

I want to see all the different ways you can come up with, for a factorial subroutine, or program. The hope is that anyone can come here and see if they might want to learn a new language. Ideas: Procedural Functional Object Oriented One liners Obfuscated Oddball Bad Code Polyglot Basically I want to see an example, of different way...

What algorithm to compare two images

Hello! My task is pretty simply (well, it SOUNDS simple): given two different image file (in whatever format I choose), I need to write a program to predict the chance if one is the illegal copy of another. The author of the copy may do stuffs like rotating, make negative, or adding trivial details (as well as changing the dimension of ...

What is your experience with software model checking?

What types of applications have you used model checking for? What model checking tool did you use? How would you summarize your experience w/ the technique, specifically in evaluating its effectiveness in delivering higher quality software? In the course of my studies, I had a chance to use Spin, and it aroused my curiosity as to how...

An O(1) Sort ~~~

Before you stone me for being a heretic, There is a sort that proclaims to be O(1), called "Bead Sort" (http://en.wikipedia.org/wiki/Bead_sort) , however that is pure theory, when actually applied I found that it was actually O(N * M), which is pretty pathetic. That said, Lets list out some of the fastest sorts, and their best case and ...

How can I measure the similarity between two images?

I would like to compare a screenshot of one application (could be a Web page) with a previously taken screenshot to determine whether the application is displaying itself correctly. I don't want an exact match comparison, because the aspect could be slightly different (in the case of a Web app, depending on the browser, some element coul...

Your favourite algorithm and the lesson it taught you.

What algorithm taught you the most about programming or a specific language feature? We have all had those moments where all of a sudden we know, just know, we have learned an important lesson for the future based on finally understanding an algorithm written by a programmer a couple of steps up the evolutionary ladder. Whose ideas and...

Equation (expression) parser with precedence?

I've developed an equation parser using a simple stack algorithm that will handle binary (+, -, |, &, *, /, etc) operators, unary (!) operators, and parenthesis. Using this method, however, leaves me with everything having the same precedence - it's evaluated left to right regardless of operator, although precedence can be enforced usin...

Impose a total ordering on all instances of *any* class in Java

I'm unsure whether the following code would ensure all conditions given in Comparator's Javadoc. class TotalOrder<T> implements Comparator<T> { public boolean compare(T o1, T o2) { if (o1 == o2 || equal(o1, o2)) return 0; int h1 = System.identityHashCode(o1); int h2 = System.identityHashCode(o2); ...

Fastest way to calculate primes in C#?

I actually have an answer to my question but it is not parallelized so I am interested in ways to improve the algorithm. Anyway it might be useful as-is for some people. int Until = 20000000; BitArray PrimeBits = new BitArray(Until, true); /* * Sieve of Eratosthenes * PrimeBits is a simple BitArray where all bit is an integer * and ...

Resources of techniques use for collision detection in 2D?

What are in your opinion the best resources (books or web pages) describing algorithms or techniques use for collision detection in a 2D environment? I'm just eager to learn different techniques to make more sophisticated and efficient games. Thanks. :D ...

How to detect duplicate data?

I have got a simple contacts database but I'm having problems with users entering in duplicate data. I have implemented a simple data comparison but unfortunately the duplicated data that is being entered is not exactly the same. For example, names are incorrectly spelled or one person will put in 'Bill Smith' and another will put in 'Wi...

Algorithmic complexity of XML parsers/validators

I need to know how the performance of different XML tools (parsers, validators, XPath expression evaluators, etc) is affected by the size and complexity of the input document. Are there resources out there that document how CPU time and memory usage are affected by... well, what? Document size in bytes? Number of nodes? And is the relati...

Does anyone have a good Proper Case algorithm

Does anyone have a trusted Proper Case or PCase algorithm (similar to a UCase or Upper)? I'm looking for something that takes a value such as "GEORGE BURDELL" or "george burdell" and turns it into "George Burdell". I have a simple one that handles the simple cases. The ideal would be to have something that can handle things such as "O...