algorithm

Is there an algorithm for calculating the multiplicative order of x modulo y (for y < 1000) that doesn't require a BigInteger type?

The algorithm I'm using at the moment runs into extremely high numbers very quickly. A step in the algorithm I'm to raises x to the result of the totient function applied to y. The result is that you can run into very large numbers. Eg. When calculating the multiplicative order of 10 modulo 53: 10^totient(53) == 10^52 == 1 * 10^52 ...

Parse text and return similarities

Let's say I have several URLs and I return the basename from each URL, like so; http://www.test.com/the.code.r00 would return the.code.r00 and I have several basenames I extracted from several URLs to work on the.code.r00 the.code.r01 .. ... the.code.r12 and together with those I have the following basenames too from other URLs ...

Algorithm to find string matches in a sliding window

One of the core steps in file compression like ZIP is to use the previous decoded text as a reference source. For example, the encoded stream might say "the next 219 output characters are the same as the characters from the decoded stream 5161 bytes ago." This lets you represent 219 characters with just 3 bytes or so. (There's more to Z...

A bit of tiling...

I just finished writing a small script to combine a lot of png pictures into a bigger one for CSS Sprite. So basically, I have a list of dimensions [(w1,h2), ..., (wn,hn)] and I need to put them into a frame with dimension (W,H) with WH as small as possible. (Of course they cannot overlap) The heuristic I used is obviously not optima...

Is Disney's FastPass Valid and/or Useful Queue Theory

At Disney World, they use a system called Fastpass to create a second, shorter line for popular rides. The idea is that you can wait in the standard line, often with a wait longer than an hour, or you can get a FastPass which allows you to come back during a specified time block (usually a couple hours later) and only wait for 10 minute...

Erroneous Data Retrieved From ListView

I am having some trouble with my program logic that loops through a collection of data that exists in two separate ListViews. After looping though and extracting the data from the ListView, I then add everything into a comma delimited text file (CLOSEULDCONFIG.TXT). The first time that I execute this logic, everything works as it shoul...

Fastest way to find most similar string to an input?

Given a query string Q of length N, and a list L of M sequences of length exactly N, what is the most efficient algorithm to find the string in L with the fewest mismatch positions to Q? For example: Q = "ABCDEFG"; L = ["ABCCEFG", "AAAAAAA", "TTAGGGT", "ZYXWVUT"]; answer = L.query(Q); # Returns "ABCCEFG" answer2 = L.query("AAAATAA"); ...

What's the most insidious way to pose this problem?

My best shot so far: A delivery vehicle needs to make a series of deliveries (d1,d2,...dn), and can do so in any order--in other words, all the possible permutations of the set D = {d1,d2,...dn} are valid solutions--but the particular solution needs to be determined before it leaves the base station at one end of the route (imagine t...

Ranking Algorithm

Hi all , i was wondering of as to what is the ranking algorithm used at stackoverflow based upon which a question reaches the front page. ...

fast way to copy one vector into another

I prefer two ways: void copyVecFast(const vec<int>& original) { vector<int> newVec; newVec.reserve(original.size()); copy(original.begin(),original.end(),back_inserter(newVec)); } void copyVecFast(vec<int>& original) { vector<int> newVec; newVec.swap(original); } How do you do it? ...

How to find free area rectangles?

Can anyone help me on how to draw rectangles for space in a bounding box region with n rectangular obstacles? There could be any number of axis parallel rectangular obstacles, this is not a unique case, thus different corner cases needs to be taken into consideration. Is it best to use maximal horizontal strip algorithm? And how? Probl...

How would you remove elements of a std::vector based on some property of the elements?

If for instance you have a std::vector<MyClass>, where MyClass has a public method: bool isTiredOfLife(), how do you remove the elements that return true? ...

pseudo code for finding closed paths in a graph

Hi All, I have an adjaceny matrix for a graph which tracks the edges between the nodes by having a 1 in the corresponding adjMat[i,j] = 1; Through this adjaceny matrix i wish to find out all the closed paths of length 4 which exists in the graph. Can anyone please provide me with a pseudo code. thank u ...

How can I implement an algorithm for multicore in Java?

Modern computers have more and more cores. We want to change our current linear algorithm to use these cores. A splitting of any algorithm to use different threads only makes sense if there is a free processor. Are there any good libraries that can help to parallelize some steps if there are free processors? I will give some examples....

Hashing for sparse bit vectors

Does anyone have any good intuition for a good hash function for a sparse bit vector? To give a concrete example, say I want to hash a 4096 bit integer where the probability of each bit being 1 is 10%. I want to get some compression in the hash. For example 4096 bits in and 32 bits out. This is just an example to illustrate what I am lo...

B-tree faster than AVL or RedBlack-Tree?

I know that performance never is black and white, often one implementation is faster in case X and slower in case Y, etc. but in general - are B-trees faster then AVL or RedBlack-Trees? They are considerably more complex to implement then AVL trees (and maybe even RedBlack-trees?), but are they faster (does their complexity pay off) ? E...

Algorithm problem

Hello all! I have a bit of a problem with the algorithm proposed as homework by our teachers. It goes something like this: Having a number of sticks like so: 4 (the number of piles to use) 11 7 5 4 (length of the sticks) 1 1 3 3 (how many sticks per length) I have to figure out an algorithm that will form the minimal number of sti...

Youtube content identification technology?

I'm not sure if Youtube is the only website with this technology, but content identification in YT (Content ID) is basically a technology to automatically identify and remove copyright infringements. You can read more about it here: http://www.youtube.com/t/contentid Well when one of my videos (containing a particular music track) got ...

Algorithm: Travelling through all array elements with limited move constraint

Greetings. I have an 2-D array of size [N][N] which will represent a rectangular area / map with N rows and N columns. Let's say I pick the middle as starting point (or anywhere else), I want to walk through all elements with the constraint of moving only X times before having to reset back to starting point. I then can walk through th...

The Hungarian Algorithm (Also Munkres' Assignment Algorithm)

I've stumbled on this algorithm recently and am having difficulty explaining it to myself. The algorithm solves the assignment problem in O(n4) (and apparently can be improved to O(n3)) but I can't see why. Intuitively I can see that the algorithm would tend to find good to optimal solutions but I can't see a proof! All the proofs I hav...