algorithm

Help with algorithm for merging vectors

I need a very fast algorithm for the following task. I have already implemented several algorithms that complete it, but they're all too slow for the performance I need. It should be fast enough that the algorithm can be run at least 100,000 times a second on a modern CPU. It will be implemented in C++. I am working with spans/ranges, a...

Pseudo random generator, Assembler

Which "random" numbers generator algorithm is the best for an assembler program? Something easy, not a long piece of code. Not external library allowed, just trying to keep it simple. @Bill Barksdale: I'm looking for an easy algorithm to use in a assembler program assigned in a course. ...

Word frequency algorithm for natural language processing

Without getting a degree in information retrieval, I'd like to know if there exists any algorithms for counting the frequency that words occur in a given body of text. The goal is to get a "general feel" of what people are saying over a set of textual comments. Along the lines of Wordle. What I'd like: ignore articles, pronouns, etc...

What are the best programming puzzles you came across?

Every single programmer worth his salt is inspired by great programming puzzles. Some puzzles are intended to sharpen your analytical abilities while some others make your programming abilities better. Programming puzzles are the soul of infotainment in the programming community. What are your favorite programming puzzles? For the val...

What would be the best algorithm to find an ID that is not used from a table that has the capacity to hold a million rows.

To elaborate .. a) A table (BIGTABLE) has a capacity to hold a million rows with a primary Key as the ID. (random and unique) b) What algorithm can be used to arrive at an ID that has not been used so far. This number will be used to insert another row into table BIGTABLE. Updated the question with more details.. C) This table already h...

How do you rate-limit an IO operation?

Suppose you have a program which reads from a socket. How do you keep the download rate below a certain given threshold? ...

How to convert floats to human-readable fractions?

Let's say we have 0.33, we need to output "1/3". If we have "0.4", we need to output "2/5". The idea is to make it human-readable to make the user understand "x parts out of y" as a better way of understanding data. I know that percentages is a good substitute but I was wondering if there was a simple way to do this? ...

Real-world problems with naive shuffling

I'm writing a number of articles meant to teach beginning programming concepts through the use of poker-related topics. Currently, I'm working on the subject of shuffling. As Jeff Atwood points out on CodingHorror.com, one simple shuffling method (iterating through an array and swapping each card with a random card elsewhere in the arra...

Book(s) on the algorithims needed for calculating trancendental functions?

For example, how are exponential, logarithm, and trigonometric functions done within the chip on a hand-held calculator? Where is a good starting place to learn about this? EDIT: specifically, how could I recreate these functions in software? With the purpose of understanding both the mathematics and the trade-offs in time and complexi...

I need to join two lists, sort them and remove duplicates. Is there a better way to do this?

I have two unsorted lists and I need to produce another list which is sorted and where all the elements are unique. The elements can occur multiple times in both lists and they are originally unsorted. My function looks like this: (defun merge-lists (list-a list-b sort-fn) "Merges two lists of (x, y) coordinates sorting them and r...

The most efficient way to implement an integer based power function pow(int, int)

What is the most efficient way given to raise an integer to the power of another integer in C? // 2^3 pow(2,3) == 8 // 5^5 pow(5,5) == 3125 ...

Algorithm to detect similar documents in python script

i need to write a module to detect similar documents. i have read many papers of fingerprints of documents technique and others but i do not know how to write code or implement. the algorithm should work for Chinese, Japanese, English and German language or language independent. can you help me. or sending me code for this problem i am ...

How to generate one texture from N textures?

Let's say I have N pictures of an object, taken from N know positions. I also have the 3D geometry of the object, and I know all the characteristics of both the camera and the lens. I want to generate a unique giant picture from the N pictures I have, so that it can be mapped/projected onto the object surface. Does anybody knows where ...

Good Algorithm Resources?

I’m looking for a good non academic book or site about algorithms, preferably one that uses a C style language or pseudo code. I have Introduction To Algorithms, but I find that it is overly academic and confusing, sort of how the GOF patterns book is (and I was a Math major, believe it or not). I’d like to specifically learn a good ...

Algorithm problem: letter combinations

I'm trying to write a piece of code that will do the following: Take the numbers 0 to 9 and assign one or more letters to this number. For example: 0 = N, 1 = L, 2 = T, 3 = D, 4 = R, 5 = V or F, 6 = B or P, 7 = Z, 8 = H or CH or J, 9 = G When I have a code like 0123, it's an easy job to encode it. It will obviously make up the code NL...

What is the best emulator for MIX and/or MMIX?

MIX is the hypothetical computer outlined by Donald Knuth in the Art of Computer Programming. I guess when I say best, I mean most suitable for working with the algorithms and problems in the Art of Computer Programming. ...

looking for a tuple matching algorithm

I need to implement an in-memory tuple-of-strings matching feature in C. There will be large list of tuples associated with different actions and a high volume of events to be matched against the list. List of tuples: ("one", "four") ("one") ("three") ("four", "five") ("six") event ("one", "two", "three", "four") should match list i...

How to prepare for a programming competition? Graphs, Stacks, Trees, oh my!

Last semester I attended ACM's (Association for Computing Machinery) bi-annual programming competition at a local University. My University sent 2 teams of 3 people and we competed amongst other schools in the mid-west. We got our butts kicked. You are given a packet with about 11 problems (1 problem per page) and you have 4 hours t...

How to generate all permutations of a list in Python

How do you generate all the permutations of a list in Python, independently of the type of elements in that list. For example: permutations ([]) [] permutations ([1,]) [1] permutations ([1,2]) [1, 2] [2, 1] permutations ([1,2,3]) [1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 1, 2] [3, 2, 1] EDIT: Eliben pointed to a solution that's...

Sort on a string that may contain a number

I need to write a Java Comparator class that compares Strings, however with one twist. If the two strings it is comparing are the same at the beginning and end of the string are the same, and the middle part that differs is an integer, then compare based on the numeric values of those integers. For example, I want the following strings...