algorithm

Adapting music in response to events

Curiosity question. Nothing serious to do with it. What are the algorithms and techniques to adapt seamlessly the theme and feeling of a soundtrack to the events the user performs. In other words, how does iMUSE work, and what kind of data do you feed in? ...

Binary search tree traversal that compares two pointers for equality

I'm reading the Cormen algorithms book (binary search tree chapter) and it says that there are two ways to traverse the tree without recursion: using stack and a more complicated but elegant solution that uses no stack but assumes that two pointers can be tested for equality I've implemented the first option (using stack), ...

Help with Ruby on Rails 5 points ranking algorithm

Hello fellows - I'm currently in the process of developing a digg-like Ruby on Rails application for my degree's Final Project and I'm stuck in the 5 point ranking algorithm. There are a couple of factors that need to be involved, here's a breakdown : Users They'll have a personal 5 points ranking per category with 5 being the best ...

Error Correction Advice?

I have an application that ideally would allow 25% of errors to be corrected with an original message that would be 12 to 16 bytes (8-bit bytes) long. The constraints are the message cannot be retransmitted and if parts of message aren't received it will be unknown which bytes did not show up. For example, let's say, I'm using somethin...

Custom paging algorithm to calculate pages to display.

I'm working on a custom data pager for a custom google maps control. The control needs to work out what range of pages to display. For example, if the user is on page 6 then the control must display pages 1 through to 10. If the user is on page 37, then the control must display pages 30 throught to 40. The variables I have available are...

Algorithm for heat map?

I have a list of values each with latitude and longitude. I'm looking to create a translucent heatmap image to overlay on Google Maps. I know there are server side and flash based solutions already, but I want to build this in javascript using the canvas tag. However, I can't seem to find a concise description of the algorithm used to...

finding shortest path from undirected graph

I have two problems; I have to find shortest path from an undirected, weighted graph sending goods to single destination sending goods to multiple destinations Assume all edge weights are positve numbers. Send me suitable algorithms for both problems. ...

Algorithm to add or subtract days from a date?

Hi, I'm trying to write a Date class in an attempt to learn C++. I'm trying to find an algorithm to add or subtract days to a date, where Day starts from 1 and Month starts from 1. It's proving to be very complex, and google doesn't turn up much, Does anyone know of an algorithm which does this? ...

How can I print out all possible letter combinations a given phone number can represent?

I just tried for my first programming interview and one of the questions was to write a program that given a 7 digit telephone number, could print all possible combinations of letters that each number could represent. A second part of the question was, what about if this was a 12 digit international number? How would that effect you de...

Transformation of Linear Column-Major Array Data to Row-Major

I have Fortran-based 3D column-major order array flattened into linear memory. What formula/algorithm can I use map it back to a Java 3D row-major order array? For example, |1, 2, 3| |10, 11, 12| |19, 20, 21| |4, 5, 6| |13, 14, 15| |22 23, 24| |7, 8, 9| |16, 17, 18| |25, 26, 27| Looks like this in memory buffer = 1, 4, 7, 2, 5, 8, 3...

using a key to rearrange string

Using Python I want to randomly rearrange sections of a string based on a given key. I also want to restore the original string with the same key: def rearrange(key, data): pass def restore(key, rearranged_data): pass Efficiency is not important. Any ideas? Edit: can assume key is hashable, but may be multiple types defin...

Another algorithm problem...

I am given N numbers and for them apply M rules about their order. The rules are represented in a pairs of indexes and every pair (A, B) is telling that the number with index A (A-th number) must be AFTER the B-th number - it doesn't have to be next to him. Ex: N = 4 1 2 3 4 M = 2 3 2 3 1 Output: 1234, 4213, 4123, 2134,...

Fastest way to get the set of convex polygons formed by Voronoi line segments

I used Fortune's Algorithm to find the Voronoi diagram of a set of points. What I get back is a list of line segments, but I need to know which segments form closed polygons, and put them together in an object hashed by the original point they surround. What might be the fastest way to find these?? Should I save some crucial informatio...

Confusion in finding the order of the data structure

Hi, Today I attended a written test conducted by a company. The overall test was focussed on data structures. I got a problem which I thought I solved. But I had a tough time in calculating the Big O function for the data structure. I will provide the question and the answer I came up with. Given a document you need to store and the...

Data structure for fast filtering (Delphi)?

I am optimizing a part of a Delphi application where lists of objects are frequently filtered using different criteria. The objects are kept in TObjectList structures and it is common to select a very small percentage (ex. 1%) of the entire set with each filter. The total number of objects can be in the 100k range and during computations...

Planar Graph Layouts

What are some edge overlap minimization techniques when laying out a graph? (Preferably related to GraphViz) Also are there any existing software that can layout a graph in a planar fashion? Current Layout - http://www.evecakes.com/doodles/master.gif The pink section in the upper left hand corner looks fine while the light blue section...

Dynamic Event Conditions

Consider that we've a class named Foo that fires "ready" event when it's ready. from observer import SubjectSet class Foo: def __init__(self): self.events = SubjectSet() self.events.create('ready') def do_sth(self): self.events.fire('ready') As you see, do_sth method makes ready instances of the Foo class. But subcla...

Merging two sorted lists

Hi, This is one of the programming questions asked during written test from Microsoft. I am giving the question and the answer that I came up with. Thing is my answer although looks comprehensive (at least to me), I feel that the number of lines can be reduced. It was asked in C and I am a Java person but I managed to code it (my answer...

Find the numbers missing

If we have an array of all the numbers up to N (N < 10), what is the best way to find all the numbers that are missing. Example: N = 5 1 5 3 2 3 Output: 1 5 4 2 3 In the ex, the number 4 was the missing one and there were 2 3s, so we replaced the first one with 4 and now the array is complete - all the numbers up to 5 are there. I...

Suggestions for algorithmic analysis of Lisp programs?

Which operations in Common Lisp programs are to be considered sufficiently primitive so as to count for a single "step" in algorithmic analysis? How widely do modern lisps vary in their implementation? Certainly arithmetic with small integers would count as a single step, but what about larger numbers? And what about considering the d...