algorithm

Algorithm to format text to Pascal or camel casing

Using this question as the base is there an alogrithm or coding example to change some text to Pascal or Camel casing. For example: mynameisfred becomes Camel: myNameIsFred Pascal: MyNameIsFred ...

What is a good open source B-tree implementation in C?

I am looking for a lean and well constructed open source implementation of a B-tree library written in C. It needs to be under a non-GPL license so that it can be used in a commercial application. Ideally, this library supports the B-tree index to be stored/manipulated as a disk file so that large trees can be built using a configurable ...

Popularity algorithm

On SO 18 Joel mentioned an algorithm that would rank items based on their age and popularity and it's based on gravity. Could someone post this? C# would be lovely, but really any language (well, I can't do LISP) would be fine. ...

Pattern recognition algorithms

In the past I had to develop a program which acted as a rule evaluator. You had an antecedent and some consecuents (actions) so if the antecedent evaled to true the actions where performed. At that time I used a modified version of the RETE algorithm (there are three versions of RETE only the first being public) for the antecedent patte...

What is tail-recursion?

Whilst starting to learn lisp, I've come across the term tail-recursive. What does it mean? ...

Best algorithm to test if a linked list has a cycle

What's the best (halting) algorithm for determining if a linked list has a cycle in it? [Edit] Analysis of asymptotic complexity for both time and space would be sweet so answers can be compared better. [Edit] Original question was not addressing nodes with outdegree > 1, but there's some talk about it. That question is more along the ...

Finding your own number in a box

100 (or some even number 2N :-) ) prisoners are in a room A. They are numbered from 1 to 100. One by one (from prisoner #1 to prisoner #100, in order), they will be let into a room B in which 100 boxes (numbered from 1 to 100) await them. Inside the (closed) boxes are numbers from 1 to 100 (the numbers inside the boxes are randomly perm...

Natural Sorting algorithm

How do you sort an array of strings naturally in different programming languages? Post your implementation and what language it is in in the answer. ...

What is a good Hash Function?

What is a good Hash function? I saw a lot of hash function and applications in my data structures courses in college, but I mostly got that it's pretty hard to make a good hash function. As a thumble rule to avoid collisions my professor said that: function Hash(key) return key mod PrimeNumber end (mod is the % operator in C and sim...

How do you build a ratings implementation?

We have need for a "rating" system in a project we are working on, similar to the one in SO. However, in ours there are multiple entities that need to be "tagged" with a vote up (only up, never down, like an increment). Sometimes we will need to show all of the entities in order of what is rated highest, regardless of entity type, basica...

Finding a single number in a list

What would be the best algorithm for finding a number that occurs only once in a list which has all other numbers occurring exactly twice. So, in the list of integers (lets take it as an array) each integer repeats exactly twice, except one. To find that one, what is the best algorithm. ...

What Are High-Pass and Low-Pass Filters?

Graphics and audio editing and processing software often contain functions called "High-Pass Filter" and "Low-Pass Filter". Exactly what do these do, and what are the algorithms for implementing them? ...

What is the most efficient way to keep track of a specific character's index in a string?

Take the following string as an example: "The quick brown fox" Right now the q in quick is at index 4 of the string (starting at 0) and the f in fox is at index 16. Now lets say the user enters some more text into this string. "The very quick dark brown fox" Now the q is at index 9 and the f is at index 26. What is the most effi...

Is this minimum spanning tree algorithm correct?

The minimum spanning tree problem is to take a connected weighted graph and find the sub set of it's edges with the lowest total weight that keeps the connected restriction but results in an acyclic graph. The algorithm I am considering is: Find all cycles. remove the largest edge from each cycle. The impetus for this version is an ...

Is there an n-ary tree implementation in Perl?

I'm writing a Perl script and would like to use a n-ary tree data structure. Is there a good implementation that is available as source code (rather than part of a Perl library) ? ...

True random number generator

Sorry for this not being a "real" question, but Sometime back i remember seeing a post here about randomizing a randomizer randomly to generate truly random numbers, not just pseudo random. I dont see it if i search for it. Does anybody know about that article? ...

What lightweight neural networks are there for Java?

I have a specific problem of having to decide in a fuzzy way between various outputs from a given set of metrics. It's a perfect candidate for neural network approaches. I've used Joone in the past with success but I'm a little scared of its 2MB jar file for something that in my mind can be done in far less code than that. Of course t...

What's a good algorithm to generate a maze?

Say you want a simple maze on an N by M grid, with one path through, and a good number of dead ends, but that looks "right" (i.e. like someone made it by hand without too many little tiny dead ends and all that). Is there a known way to do this? ...

Optimizing Conway's 'Game of Life'

To experiment, I've (long ago) implemented Conway's Game of Life (and I'm aware of this related question!). My implementation worked by keeping 2 arrays of booleans, representing the 'last state', and the 'state being updated' (the 2 arrays being swapped at each iteration). While this is reasonably fast, I've often wondered about how to...

What kind of problems are state machines good for?

What kind of programming problems are state machines most suited for? I have read about parsers being implemented using state machines, but would like to find out about problems that scream out to be implemented as a state machine. ...