algorithm

Generating a set of random events at a predefined frequency

I have a set of events that must occur randomly, but in a predefined frequency. i.e over a course of (totally) infinite events, event A should have occured 10% of the times, event B should have occured 3%, and so on... Of course the total sum of the percentages of the event list will add upto 100. I want to achieve this programmaticall...

Prefix search in a radix tree/patricia trie

I'm currently implementing a radix tree/patricia trie (whatever you want to call it). I want to use it for prefix searches in a dictionary on a severely underpowered piece of hardware. It's supposed to work more or less like auto-completion, i. e. showing a list of words that the typed prefix matches. My implementation is based on this ...

Algorithm for suggesting products

What's a good algorithm for suggesting things that someone might like based on their previous choices? (e.g. as popularised by Amazon to suggest books, and used in services like iRate Radio or YAPE where you get suggestions by rating items) ...

Erlang Implementation of A Star Search Algorithm

Hi all, I need an Erlang implementation of the A* search algorithm. Any pointers? ...

How to turn plural words singular?

I'm preparing some table names for an ORM, and I want to turn plural table names into single entity names. My only problem is finding an algorithm that does it reliably. Here's what I'm doing right now: If a word ends with -ies, I replace the ending with -y If a word ends with -es, I remove this ending. This doesn't always work however...

How to determine a strings dna for likeness to another

I am hoping I am wording this correctly to get across what I am looking for. I need to compare two pieces of text. If the two strings are alike I would like to get scores that are very alike if the strings are very different i need scores that are very different. If i take a md5 hash of an email and change one character the hash change...

Best way to find recurring values in a set

What is the best way to find the most recurring values in a set? I'd like to use a one-pass algorithm, assuming that values are from the 1,2,3,4,..,m domain? If I had to write an algorithm to do that, how would I do that? ...

Partial, or wrapped multiplication - can anyone identify this function ?

I am hoping for insight into what looks like a partial multiplication. #define LOW(x) ((x)&0xffffffff) #define HIGH(x) ((x)>>32) unsigned long long NotMultiply(unsigned long long x, unsigned long long y) { return HIGH(x)*HIGH(y) + LOW(x)*LOW(y); } This function is iterated multiple times, as follows: unsigned long long DoBusy...

Some pointers on implementing algorithms in code

Hi, The other day I thought I'd attempt creating the Fibonacci algorithm in my code, but I've never been good at maths. I ended up writing my own method with a loop but it seemed inefficient or not 'the proper way'. Does anyone have any recommendations/reading material on implementing algorithms in code? ...

C How to "draw" a Binary Tree to the console

Hi all Im looking for an algorithm( not a library!) i could use to "draw" a binary tree( the tree itself is implemented in C) to the console, so for example a bst with numbers: 2 3 4 5 8 would be shown in the console as : Thanx for all your replyes.... ...

Algorithm for message code validation

Hi! If you read this thread before - forget everything I wrote, I must have been drunk when I wrote it. I'm starting over: I'm currently working on a project where we will be using some sort of algorithm for validating user input. There are three parties to consider; Client - Browsing our web pages Company - We, handling the Client r...

How to write a custom pretty printer

A problem that has frequently come up in my career is I have some kind of data structure (perhaps an s-expression) and I want to print it in a human readable form complete with reasonable indentation choices. Is there a book or blog entry that describes how to do this elegantly? I am interested in the algorithm more than a specific lib...

Algorithm for estimating text width based on contents

This is a long shot, but does anyone know of an algorithm for estimating and categorising text width (for a variable width font) based on its contents? For example, I'd like to know that iiiiiiii is not as wide as abcdefgh, which in turn is not as wide as WWWWWWWW, even though all three strings are eight characters in length. This is a...

Intelligent Selection Algorithm

Hi all, I am using VB.NET and I am trying to come up with some algorithm or some pseudo-code, or some VB.NET code that will let me do the following (hopefully I can explain this well): I have 2 collection objects, Cob1 and Cob2. These collection objects store objects that implement an interface called ICob. ICob has 3 properties. A boo...

Diff Algorithm

I've been looking like crazy for an explanation of a diff algorithm that works and is efficient. The closest I got is this link to RFC 3284 (from several Eric Sink blog posts), which describes in perfectly understandable terms the data format in which the diff results are stored. However, it has no mention whatsoever as to how a program...

Novel fitness measure for evolutionary image matching simulation

I'm sure many people have already seen demos of using genetic algorithms to generate an image that matches a sample image. You start off with noise, and gradually it comes to resemble the target image more and more closely, until you have a more-or-less exact duplicate. All of the examples I've seen, however, use a fairly straightforwar...

What is the benefit for a sort algorithm to be stable?

A sort is said to be stable if it maintains the relative order of elements with equal keys. I guess my question is really, what is the benefit of maintaining this relative order? Can someone give an example? Thanks. ...

What's the fastest way in Perl to get all lines of file1 that do not appear in file2?

I have two (very large) text files. What is the fastest way - in terms of run time - to create a third file containing all lines of file1 that do not appear in file2? So if file1 contains: Sally Joe Tom Suzie And file2 contains: Sally Suzie Harry Tom Then the output file should contain: Joe ...

Using Perl, how can I sort an array using the value of a number inside each array element?

Let's say I have an array, @theArr, which holds 1,000 or so elements such as the following: 01 '12 16 sj.1012804p1012831.93.gz' 02 '12 16 sj.1012832p1012859.94.gz' 03 '12 16 sj.1012860p1012887.95.gz' 04 '12 16 sj.1012888p1012915.96.gz' 05 '12 16 sj.1012916p1012943.97.gz' 06 '12 16 sj.875352p875407.01.gz' 07 '12 16 sj.875408p87543...

Splitting a String into Smaller Parts based on Parens

Using java I am trying to develop a method using recursion to analyze a String of the form: (PART0(PART1(PART2)(PART3))) I want the method to split apart the relevant Strings. I want this method to give me the ability to perform some logic on each part of the String without the parentheses being involved in this order: PART2 PART3 P...