algorithm

BlockSchemes in JavaScript

I need visualizer of algorythmes created in JavaScript. Like BlockSchemes, mostly with If and Statement blocks. That could be moved, resized, connected with arrows. Anybody saw such open source projects? ...

First Name Variations in a Database

I am trying to determine what the best way is to find variations of a first name in a database. For example, I search for Bill Smith. I would like it return "Bill Smith", obviously, but I would also like it to return "William Smith", or "Billy Smith", or even "Willy Smith". My initial thought was to build a first name hierarchy, but I...

Optimizing the speed of insertion in java.util.Map/Set

Hi all, is there a way to optimize the speed of the insertions in a java.util.Collection by specifying the order of the items ? For example java.util.Set<String> set = java.util.TreeSet<String>(); will this solution: set.add("A"); set.add("B"); set.add("C"); set.add("D"); set.add("E"); be faster than this one (random order) ? set...

The best way to calculate the height in a binary search tree? (balancing an AVL-tree)

I'm looking for the best way to calculate a nodes balance in an AVL-tree. I thought I had it working, but after some heavy inserting/updating I can see that it's not working correct (at all). This is kind of a two-part question, the first part would be how to calculate the height of a sub-tree, I know the definition "The height of a no...

Algorithms for Big O Analysis

What all algorithms do you people find having amazing (tough, strange) complexity analysis in terms of both - Resulting O notation and uniqueness in way they are analyzed? ...

Finding how similar two strings are

I'm looking for an algorithm that takes 2 strings and will give me back a "factor of similarity". Basically, I will have an input that may be misspelled, have letters transposed, etc, and I have to find the closest match(es) in a list of possible values that I have. This is not for searching in a database. I'll have an in-memory list o...

Is there a proximity map algorithm or data structure?

A problem I keep running into when writing code that draws images of scientific data is the following: Given some floating point data, fit those data into slots (1-dimensional case) or a grid (2-dimensional case) such that each datum is in the slot or grid entry whose value is closest to the datum's value. It is not the case that the s...

How to implement undirected graph in Ruby on Rails?

I need to implement a undirected graph G = (V,E) in Ruby on Rails and thought of building a Vertex and an Edge model where *Vertex has_many Edges*. As an edge connects exactly two vertices, how would you enforce this in Rails? Do you know any gem or library that would help implementing such a graph (not intrested in re-inventing the w...

Common algorithm for generating a diff of the fields in two beans?

Let's say you have two instances of the same bean type, and you'd like to display a summary of what has changed between the two instances - for example, you have a bean representing a user's settings in your application, and you'd like to be able to display a list of what has changed in the new settings the user is submitting (instance #...

How to output the code itself?

How many ways are there to let the code output itself? For example, write the code below, public class Test { public static void main(String[] args) { // some code } } to output itself public class Test { public static void main(String[] args) { // some code } } (Any programming language is accepted)...

Nonblocking algorithm to generate unique negative numbers

I recently refactored a piece of code used to generate unique negative numbers. edit: Multiple threads obtain these ids and add as keys to a DB; numbers need to be negative to be easily identifiable -at the end of a test session they're removed from the DB. My Java algorithm looks like this: private final Set<Integer> seen = Collec...

Links for simple game algorithms

I was reading that question and I remember of the Wikipedia list of algorithms. I know that Wikipedia have a list of Open Source games too, but what I want is a links for simple game algorithms, even if written in pseudocode. As "simple" games, I mean games like Sudoku, Bejeweled, Solitaire, Minesweeper, Labyrinth, Snakes, Gorilla, Che...

Join a string using delimiters

What is the best way to join a list of strings into a combined delimited string. I'm mainly concerned about when to stop adding the delimiter. I'll use C# for my examples but I would like this to be language agnostic. EDIT: I have not used StringBuilder to make the code slightly simpler. Use a For Loop for(int i=0; i < list.Length; ...

XSLT mapping algorithm

I have a particular problem I'm not sure how to approach. Here at the office there is this large unwieldy XSLT we have for adapting one type of XML to another. The problem is that it's not very consistently written and very difficult to follow. In the ancient creation of this stylesheet, it seems it was forgotten exactly what it does. ...

Alternate UniqueId generation technique

In the application, when special types of objects are created, I need to generate a unique-id for each of them. The objects are created thro' a factory and have a high possibility of being created in a 'bulk' operation. I realize that the "Random" from the framework is not so 'random' after all, so I tried appending the time-stamp as fol...

What is this problem called?

I'm trying to look up this problem but I don't know what it's called. The premise is this: Given m machines and j jobs, where each job can only be assigned to machines i through j, I need to assign the jobs to machines so that I maximize busy machines at one time. I am only concerned with how they are assigned at time 0. I am not concer...

What is the equation to calculate the distance from the end of a line segment to the edge of a circle?

I have a circle with two points inside it that make up a line segment. How can I calculate the distance from one endpoint to the edge of the circle where the line would intersect it? ...

Speed boost to adjacency matrix

I currently have an algorithm that operates on an adjacency matrix of size n by m. In my algorithm, I need to zero out entire rows or columns at a time. My implementation is currently O(m) or O(n) depending on if it's a column or row. Is there any way to zero out a column or row in O(1) time? ...

How to implement a most-recently-used cache

What would be the best way to implement a most-recently-used cache of objects? Here are the requirements and restrictions... Objects are stored as key/value Object/Object pairs, so the interface would be a bit like Hashtable get/put A call to 'get' would mark that object as the most recently used. At any time, the least recently used ...

How do I check if a directed graph is acyclic?

How do I check if a directed graph is acyclic? And how is the algorithm called? I would appreciate a reference. Niko ...