algorithm

Need a deterministic algorithm to generate a resource domain prefix for a given path in an evenly distributed fashion

I need to generate a resource domain prefix based on a given path and configured number of resource domains in a deterministic fashion with good distribution. For example, if you pass it the path "/script/site.js" it returns "res#", where '#' is an integer between 0 and the configured amount of resource domains. Using C# 3.0. So far ha...

Algorithm to determine vista/windows 7 OS edition from product key

We have to automatically create the XML file for an unattended vista/windows 7 installation in which we do write the product key (MAK type). Unfortunately the windows image contains multiple editions (home, home premium, professional, ultimate) so we need to decide which version we should use and write that info to the XML as well. And w...

the best shortest path algoritm

hello all, what is the difference between the "Floyd-Warshall algorithm" and "Dijkstra's Algorithm", and which is the best for finding the shortest path in a graph? I need to calculate the shortest path between all the pairs in a net and save the results to an array as follows: **A B C D E** A 0 10 15 5 ...

Given an RGB value what would be the best way to find the closest match in the database?

I have a rgb value and if it doesn't exist in the color table in my database I need to find the closest color. I was thinking of comparing all values and finding the difference(in red,green,and blue) then take the average. The lowest average deviation should be the closest color. There seems to me like there should be a better way. A...

How many digits in this base ?

The problem is to derive a formula for determining number of digits a given decimal number could have in a given base. For example: The decimal number 100006 can be represented by 17,11,9,8,7,6,8 digits in bases 2,3,4,5,6,7,8 respectively. Well the formula I derived so far is like this : (log10(num) /log10(base)) + 1. in C/C++ I use...

Count number of points inside a circle fast

Given a set of n points on plane, I want to preprocess these points somehow faster than O(n^2) (O(nlog(n)) preferably), and then be able to answer on queries of the following kind "How many of n points lie inside a circle with given center and radius?" faster than O(n) (O(log(n) preferably). Can you suggest some data structure or algo...

Spam detection in (objective-) C

Hello, I'm currently writing an iPhone application which gets some data from the user and uploads it to a server. The uploaded data will be displayed to other users of the same program (there's more to it than that, but to keep the idea simple...). The data which is uploaded is basically just three strings: a name(max. 50 char.), a titl...

anything better than bounding boxes?

Hi all I have a scenario, where I have x million longitude latitude points. When a new long/lat point is added I want to know efficiently which other points are within a user configured distance parameter, so I can add them to a list. got anything better than bounding boxes? I would love to see algorithms, references and a few implem...

iPhone hard computation and caching

Hi people. I have problem. I have database with 500k records. Each record store latitude, longitude, specie of animal,date of observation. I must draw grid(15x10) above mapkit view, that show the concentration of specie in this grid cell. Each cell is 32x32 box. If I calculate in run-time it is very slow. Have somebody idea how to cache...

Pre-sorting analysis algorithm?

It's a well-known isssue with Quicksort that when the data set is in or almost in sort order, performance degrades horribly. In this case, Insertion Sort, which is normally very slow, is easily the best choice. The question is knowing when to use which. Is there an algorithm available to run through a data set, apply a comparison fact...

Do Python Dicts preserve iteration order if they are not modified?

If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups). ...

How can you detect if two regular expressions overlap in the strings they can match?

I have a container of regular expressions. I'd like to analyze them to determine if it's possible to generate a string that matches more than 1 of them. Short of writing my own regex engine with this use case in mind, is there an easy way in C++ or Python to solve this problem? ...

Simple Suggestion / Recommendation Algorithm

I am looking for a simple suggestion algorithm to implement in to my Web App. Much like Netflix, Amazon, etc... But simpler. I don't need teams of Phd's working to get a better suggestion metric. So say I have: User1 likes Object1. User2 likes Object1 and Object2. I want to suggest to User1 they might also like Object2. I can obvi...

How to intelligently degrade or smooth GIS data (simplifying polygons)?

I have detailed US county maps, from the TIGER LINE data sets. How might I sample, smooth, or degrade the data so that I get straighter, more boxy, less "noisy" shapes to represent the geographical features -- in this case just county boundaries and state lines, but maybe also in the general case? The sampling could happen at renderin...

Compare the textual content of websites

I'm experimenting a bit with textual comparison/basic plagiarism detection, and want to try this on a website-to-website basis. However, I'm a bit stuck in finding a proper way to process the text. How would you process and compare the content of two websites for plagiarism? I'm thinking something like this pseudo-code: // extract tex...

Detecting if integer can be written as sum of given integers

Hi Supposing I'm having the constants 3,5,6,9,10. How can I detect how to write $n, which is the input, as a sum of these constants with the least number of terms? Examples $n=10, S=10 $n=18, S=9+9 $n=24, S=9+9+6 $n=27, S=9+9+9 $n=28, S=10+9+9 Thanks ...

What is the time complexity of java.util.HashMap class' keySet() method?

I am trying to implement a plane sweep algorithm and for this I need to know the complexity of java.util.HashMap class' keyset() method. What i feel, it would be O(n log n). Am I correct? **Edit I am talking about the time complexity of the method keySet(), the walking over will take surely O(n) time. But I am not sure, how it retrieves...

How to go about making an untrained speech to text converter ?

I have a severe to profound deafness from a very early age but luckily I can speak like a normal person. Verbal communication has always been difficult for me due to my impaired speech recognition abilities even with lip-reading. I have gone through school and college by just reading boards, powerpoint slides, books and the internet. I a...

Generate all binary strings of length n with k bits set

What's the best algorithm to find all binary strings of length n that contain k bits set? For example, if n=4 and k=3, there are... 0111 1011 1101 1110 I need a good way to generate these given any n and any k so I'd prefer it to be done with strings. ...

Algorithm for finding path to point

I'm not sure if I worded this properly, but basically I have an object at point X,Y and I want an algorithm that can get this point to X',Y' but like show its route so I can animate it. I'm building a tile game and when the game starts I want the tiles to magically place themselves into a nice 2d array. So I will generate a random coordi...