algorithm

What are some compact algorithms for generating interesting time series data?

The question sort of says it all. Whether it's for code testing purposes, or you're modeling a real-world process, or you're trying to impress a loved one, what are some algorithms that folks use to generate interesting time series data? Are there any good resources out there with a consolidated list? No constraints on values (except pl...

How can I make my applications scale well?

In general, what kinds of design decisions help an application scale well? (Note: Having just learned about Big O Notation, I'm looking to gather more principles of programming here. I've attempted to explain Big O Notation by answering my own question below, but I want the community to improve both this question and the answers.) Resp...

Levenshtein distance based methods Vs Soundex

As per this comment in a related thread, I'd like to know why Levenshtein distance based methods are better than Soundex. ...

How to implement a "related" degree measure algorithm?

I was going to Ask a Question earlier today when I was presented to a surprising functionality in Stackoverflow. When I wrote my question title stackoverflow suggested me several related questions and I found out that there was already two similar questions. That was stunning! Then I started thinking how I would implement such function...

Algorithm to randomly generate an aesthetically-pleasing color palette

I'm looking for a simple algorithm to generate a large number of random, aesthetically pleasing colors. So no crazy neon colors, colors reminiscent of feces, etc. I've found solutions to this problem but they rely on alternative color palettes than RGB. I would rather just use straight RGB than mapping back and forth. These other solut...

How do you know if you can use a patented algorithm?

I've been reading up on Sun's new Garbage First garbage collection algorithm, and was considering using it on a personal project. When googling for more information I found that it is patented, which raises the question if I could ever release my code. How can I tell whether this specific research is safe to learn from and use? Did Su...

What't the best solution for creating subsets of a set of characters?

I know 'best' is subjective, so according to you, what is the best solution for the following problem: Given a string of length n (say "abc"), generate all proper subsets of the string. So, for our example, the output would be {}, {a}, {b}, {c}, {ab}, {bc}, {ac}. {abc}. What do you think? ...

Given that I have a hash of id(key) and countries(values) sorted alphabetically, what is the best way to bubble up an entry to the top of the stack?

This is a php example, but an algorithm for any language would do. What I specifically want to do is bubble up the United States and Canada to the top of the list. Here is an example of the array shortened for brevity. array( 0 => '-- SELECT --', 1 => 'Afghanistan', 2 => 'Albania', 3 => 'Algeria', 4 => 'American Samoa', 5 =...

Algorithm / pseudo-code to create paging links?

Can someome provide code or pseudo-code for how the paging links in stackoverflow are generated? I keep racking my brain but can't think of a decent way to build the dynamic links that always shows the 2 pages around the current, plus the first and last. Example: 1 .. 5 6 7 .. 593 ...

Library or algorithm to explode an alphanumeric range

I was wondering if there is an open source library or algorithm that can expand a non-numeric range. For example, if you have 1A to 9A you should get 1A, 2A, 3A, 4A, 5A, 6A, 7A, 8A, 9A. I've tried Googling for this and the best I could come up with were Regex that would expand numerics with dashes (1-3 becoming 1,2,3). ...

How to generate a verification code/number ?

Hi, I'm working on an application where users have to make a call and type a verification number with the keypad of their phone. I would like to be able to detect if the number they type is correct or not. The phone system does not have access to a list of valid numbers, but instead it will validate the number against an algorithm (like...

How can a simple tree algorithm be coded in a functional language?

Suppose I want to implement a reasonably efficient 'keyword recognition algorithm', that is first given a list of keyword, and must then answer if another given word was in the list. In an imperative language, I would store the keywords in a tree (one node per character). Then, when receiving a word to test, I would scan my tree to tes...

Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.

Example input and output: >>> reverse_words("this is a string") 'string a is this' It should be O(N) in time and O(1) in space (split() and pushing on/poping of stack are not allowed). The puzzle is taken from here ...

Select a random N elements from List<T> in C#

I need a quick algorithm to select a random 5 elements from a generic list. For example, I'd like to get a random 5 elements from a List. ...

Modern books on algorithms

My book shelf is occupied by following books: Data Structures and Algorithm (Alfred V. Aho, Jeffrey D. Ullman, John E. Hopcroft) Introduction to Algorithms 2n edition (Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Cliff Stein) Art of Computer Programming, The, Volumes 1-3 (Donald E. Knuth) Are there any modern good books ...

Finding the phone numbers in 50,000 HTML pages

How do you find the phone numbers in 50,000 HTML pages? Jeff Attwood posted 5 Questions for programmers applying for jobs: In an effort to make life simpler for phone screeners, I've put together this list of Five Essential Questions that you need to ask during an SDE screen. They won't guarantee that your candidate w...

Approximate string matching algorithms

Hello. Here at work, we often need to find a string from the list of strings that is the closest match to some other input string. Currently, we are using Needleman-Wunsch algorithm. The algorithm often returns a lot of false-positives (if we set the minimum-score too low), sometimes it doesn't find a match when it should (when the mini...

A good algorithm similar to Levenstein but weighted for Qwerty keyboards?

I noticed some posts here on string matching, which reminded me of an old problem I'd like to solve. Does anyone have a good Levenstein-like algorithm that is weighted toward Qwerty keyboards? I want to compare two strings, and and allow for typos. Levenstein is okay, but I'd prefer to also accept spelling errors based on the physical d...

Good Java graph algorithm library?

Has anyone had good experiences with any Java libraries for Graph algorithms. I've tried JGraph and found it ok, and there are a lot of different ones in google. Are there any that people are actually using successfully in production code or would recommend? To clarify, I'm not looking for a library that produces graphs/charts, I'm look...

Graph (Chart) Algorithm

Does anyone have a decent algorithm for calculating axis minima and maxima? When creating a chart for a given set of data items, I'd like to be able to give the algorithm: the maximum (y) value in the set the minimum (y) value in the set the number of tick marks to appear on the axis an optional value that must appear as a tick (...