algorithm

Where can I learn more about "ant colony" optimizations?

I've been reading things here and there for a while now about using an "ant colony" model as a heuristic approach to optimizing various types of algorithms. However, I have yet to find an article or book that discusses ant colony optimizations in an introductory manner, or even in a lot of detail. Can anyone point me at some resources ...

"Approximate" greatest common divisor

Suppose you have a list of floating point numbers that are approximately multiples of a common quantity, for example 2.468, 3.700, 6.1699 which are approximately all multiples of 1.234. How would you characterize this "approximate gcd", and how would you proceed to compute or estimate it? Strictly related to my answer to this questio...

What algorithms should every developer know?

I know there is a thread about what every developer should know but this is really a list of topics, such as xml, software licensing, various important distinctions (e.g. value/reference types), and many general topics (xml etc being important as they are used in code to construct xml documents etc). Anyway, as I am working on some of t...

Where can I get a "useful" C++ binary search algorithm?

I need a binary search algorithm that is compatible with the C++ standard containers, something like std::binary_search in the standard library's <algorithm> header, but unlike std::binary_search, I need it to return the iterator that points at the result, not a simple boolean telling me if the element exists (On a side note, what the ...

Variable Sized Arrays in C

On the discussion of dynamic memory here: "Intro to C Pointers and Dynamic Memory" The author states: A memory block like this can effectively be used as a more flexible array. This approach is actually much more common in real-world C programs. It's also more predictable and flexible than a "variable size array" The type of memor...

Most binary combinations from 4 bits - with each bit able to change state only once

I have 4 binary bits Bit 3 Bit 2 Bit 1 Bit 0 Normally the answer is simple: 2^4, or 16 different combinations; and it would looks something like the following: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 However, The LSB (Bit 0) changes state every iteration I need an algorithm where the state ...

algorithm to convert pathname to unique number

I want to convert windows pathname to unique integer. Eg: For pathname C:\temp\a.out, if i add ascii value of all the characters, i get 1234. But some other path can also generate the same number. So, what is the best way to generate unique numbers for different pathnames? ...

How do I calculate the surface area of a 2d polygon?

Assuming a series of points in 2d space that do not self-intersect, what is an efficient method of determining the surface area of the resulting polygon? As a side note, this is not homework and I am not looking for code. I am looking for a description I can use to implement my own method. I have my ideas about pulling a sequence of t...

Similar String algorithm

I'm looking for an algorithm, or at least theory of operation on how you would find similar text in two or more different strings... Much like the question posed here: http://stackoverflow.com/questions/246961/algorithm-to-find-similar-text, the difference being that my text strings will only ever be a handful of words. Like say I have...

How complex should code be?

I'm studying about algorithms which can help me write smaller but more complex code. Instead of writing 150 lines of if-else statements, I can design an algorithm that does it in 20 lines. The problem is a lot of these algorithms can be complex and require a lot of math to understand them. I'm also the only one around here who underst...

Is there an algorithm to determine contiguous colored regions in a grid?

Given a basic grid (like a piece of graph paper), where each cell has been randomly filled in with one of n colors, is there a tried and true algorithm out there that can tell me what contiguous regions (groups of cells of the same color that are joined at the side) there are? Let's say n is something reasonable, like 5. I have some id...

How can I calculate the age of a person in year, month, days?

I want to calculate the age of a person given the date of birth and the current date in years, months and days relative to the current date. For example: >>> calculate_age(2008, 01, 01) 1 years, 0 months, 16 days Any pointer to an algorithm that does that will be appreciated. ...

Serial number (registration key) algorithm in .NET

There have been a few timely posts about IP security and the like, but none that I can find that specifically address an algorithm. In one of my current projects, we've decided to go the route of an offline registration key system. I imagine most of our eventual user base will be honest, so I don't think we have too much to worry about....

I need a problem for my algorithm. I need like search engine input data

Hello! Imagine you have some products, or items, or just anything that you want to see in some order of importance. Like you want in a search engine. Like websites. And you don't know how to sort them. But you have some criteria that give you a clue. You have a bag of criteria, and according to each, you can find a sorting, but you cann...

How would you tackle the netflix prize?

So, I'm just stabbing into the wild. I'm really not much of a data-miner. I ask out of pure interest because I really won't have time to try taking part in this contest. But just for the fun of it, how would you tackle it? It works something like this: You get a really large set of movie IDs and user votes. Now given a few votes by so...

Programming Problem - Fax Compression

I'm preparing to go to a computer science contest by completing problems from past contests. Most of them are pretty easy, but this one is bugging me...it seems simple but I'm just not being able to do it. If you have a string of ones and zeros: 100111010001111100101010 What would be the code to take that as an input and then output ...

visual side by side text comparison tool/routine for use in asp.net app

I am sure a general routine, or library must exists to do this, but I need to be able to show the user a "before" and "after" comparison of two versions of a string/text file. For example the old visual source safe had a great tool where it show both files and highlighted the adds, deletes and changes. I don't want to re-invent the whe...

Most efficient way to sort parallel arrays in a restricted-feature language

The environment: I am working in a proprietary scripting language where there is no such thing as a user-defined function. I have various loops and local variables of primitive types that I can create and use. I have two related arrays, "times" and "values". They both contain floating point values. I want to numerically sort the "ti...

Are there O(1) random access data structures that don't rely on contiguous storage?

The classic O(1) random access data structure is the array. But an array relies on the programming language being used supporting guaranteed continuous memory allocation (since the array relies on being able to take a simple offset of the base to find any element). This means that the language must have semantics regarding whether or n...

How to find intersecting periods in a huge list of periods?

I need an idea for an efficient index/search algorithm or datastructure for a particular problem. So far I could not come up with something fast and elegant... Consider a huge collection of objects with every object having a date period (start / end). Huge as in a few million elements. The element periods can be large or small, they can...