algorithm

How can I shuffle a list without randomness, and guarantee that a portion of elements will eventually appear on one side?

Given a list of elements, does a shuffling algorithm exist that will guarantee that eventually a selected half portion will be on one side, and the remainder on the other? Example: { 4, 3, 10, 7, 2, 9, 6, 8, 1, 5 } Given the set above, I'd like to have a mixing algorithm that eventually moves the marked ones to the left, even though...

Large-scale pseudoinverse

I would like to compute the Moore–Penrose pseudoinverse of an enormous matrix. Ideally, I would like to do it on a matrix that has 23 million rows and 1000 columns, but if necessary I can reduce the number of rows to 4 million by only running on one part of my experiment. Obviously, loading the matrix in to memory and running SVD on it...

Matrix Decomposition

I have a square n*n matrix S that has to be decomposed into a product of two matrices - A1 and A2, where A2 is transposed matrix to A1 (A2=A1^T) , so A1 * A2 = S. Are there any algorithms to do such operation effectively? C#/C++ solution would be nice. ...

An algorithm to check if a vertex is reachable.

Hi! Is there an algorithm that can check, in a directed graph, if a vertex, let's say V2, is reachable from a vertex V1, without traversing all the vertices? ...

How does google know if I type in redflower.jpg I mean Red Flower?

I'm curious what the programming terms or methodology is used when Google shows you the "did you mean" link for a word that is made up of multiple words? For example if I type in "redflower.jpg" It knows to break that up into Red Flower Is there a common paradigm for doing that sort of operation? Would a Lucene search give you that? th...

Optimization problem - finding a maximum

I have a problem at hand which can be reduced to something like this : Assume a bunch of random points in a two-dimension plane X-Y where for each Y, there could be multiple points on X and for each X, there could be multiple points on Y. Whenever a point (Xi,Yi) is chosen, no other point with X = Xi OR Y = Yi can be chosen. We have ...

How to find all matching numbers, that sums to 'N' in a given array

My goal here is to find all possible combinations that sums to a given total. For example, if the array is 2 59 3 43 5 9 8 62 10 4 and if the total is 12, then possible combinations are 2 10 3 9 8 4 5 3 4 Here is the first set of code, that I've written. Wondering the best improvements that can be done on this. int find_numbers...

least common divisors

what i am trying is write recursive function which return least common divisor or for example let take let take 150 and 125 greatest common divisor is 25 while least common divisor is 5 once again i need recurive fucntion in direct method it is trivial ...

Efficient Packing Algorithm for Irregular Polygons

I'm looking for a packing algorithm which will reduce an irregular polygon into rectangles and right triangles. The algorithm should attempt to use as few such shapes as possible and should be relatively easy to implement (given the difficulty of the challenge). It should also prefer rectangles over triangles where possible. If possibl...

How to find all grid squares on a line?

I'm trying to implement a line-of-sight algorithm on a 2-dimensional grid. I know how it needs to work conceptually, but I can't think of how to implement it as an algorithm. The basic idea is pretty simple. In pseudocode: function LineOfSight(point1, point2): boolean squares = GetListOfSquaresOnLine(point1, point2) for each squa...

Price Filter Grouping Algorithm

I am creating an ecommerce site, and I am having trouble developing a good algorithm to sort a products that are pulled from the database into halfway appropriate groups. I have tried simply dividing the highest price into 4, and basing each group off that. I also tried standard deviations based around the mean. Both could result with pr...

Stretching out an array

I've got a vector of samples that form a curve. Let's imagine there are 1000 points in it. If I want to stretch it to fill 1500 points, what is the simplest algorithm that gives decent results? I'm looking for something that is just a few lines of C/C++. I'll always want to increase the size of the vector, and the new vector can be a...

Given a set of top/bottom pixel ranges, how do I find which one has been scrolled into?

The Problem As the page is scrolled from top to bottom, the user will pass through these ranges. Suppose they are values in an alphabetical address book: as they scroll from top to bottom, they will pass from A to Z. There are tabs on the side labeled with the names of sections in the document, labeled 'Aa-An', 'Am-As', etc. What I wan...

How do I map a spherical triangle to a plane triangle?

The gnomonic projection maps spherical triangles to straight-edged plane triangles. But I've heard that the Chamberlin trimetric projection has less distortion, so I'd like to use that instead. Alas, when I use my (extremely rough and probably buggy) implementation of Chamberlin trimetric projection to map the spherical triangle formed ...

how to compress an unsorted list of numbers?

I am working on compressing graphs. The graph is represented as an adjacency list i.e each node in graph maintains a list of adjacent nodes. The lists contain Node_IDs(4 byte integers) and they are ordered by popularity of each Node_ID(score). So, I end with up unsorted list of Node_ID numbers and I have to compress them while maintainin...

Simple Algorithm for Matrix Inverse

I want to implement a program to calculate the Inverse of a matrix in F(2) (only 0 and 1) . Please let me know if you can think of any algorithm or just simple algo for inverse of Matrix. ...

What is an inner miter calculation?

I found the following algorithm to generate polygon outlines: void CGlShape::GenerateLinePoly(std::vector<DOUBLEPOINT> &input, int width) { OutlineVec.clear(); if(input.size() < 2) { return; } if(connected) { input.push_back(input[0]); input.push_back(input[1]); } float w = width / 2.0f; //glBegin(GL_TRIANGLES); for...

algorithms problem in uniform cost solution

I am doing the unifrom cost search algorithm. I am getting my solution slightly larger than actual. The number of expanded nodes are coming larger than actual. I used this algorithm: Get the initial node and put it into the priority queue.The P.queue will itself arranges the nodes in it according to the cost. Lower cost node will come ...

Any benefits of learning 3d software rasterization & theory before jumping into OpenGL/Direct3D?

I came across a very interesting book. I have done some 2d games but 3D is a whole new ballpark for me. I just need to know if there any benefits of learning 3d software rasterization & theory before jumping into OpenGL/Direct3D? Any reason why to either approach? Thanks in advanced! ...

Parsing an canonical path with wildcards.

I am writing the C# function which retrieves some files matched pattern. Input : C:\abc*\abc?\testfile.* Output : All files matched. I thought I could make it by recursion. But it was not easy :( Do you have a nice algorithm? Update: I made it. Thanks Kieren :) void PrintAllFiles(DirectoryInfo currentDir, string...