algorithm

Longest path between from a source to certain nodes in a DAG

Hi Experts, How do i find the longest path from single source to all final destinations i.e. For source i1, Give longest path between i1 -> o1 and i1 -> o2. The legends described in the above graph are as follows: (i1, i2) are start nodes (o1, o2) are end nodes (1-8) are sub graphs The edges may have +ive/-ive weights The lon...

What is the most efficient (read time) string search method? (C#)

I find that my program is searching through lots of lengthy strings (20,000+) trying to find a particular unique phrase. What is the most efficent method for doing this in C#? Below is the current code which works like this: The search begins at startPos because the target area is somewhat removed from the start It loops through the ...

How does the PageRank algorithm handle links?

We discussed Google's PageRank algorithm in my algorithms class. What we discussed was that the algorithm represents webpages as a graph and puts them in an adjacency matrix, then does some matrix tweaking. The only thing is that in the algorithm we discussed, if I link to a webpage, that webpage is also considered to link back to me. ...

Is minimization of boolean expressions NP-Complete?

I know that boolean satisfiability is NP-Complete, but is the minimization/simplification of a boolean expression, by which I mean taking a given expression in symbolic form and producing an equivalent but simplified expression in symbolic form, NP-Complete? I'm not sure that there's a reduction from satisfiability to minimization, but I...

How to check if a number is a power of 2

Today I needed a simple algorithm for checking if a number is a power of 2. The algorithm needs to be: Simple Correct for any ulong value. I came up with this simple algorithm: private bool IsPowerOfTwo(ulong number) { if (number == 0) return false; for (ulong power = 1; power > 0; power = power << 1) { ...

What's the smart way to implement OrderBy / ThenBy?

I'm implementing a LINQ clone in Lua, but that's not too relevant here, and I've got most features done (enumerable/queryable, not the precompiler yet), but can't think of a smart way to implement OrderBy's ThenBy. Currently I sort once, then place in new lists and then sort those sub lists and finally merge the results again, but that...

permute i and T[i]

Hi, Assuming that I have an array of int T, I am looking for an in-place algorithm that permute i and T[i] I have : [3 2 0 1] (a) I want : [2 3 1 0] (b) eg. in (b) T[0] = 2 because, in (a) T[2] was equal to 0. I was expecting to find a simple O(n) time, O(1) space algorithm, but I can't find it. Any ideas ? Note : There is one ...

Generating Synthetic DNA Sequence with Subtitution Rate

Given these inputs: my $init_seq = "AAAAAAAAAA" #length 10 bp my $sub_rate = 0.003; my $nof_tags = 1000; my @dna = qw( A C G T ); I want to generate: One thousand length-10 tags Substitution rate for each position in a tag is 0.003 Yielding output like: AAAAAAAAAA AATAACAAAA ..... AAGGAAAAGA # 1000th tags Is there a compact ...

Ranking newer items fairly?

Using StackOverflow itself as an example, if you had any such system where entries were voted and viewed in order of rank based on this, how do you compensate to sort newer entries fairly? That is, if ten bad answers are given and upvoted, how do you make sure people see the new entry that might be better, but hasn't had time to gather v...

Which algorithm for extremely high non burst errors?

I have a binary stream that has a very high error rate. The error rate is 50% meaning each bit has a 50% chance of being flipped. The error does not occur in bursts and is completely random, so Reed–Solomon codes wouldn't work well. Which scheme or algorithm should I apply to the stream? I don't care about the overhead at all. This ...

List<T> or LinkedList<T>

I need a data structure that holds a list of elements of the same type. Needed features are Add GetEnumerator (may be) Clear An indexed access, sorting, searching, removing of elements are not required. What is the best collection class for it? The following aspects should be taken in consideration: performance, memory usage, behavio...

What is the correct algorthm for a logarthmic distribution curve between two points?

I've read a bunch of tutorials about the proper way to generate a logarithmic distribution of tagcloud weights. Most of them group the tags into steps. This seems somewhat silly to me, so I developed my own algorithm based on what I've read so that it dynamically distributes the tag's count along the logarthmic curve between the thresh...

How to build a distributed robust linked list on several computers on the net?

I was thinking about building a program that use a raid(disk) like algorithms. If one computer dies. The next will step in. In it's place. And it need to scale from 1 - 1000 computers. I need some advice. What the name of the algorithms I'm need to learn? At one point I thought it was possible to build it on top of git. ...

convert vector of strings/doubles to arrays

I am using matheval library. Its functions take c-style parameters, for example: #include<matheval.h> char * evaluator_evaluate(void * evaluator, int count, char **names, double *values); In my case, I want to convert std::vector of names and std::vector of values to char ** and double * Also, every name correspond to a uni...

What are the enduring properties of a book on algorithms?

I will soon start writing a book on a certain subset of algorithms. Many people, including myself, praise The Art of Computer Programming to the top of their lungs, believing these volumes are a work of art in mathematics and computer science. However, I can't put my finger on what it is that makes TAOCP mythically great, mostly when com...

Finding an axis-aligned rectangle inside a polygon

I am looking for a good algorithm to find an axis-aligned rectangle inside a (not necessarily convex) polygon. A maximal rectangle would be nice, but is not necessary - any algorithm that can find a "fairly good" rectangle would be fine. The polygon may also have holes, but any pointers to algorithms that only work for convex or simple ...

Linearly recursive list-difference function in Common Lisp.

I was going through this tutorial for fun, and got stuck on the very last thing he says, "Exercise: Give a linearly recursive implementation of union and difference." (for a list) Union, no sweat. Difference, sweat. An attempt looks like this. . . (defun list-diff (L1 L2) (cond ((null L1) L2) ((null (member (first L1) L2...

Counting with an Integer Divide-based routine - Is there a formulaic approach?

Consider a routine that counts by successive divide w/ remainder operations. Starting with a 64-bit dividend, the routine divides by a constant divisor. If the remainder is 0, the routine returns. Otherwise, a new dividend is constructed by multiplying the remainder by 2^32 and adding the integer quotient. In code: /// ULong ...

Reasonable optimized chart scaling.

I need to make a chart with an optimized y axis maximum value. The current method I have of making charts simply uses the maximum value of all the graphs, then divides it by ten, and uses that as grid lines. I didn't write it. Update Note: These graphs have been changed. As soon as I fixed the code, my dynamic graphs started working, ...

Resolving ambiguous categories in an ordered list

Let's take a concrete example and hope I can be clear. Suppose the (ordered) list of months: January < February < March < ... < December (with integers that stand for the months, zero-based), such that Jan is 0, Feb is 1, ..., Dec is 11. Now suppose I do not have access to the full names of months, and am given the followi...