algorithm

Computing number of permutations of two values, with a restriction on runs

I was thinking about ways to solve this other question about counting the number of values whose digits sum to a target, and decided to try the case where the range was of the form [0, n^base). So essentially you get N independent digits to work with, which is a simpler problem. The number of ways N natural numbers can sum to a target T...

Find the 2nd largest element in an array with minimum # of comparisom.

For an array of size N, what is the # of comparisons required? ...

C++ minimax function

I have searched Google and Stackoverflow for this question, but I still don't understand how a minimax function works. I found the wikipedia entry has a pseudocode version of the function: function integer minimax(node, depth) if node is a terminal node or depth <= 0: return the heuristic value of node α = -∞ for ch...

Cube on Cube collision detection algorithm?

I'm trying to find the most efficient way to check if 2 arbitrarily sized cubes collide with each other. The sides of the cubes are not necessarily all equal in length (a box is possible). Given these constraints, how could I efficiently check if they collide? (each box has 24 verticies) Thanks They are axis alligned ...

What's the big O of this little code snippet?

for i := 1 to n do j := 2; while j < i do j := j^4; I'm really confused when it comes to Big-O notation, so I'd like to know if it's O(n log n). That's my gut, but I can't prove it. I know the while loop is probably faster than log n, but I don't know by how much! Edit: the caret denotes exponent. ...

C# Algorithm to assign matches between teams in a sport

Possible Dup: Help Me Figure Out A Random Scheduling Algorithm using Python and PostgreSQL Let's say you have a division with 9 teams, and you want them to play 16 games each. Usually you would want to have 8 games (Home), and 8 games (Visitor). Is there a known algorithm to go in and assign the matches, randomly? Note -> It can, somet...

Median Algorithm in O(log n)

How can we remove the median of a set with time complexity O(log n)? Some idea? ...

What is the "m-bridge technique" for partitioning binary trees for parallel processing?

How does it work? Please explain in enough detail in English or pseudocode so that I can implement in any language. It is mentioned and briefly described in this paper: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.4.3643&amp;rep=rep1&amp;type=pdf but there isn't enough detail there to implement myself. (the weights in Fig...

Geo-region data for countries/states/oceans

I'm developing an application where entities are located at positions on Earth. I want to have a set of data from which I can determine what region(s) a point is contained within. Regions may be of types: Continent Country Lake Sea DMZ Desert Ice Shelf ...and so forth. I'm envisioning representing each region as a polygon. For an...

Path Similarity in a Directed Graph

I was wondering if anyone knows of a graph-theoretic algorithm that provides a metric for determining the pairwise similarity between paths through a directed graph? I imagine the simplest algorithms/metrics just counts the number of nodes common to both paths and does some sort of weighting in the case of comparing paths of different le...

Bezier curves algorithm - maybe Canonical Splines?

I've got a path that is made up of multiple points - i.e. 0,0 0,50 50,50 70,20 If I just draw this line on the screen it looks quite harsh as it puts a sharp angle at the joining of each point. Hence I was wondering what the bezier curves algorithm/method would look like which I could call that automatically change the sharp angles ...

Is this Project Euler #5 solution more efficient than a known one?

Here's my solution to Project Euler problem #5: #include <stdio.h> #include <stdint.h> #define N 20 int main( int argc, char* argv[] ) { uint64_t r = 1; uint64_t i, j; for( i = 2; i <= N; ++i ) if( (j = r%i) ) r *= ( (i%j) ? i : (i/j) ); printf( "\n%llu\n", r ); return 0; } It is of O(n) efficiency. ...

c+ stl sorted vector inplace union

I'd like an efficient method for doing the inplace union of a sorted vector with another sorted vector. By inplace, I mean that the algorithm shouldn't create a whole new vector or other storage to store the union, even temporarily. Instead, the first vector should simple grow by exactly the number of new elements. Something like: vo...

Algorithm to find hole in an infinite one dimensional graph

A cow is standing in front of an infinite fence . On the other side is grass. The cow wants to get to this grass. Somewhere along this fence is a hole through which the cow can get to the other side. The distance d from the cow to the hole has a probability distribution f(d) associated with it i.e. the probability that the hole is k step...

Calculating which item is next in a percentage distribution

I'm working on a project that involves diverting phone calls to a number of destinations. For example, I want: 10% of calls to go to destination A 20% of calls to go to destination B 30% of calls to go to destination C 40% of calls to go to destination D The number of destinations and their percentages must be configurable. I've ...

apply graph analysis on networked data represented with RDF

I want to run some analysis on networked data having multiple modes(i.e. multiple types of network nodes) and multiplex relations(i.e. multiples types of network edges). The analysis is probably about SNA or applying any algorithm from graph theory, e.g. tie strength, centrality, betweenness, node distance, block, cluster, etc. The sou...

Open source queuing theory algorithms in Java

I need to write a program to analyze the performance of computer systems and networks using queuing theory (http://en.wikipedia.org/wiki/Queueing_theory). I was wondering if there is an open source Java library implementing the various algorithms of queuing theory that can make my task easier. Does anyone have any recommendations? ...

Traversing weighted graph through all vertecies ending up at the same point

Is there an algorithm that will allow me to traverse a weighted graph in the following manner? Start at a specific node Go through all vertecies in the graph Do this in the least amount of time (weights are times) End up at the starting node ...

Greatest Common Divisor from a set of more than 2 integers

There are several questions on Stack Overflow discussing how to find the Greatest Common Divisor of two values. One good answer shows a neat recursive function to do this. But how can I find the GCD of a set of more than 2 integers? I can't seem to find an example of this. Can anyone suggest the most efficient code to implement this ...

How to detect the "likeness" of data

Generally speaking, can you suggest an approach which would let me test objects to make sure they are alike. Accept that objects are alike if over 'n%' worth of content of the object is identical. Other then a brute force, are there any libraries available i can take advantage of? thanks ...