algorithm

Has anyone seen this improvement to quicksort before?

Handling repeated elements in previous quicksorts I have found a way to handle repeated elements more efficiently in quicksort and would like to know if anyone has seen this done before. This method greatly reduces the overhead involved in checking for repeated elements which improves performance both with and without repeated elements....

Pseudorandom Number Generator - Exponential Distribution

I would like to generate some pseudorandom numbers and up until now I've been very content with the .Net library's Random.Next(int min, int max) function. PRNGs of this variety are supposed to be using a Uniform distribution, but I would very much like to generate some numbers using an Exponential Distribution. I'm programming in C#, a...

Pythonic way of summing lists and lists of lists

I'm trying to find a neat way of summing a list and a list of lists in the same function, so far I've got: import operator """ Fails late for item = ['a', 'b'] """ def validate(item): try: return sum(item) == sum(range(1, 10)) except TypeError: return sum(reduce(operator.add, item)) == sum(range(1, 10)) """ ...

Fastest cross-platform A* implementation?

With so many implementations available, what is the fastest executing (least CPU intensive, smallest binary), cross-platform (Linux, Mac, Windows, iPhone) A* implementation for C++ using a small grid? Implementations Google returns: http://www.heyes-jones.com/astar.html (Most links on that site are dead.) http://www.grinninglizard.co...

What kind of algorithm does an HTML SELECT element uses to show results as you type?

I'm trying to replicate an HTML SELECT element (drop-down-list or combobox) in Flash (AS3). In most browsers, when you have one in focus and you type something, the combobox will try to find the value within its options and show the closest one. I was wondering what kind of algorithm is used for that. I don't think its Levenshtein or si...

database/algorithm for a rate structure

I have to calculate a price based on a rate structure along these lines: $303.00 fixed price up to 500 units $0.023 additional per unit from 501-10,000 units $0.022 additional per unit from 10,001-25,000 units $0.021 additional per unit from 25,001-50,000 units I'm a little lost on setting up a database structure and algorithm (the la...

File indexing (using Binary trees?) in Python

Background I have many (thousands!) of data files with a standard field based format (think tab-delimited, same fields in every line, in every file). I'm debating various ways of making this data available / searchable. (Some options include RDBMS, NoSQL stuff, using the grep/awk and friends, etc.). Proposal In particular, one ide...

Algorithm to find most efficient moves to arrive at a given point

(This is not exactly the problem that I have, but it's isomorphic, and I think that this explanation will be easiest for others to understand.) Suppose that I have a set of points in an n-dimensional space. Using 3 dimensions for example: A : [1,2,3] B : [4,5,6] C : [7,8,9] I also have a set of vectors that describe possible movement...

For problem solving..

This may be a bit OT... Here's the problem: "N different points with integer coordinates are given in a plane. You are to write a program that finds the maximum number of collinear points (they all belong to the same line)." Now my question: You don't have to solve this for me, instead I want to know where I can find some materials for...

self organizing computer networks & node discovery: libraries, algorithms, docs: where do I begin?

hi, I would like to write a networked software without centralized directory, capable to automatically discover its fellow nodes and "self-organize" a resilient, "not too unbalanced" logical network (maybe i should define it as a graph with relatively short routes between each pair of nodes). in witch hunting times like these, maybe it...

Is there a good algorithm to check for changes in data over a specified period of time?

We have around 7k financial products whose closing prices should theoretically move up and down within a certain percentage range throughout a defined period of time (say a one week or month period). I have access to an internal system that stores these historical prices (not a relational database!). I would like to produce a report tha...

Toilet Seat Algorithm

Let's take some regular house with a man, which has to go to the toilet every n minutes, requiring the seat to be up, and a woman, which has to do it every m minutes, requiring a seat to be down. Is there a possibility to create a O(1) algorithm which will output the exact number of toilet seat movements for a given period of X minutes? ...

Algorithm for creating unique bingo faces

Hi, Does anyone know of an algorithm that can generate unique bingo card faces? I'm looking to implement this algorithm in C#. Thanks, ...

Quickest way to find missing number in an array of numbers

I have an array of numbers from 1 to 100 (both included). The size of the array is 100. The numbers are randomly filled in the array but there is one random slot empty in the array. What is the quickest way to find that slot as well as the number that should be put in the slot? A java solution is preferable. ...

Data structure/Algorithm for Streaming Data and identifying topics

Hi, I want to know the effective algorithms/data structures to identify the below information in streaming data. Consider a real-time streaming data like twitter. I am mainly interested in the below queries rather than storing the actual data. I need my queries to run on actual data but not any of the duplicates. As I am not i...

data structure to support google/bing maps

I was wondering what the data structure is in an application like google/bing maps. How is it that the results are returned so quickly when searching for directions? what kind of algorithms are being used to determine this information? thanks ...

efficient loop collapse

in certain applications, I have need to collapse nested loops into one while retaining individual index information. for j in N: for i in M: ... A(i,j) ... // Collapse the loops for ij in MN: ... A(i,j) ... so have looked at the obvious ways to recover i,j from ij using division/modulo (expensive operation) and using if stat...

I want a function in VB SCRIPT to calculate numerology

I want a function to calculate numerology.For example if i enter "XYZ" then my output should be 3 . Here is how it became 3: X = 24 Y = 25 Z = 26 on adding it becomes 75 which again adds up to 12 (7+5) which again adds up to 3(1+2) . Similarly whatever names i should pass,my output should be a single digit score. ...

Is point A nearby point B in 3D - distance check

I am looking for efficent algorithm for checking if one point is nearby another in 3D. sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2) < radius This doesn't seem to be too fast and actually I don't need such a big accuracy. How else could I do this? ...

Help me understand Inorder Traversal without using recursion

I am able to understand preorder traversal without using recursion, but I'm having a hard time with inorder traversal. I just don't seem to get it, perhaps, because I haven't understood the inner working of recursion. This is what I've tried so far: def traverseInorder(node): lifo = Lifo() lifo.push(node) while True: ...