algorithm

What's a good introductory-level book / resource for compression?

I'm looking to learn some theory about data/audio/video compression, and would be glad to get some recommendations. Online and print resources are both fine. ...

All possible combinations of n items selected randomly from a set of x items (algorithm)

I have a set of x string items e.g("A","B","C","D","E","F") I need to know the formula that calculates how many combinations of n items and what is the algorithm that generates all possible combinations e.g if we need to select 4 items from the list randomly. those 4 items could be: ("A","B","C","D") or ("A","B","C","E") or ("A","B","C",...

Project Euler Question 14 (Collatz Problem)

The following iterative sequence is defined for the set of positive integers: n ->n/2 (n is even) n ->3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 40 20 10 5 16 8 4 2 1 It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it ha...

Whats the best data-structure for storing 2-tuple (a, b) which support adding, deleting tuples and compare (either on a or b))

Hi So here is my problem. I want to store 2-tuple (key, val) and want to perform following operations: keys are strings and values are Integers multiple keys can have same value adding new tuples updating any key with new value (any new value or updated value is greater than the previous one, like timestamps) fetching all the keys wit...

Getting the submatrix with maximum sum?

With the help of the Algorithmist and Larry and a modification of Kadane's Algorithm, here is my solution: int dim = matrix.length; //computing the vertical prefix sum for columns int[][] ps = new int[dim][dim]; for (int i = 0; i < dim; i++) { for (int j = 0; j < dim; j++) { if (j == 0) { ...

Memcache key generation strategy

Given function f1 which receives n String arguments, what would be considered better ,in terms of runtime performance, random key generation strategy for memcache? Our Memcache client does internal md5sum hashing on the keys it gets: public class MemcacheClient { public Object get(String key) { String md5 = Md5s...

Accenture interview question - Find the only unpaired element in the array

You have been given an array of size 2n+1 that have n pair of integers(can be +ve, -ve or 0) and one unpaired element. How would you find the unpaired element. Pair means duplicate. So (3,3) is a pair and (3,-3) is not a pair. ...

How do I find the ceiling and floor for a number from a set of numbers?

1st number: 50 2. 30 3. 70 4. 40 5. 11 and other number is 33 I need to calculate which two numbers the last number is between (using php) .. any help? ...

RSA Factorization problem

At class we found this programming problem, and currently, we have no idea how to solve it. The positive integer n is given. It is known that n = p * q, where p and q are primes, p<=q and |q-k*p|<10^5 for some given positive integer k. You must find p and q. Input: 35 1 121 1 1000730021 9 Output: 5 * 7 11 * 11 10007 * 100003 ...

Suggestions of the easiest algorithms for some Graph operations

Hi, The deadline for this project is closing in very quickly and I don't have much time to deal with what it's left. So, instead of looking for the best (and probably more complicated/time consuming) algorithms, I'm looking for the easiest algorithms to implement a few operations on a Graph structure. The operations I'll need to do is ...

Simulating a baseball game

It seems that baseball is perhaps the easiest sport to simulate due to its very linear nature. I'm curious as to whether not there is someone out there with some experience in this matter that can advise me as to the best route to go. There are several options, such as simulating each pitch, simulating an at bat as a single event, or s...

"Anagram solver" based on statistics rather than a dictionary/table?

My problem is conceptually similar to solving anagrams, except I can't just use a dictionary lookup. I am trying to find plausible words rather than real words. I have created an N-gram model (for now, N=2) based on the letters in a bunch of text. Now, given a random sequence of letters, I would like to permute them into the most likely...

K-nearest neighbour with closed-loop dimensions

Hi, I've got a K-nearest neighbour problem where some of the dimensions are closed loops. For example one is 'time of day' and I'm matching for similarity so 'very early morning' is close to 'late evening', you can't just make it a linear scale from 'very early morning' at one end to 'late evening' at the other. How can I represent thi...

Reverse factorial

Well, we all know that if N is given it's easy to calculate N!. But what about reversing? N! is given and you are about to find N - Is that possible ? I'm curious. ...

How to find the shortest path between two blobs(contours/closed curves) using MATLAB?

bwlabel can be used to get disconnected objects in an image: [L Ne] = bwlabel(image); How to calculate the shortest path between two disconnected closed curves? Is there a practical(not theoretical) solution? ...

Grouping geographical shapes

I am using Dundas Maps and attempting to draw a map of the world where countries are grouped into regions that are specific to a business implementation. I have shape data (points and segments) for each country in the world. I can combine countries into regions by adding all points and segments for countries within a region to a new reg...

barebones sort algorithm

i have been asked to make a simple sort aglorithm to sort a random series of 6 numbers into numerical order. However i have been asked to do this using "Barebones" a theoretical language put forward in the Book Computer Science an overview. Some information on the language can be found here http://www.brouhaha.com/~eric/software/barebo...

Most efficient way of creating tree from adjacency list

I have an adjacency list of objects (rows loaded from SQL database with the key and it's parent key) that I need to use to build an unordered tree. It's guaranteed to not have cycles. This is taking wayyy too long (processed only ~3K out of 870K nodes in about 5 minutes). Running on my workstation Core 2 Duo with plenty of RAM. Any i...

How is PI calculated?

I want to make a function in C that can return PI to X places.. I'm just not sure how... Thanks Edit: I don't care how slow it is I really just want an algorithm that will return PI at X decimal... Iv been looking at http://bellard.org/pi/ but I don't understand how to get the nth of Pi from this. Thanks ...

Convert latitude and longitude into northings and eastings

Hi I have the following UK postcode dy8 3xt and know that the latitude and longitude is:- 54.452772 -2.156082 I also know that the Eastings, Northings for the postcode is:- 389490 283880 However I am struggling to find the equation that converts lat/long to northings and Eastings, I would prefer to have the equation in both in ...