algorithm

Shortest path with a fixed number of edges

We were discussing this problem in class, and were unable to come up with a solution I found satisfying. The problem: Find the shortest path through a graph in efficient time, with the additional constraint that the path must contain exactly n nodes. We have a directed, weighted graph. It may, or may not contain a loop. We can easily f...

transitive reduction algorithm: pseudocode?

I have been looking for an algorithm to perform a transitive reduction on a graph, but without success. There's nothing in my algorithms bible (Introduction To Algorithms by Cormen et al) and whilst I've seen plenty of transitive closure pseudocode, I haven't been able to track down anything for a reduction. The closest I've got is that ...

Find quickest way to get from wepage A to webpage B following links

I'm looking for an algorithm to find the shortest path between two URL's, or two Wikipedia pages. For example, the shortest way to get from the wikipedia article of Reddit to the article of Computer science is to follow the link to Science, where there is a link to Computer science. Assume that all links are static, and that it is impr...

Algorithm to generate random order of elements

How to randomize order of approximately 20 elements with lowest complexity? (generating random permutations) ...

Best way to convert epoch time to "real" date/time

What I want to do is convert an epoch time (seconds since midnight 1/1/1970) to "real" time (m/d/y h:m:s) So far, I have the following algorithm, which to me feels a bit ugly: void DateTime::splitTicks(time_t time) { seconds = time % 60; time /= 60; minutes = time % 60; time /= 60; hours = time % 24; time /= 24;...

Applying a function to a distance matrix in R.

This question came today in the manipulatr mailing list. http://groups.google.com/group/manipulatr/browse_thread/thread/fbab76945f7cba3f I am rephrasing. Given a distance matrix (calculated with dist) apply a function to the rows of the distance matrix. Code: library(plyr) N <- 100 a <- data.frame(b=1:N,c=runif(N)) d <- dist(a,diag...

how to solve linear equations using genetic algorithm

hello i want to solve a system of n linear equations containing n variables using genetic algorithm. i am having difficulty in defining the crossover operation as the solution may consist of floating point values. how do i proceed. seems possible but this is my first encounter with genetic algorithms so your help would be great. suppos...

comparing objects

I have two student objects. class Student{ int physics; int english; int chemistry; } I need to compare Student A marks in each subject with Student B's marks in all the subjects. A marks in physics needs to be compared with B's marks in physics, english, chemistry. Similarly A's english with all the three of B. if there is atleast ...

Algorithm to sort

Hi, I have a list of numbers ex: list=[10,50,90,60] I have this list to be sorted on the sum of any two elements. along with combination. for ex: output list should contain 10+50,10+90,10+60,50+90,50+60,90+60 sorted in ascending. i.e outputlist=[[60,10,50],[70,10,60].... [similar to shake hand problems in permutations and combinatio...

Append value to multidimensional array

function append (array, value, dimension) { switch (dimension) { case 0: array.push( value ); break; case 1: array[array.length-1].push( value ); break; case 2: array[array.length-1][array[array.length-1].length-1].push( value ); break; case 3: array[array.length-1][array[array....

Create a sorted array out of 2 arrays

There are 2 arrays given for ex. A = [20,4,21,6,3] B = [748,32,48,92,23......] assuming B is very large and can hold all the elements of array A. Find the way in which array B is in (containing all the elements of array A as well) sorted order. Design an algorithm in the most efficient way. ...

Lineary separate two sets

I have three arrays (it's written in C but that is not important, it could be any language): float x[] = { 0.72, 0.91, 0.46, 0.03, 0.12, 0.96, 0.79, 0.46, 0.66, 0.72, 0.35, -0.16, -0.04, -0.11, 0.31, 0.00, -0.43, 0.57, -0.47, -0.72, -0.57, -0.25, 0.47, -0.12, -0.58, -0.48, -0.79, -0.42, -0.76, -0.77 }; flo...

Graph Isomorphism

Is there an algorithm or heuristics for graph isomorphism? Corollary: A graph can be represented in different different drawings. What s the best approach to find different drawing of a graph? ...

How can I concatenate two arrays in C?

How do I concatenate two arrays to get a single array containing the elements of both original arrays? ...

Help with Perceptron

Here is my perceptron implementation in ANSI C: #include <stdio.h> #include <stdlib.h> #include <math.h> float randomFloat() { srand(time(NULL)); float r = (float)rand() / (float)RAND_MAX; return r; } int calculateOutput(float weights[], float x, float y) { float sum = x * weights[0] + y * weights[1]; return (sum >...

Algorithm for solving Sudoku

I want to write a code in python to solve a sudoku puzzle. Do you guys have any idea about a good algorithm for this purpose. I read somewhere in net about a algorithm which solves it by filling the whole box with all possible numbers, then inserts known values into the corresponding boxes.From the row and coloumn of known values the kno...

Fast modulo 3 or division algorithm?

Hello is there a fast algorithm, similar to power of 2, which can be used with 3, i.e. n%3. Perhaps something that uses the fact that if sum of digits is divisible by three, then the number is also divisible. This leads to a next question. What is the fast way to add digits in a number? I.e. 37 -> 3 +7 -> 10 I am looking for somethin...

Why lookup in SortedDictionary<> is SLOWER than lookup in Dictionary<> ?

As as human I always thought that lookup in something sorted is the way faster than lookup in not sorted. But looking at this http://dotnetperls.com/sorteddictionary I can say that I was wrong. Maybe anyone can explain why it is so ? ...

How can I rebuild my base of algorithms/data structures knowledge?

I recently graduated from UMass Amherst with a B.S. in Computer Science. I maintained a 4.00 GPA, and I feel like I received a very solid education in most areas of the discipline. In my junior year, I took the Data Structures and Algorithms course. I feel that it was poorly taught. I breezed through it and understood the majority of th...

How to implement efficient sorting algorithms for multiple processors with Scala?

How to implement efficient sorting algorithms for multiple processors in Scala? Here's the link for radix algorithm in GPU: radix algorithm in GPU ...