algorithm

3d bin packing algorithm

I am looking for a deterministic implementation for any 3d bin packing algorithm, i.e. for packing many small and different cuboids inside one or many bigger ones. The solution could vary from the optimal one. It should be written in C, C++, Java, C#, IronPython, IronRuby or any other language an can bin to from .Net code. I found this...

How to implement MapThread with basic list mapping?

Mathematica has a function MapThread that behaves like this: MapThread[ f , { {a,b,c} , {d,e,f} } ] -> { f[a,d] , f[b,e] , f[c,f] } I'd like to implement this in TeX, which has very primitive programming facilities. I've basic facilities for iterating over lists, but no logical indexing into them. Given this restriction, is there an a...

Edit Distance Algorithm

I have a dictionary of 'n' words given and there are 'm' Queries to respond to. I want to output the number of words in dictionary which are edit distance 1 or 2. I want to optimize the result set given that n and m are roughly 3000. Edit added from answer below: I will try to word it differently. Initially there are 'n' words given ...

Fast algorithm to check membership of a pair of numbers in large (x,y) coordinates in Perl

I have a list of sorted coordinates (let's call it xycord.txt) that looks like this: chr1 10003486 10043713 chr1 10003507 10043106 chr2 10003486 10043713 chr2 10003507 10043162 chr2 10003532 10042759 In reality the this file is very2 large with 10^7 lines. What I want to do is given a...

What's the most efficient way to partition a large hash into N smaller hashes in Ruby?

The Problem I'm working on a problem that involves sharding. As part of the problem I need to find the fastest way to partition a large Ruby hash (> 200,0000 entries) in two or more pieces. Are there any non O(n) approaches? Is there a non-Ruby i.e. C/C++ implementation? Please don't reply with examples using the trivial approach ...

Why is my Polymorphic Parent class calling the Subclass Method from within itself?

Heres the code I've made up so far. Its fully functional and the only gripe I have with it is that my output for Weekly and Annual pay is always weekly...I'm at a loss as to how to get this from within either toString method. public class PolyEmployees { public static void main(String[] args) { Employee [] myEmployees = { ...

Java Algorithm for finding the largest set of independent nodes in a binary tree

By independent nodes, I mean that the returned set can not contain nodes that are in immediate relations, parent and child cannot both be included. I tried to use Google, with no success. I don't think I have the right search words. A link, any help would be very much appreciated. Just started on this now. I need to return the actual...

How to compute the absolute minimum amount of changes to convert one sortorder into another?

Goal How to encode the data that describes how to re-order a static list from a one order to another order using the minimum amount of data possible? I have a feeling there is an algorithm or computer science term that will help me but right now I'm too stuck on the problem to figure out other ways of looking at it. Background Motivat...

Enabling behavior based on bit values

I have a series of behaviors I want to enable/disable based on bit values. For example, the status of Behavior "A" is 0 or 1, Behavior "B" is 0 or 2, Behavior "C" is 0 or 4, etc. If the value of the variable containing the status is "5", I know Behavior "A" and "C" are enabled. "B" is not. My program should then toggle on A & C. I'm not...

how many float point operations for a strassen algorithm for a matrix of size k*k

I am trying to understand this http://en.wikipedia.org/wiki/Strassen%5Falgorithm#Numerical%5Fanalysis But i am still not too sure how many operations are invovled? ...

C#: Implementation of the Sieve of Atkin

I was wondering if someone here have a good implementation of the Sieve of Atkin that they would like to share. I am trying to implement it, but can't quite wrap my head around it. Here is what I have so far. public class Atkin : IEnumerable<ulong> { private readonly List<ulong> primes; private readonly ulong limit; publi...

C#: How to make Sieve of Atkin incremental

I don't know if this is possible or not, but I just gotta ask. My mathematical and algorithmic skills are kind of failing me here :P The thing is I now have this class that generates prime numbers up to a certain limit: public class Atkin : IEnumerable<ulong> { private readonly List<ulong> primes; private readonly ulong limit; ...

What does this recursive snippet of Java code do?

I passed through this recursion example, but I couldn't find out its purpose. Could you please help me? public static int somerec(int n, int x, int y) { if (n < x*y) return 0; else if (n == x*y) return 1; else { int sum = 0; for (int i = x; i <= n;i++) sum += somerec(n-i, i, y-1);...

tree traverse recursive in level-first order and depth-first order

Hello, Is there any algorithm can traverse a tree recursively in level-first order and non-recursively in postorder.Thanks a lot. ...

Clock Speed Formula

Guys, Is there a simple way to determine how many milliseconds I need to "Sleep" for in order to "emulate" a 2 mhz speed. In other words, I want to execute an instruction, call System.Threading.Thread.Sleep() function for an X amount of milliseconds in order to emulate 2 mhz. This doesn't need to be exact to the millisecond, but is ther...

duplicacy problems while creating a sudoku puzzle

I am trying to create my own normal 9x9 sudoku puzzle. I divided the problem into two parts - creating a fully filled sudoku, and removing unnecessary numbers from the grid Right now, I am stuck with the first part. This is the algorithm I use in brief: a) first of all I choose a number (say 1), generate a random cell position,...

Java Need help implementing an algorithm

This algorithm is so advanced for my basic programming skills that I just don't see how I could implement it. I'm posting this in a new question because I can't keep bothering the guy who gave me the algorithm alone about this in the comment section in the previous question. MaxSet(node) = 1 if "node" is a leaf MaxSet(node) = Max(1 + S...

Fastest way to scan for bit pattern in a stream of bits

I need to scan for a 16 bit word in a bit stream. It is not guaranteed to be aligned on byte or word boundaries. What is the fastest way of achieving this? There are various brute force methods; using tables and/or shifts but are there any "bit twiddling shortcuts" that can cut down the number of calculations by giving yes/no/maybe co...

Many to many and writing a semi-smart matching algorithm

Hello community, I'm learning to program with Ruby on Rails and I've reached my hardest task yet. I have two tables, each containing a list of business categories (I.E. Thai Food Restaurant, Plumber, Office Supply Store). These two tables come from two different APIs where I'm essentially acting as the middle-man between them. They list...

How do I find the nearest prime number?

Is there any nice algorithm to find the nearest prime number to a given real number? I only need to search within the first 100 primes or so. At present, I've a bunch of prime numbers stored in an array and I'm checking the difference one number at a time (O(n)?). ...