algorithm

Proving correctness of multithread algorithms

Multithread algorithms are notably hard to design/debug/prove. Dekker's algorithm is a prime example of how hard it can be to design a correct synchronized algorithm. Tanenbaum's Modern operating systems is filled with examples in its IPC section. Does anyone have a good reference (books, articles) for this? Thanks! ...

What is the best way to check the strength of a password?

See also How do you compute password complexity? What is the best way of ensuring that a user supplied password is a strong password in a registration or change password form? EDIT: one idea I had (in python) def validate_password(passwd): conditions_met = 0 conditions_total = 3 if len(passwd) >= 6: if passwd.lowe...

Converting a Uniform Distribution to a Normal Distribution

How can I convert a uniform distribution (as most random number generators produce, e.g. between 0.0 and 1.0) into a normal distribution? What if I want a mean and standard deviation of my choosing? ...

Algorithm for finding similar images

I need an algorithm that can determine whether two images are 'similar' and recognizes similar patterns of color, brightness, shape etc.. I might need some pointers as to what parameters the human brain uses to 'categorize' images. .. I have looked at hausdorff based matching but that seems mainly for matching transformed objects and p...

Do you know of any language-aware diffing tools?

I got to thinking about how annoying messy merges can be and was wondering if there are any language aware diffing tools that go beyond the typical language-aware features of comment skipping and case sensitivity. Seems like the diffing engine could infer a lot more if it were aware of the syntax of what it is diffing instead of just tr...

Prim's Algorithm, Priority First Search and Minimum Spanning Trees (MST)

Prims algorithm is a priority first search algorithm. If this is the case, why does Sedgewick refer to the MST algorithm for a sparse graph as the priority first search algorithm but the MST algorithm for a dense graph is called Prim's algorithm? The complexity differences between the two only arise because (a) the properties of sparse ...

Beats per minute from real-time audio input

I'd like to write a simple C# application to monitor the line-in audio and give me the current (well, the rolling average) beats per minute. I've seen this gamedev article, and that was absolutely no help. I went through and tried to implement what he was doing but it just wasn't working. I know there have to be tons of solutions for t...

Anyone Recommend a Good Tutorial on Conditional Random Fields

I have been trying to find a good tutorial on Conditional Random Fields and have yet to find one that didn't start sending my brain into meltdown. I have a good grasp of HMM's, and I get the difference between discriminative and generative models ... but as of yet I have not been able to find a resource that can give a good comparison of...

storing revision changes of a message

What algorithms and processes are involved in storing revision changes like stackoverflow and wikipedia do? Is only one copy of the message kept? And if so is it only the latest copy? Then only changes to go back to the previous version(s) are stored from there? (This would make for a faster display of the main message). Or are compl...

Algorithm to find which numbers from a list of size n sum to another number

I have a decimal number (let's call it goal) and an array of other decimal numbers (let's call the array elements) and I need to find all the combinations of numbers from elements which sum to goal. I have a preference for a solution in C# (.Net 2.0) but may the best algorithm win irrespective. Your method signature might look somethin...

Is there an efficient algorithm to generate a 2D concave hull?

Having a set of (2D) points from a GIS file (a city map), I need to generate the polygon that defines the 'contour' for that map (its boundary). Its input parameters would be the points set and a 'maximum edge length'. It would then output the corresponding (probably non-convex) polygon. The best solution I found so far was to generate ...

What is the quickest way to find the shortest cartesian distance between two polygons

Hi, I have 1 red polygon say and 50 randomly placed blue polygons - they are situated in geographical 2D space. What is the quickest/speediest algorithim to find the the shortest distance between a red polygon and its nearest blue polygon? Bear in mind that it is not a simple case of taking the points that make up the vertices of the ...

Distributed hierarchical clustering

Are there any algorithms that can help with hierarchical clustering? Google's map-reduce has only an example of k-clustering. In case of hierarchical clustering, I'm not sure how it's possible to divide the work between nodes. Other resource that I found is: http://issues.apache.org/jira/browse/MAHOUT-19 But it's not apparent, which algo...

What's the best way to model recurring events in a calendar application?

I'm building a group calendar application that needs to support recurring events, but all the solutions I've come up with to handle these events seem like a hack. I can limit how far ahead one can look, and then generate all the events at once. Or I can store the events as repeating and dynamically display them when one looks ahead on th...

I need an algorithm for rendering soft paint brush strokes.

I have an array of mouse points, a stroke width, and a softness. I can draw soft circles and soft lines. Which algorithm should I use for drawing my array of points? I want crossed lines to look nice as well as end points. ...

What is the inversion of the Shunting Yard algorithm?

Dijkstra's Shunting Yard algorithm is used to parse an infix notation and generate RPN output. I am looking for the opposite, a way to turn RPN into highschool-math-class style infix notation, in order to represent RPN expressions from a database to lay users in an understandable way. Please save your time and don't cook up the algorit...

Calculating frames per second in a game

What's a good algorithm for calculating frames per second in a game? I want to show it as a number in the corner of the screen. If I just look at how long it took to render the last frame the number changes too fast. Bonus points if your answer updates each frame and doesn't converge differently when the frame rate is increasing vs decr...

What algorithm can you use to find duplicate phrases in a string?

Given an arbitrary string, what is an efficient method of finding duplicate phrases? We can say that phrases must be longer than a certain length to be included. Ideally, you would end up with the number of occurrences for each phrase. ...

Polynomial time algorithm for finding a Hamiltonian walk in a graph

Is there a polynomial time algorithm for finding a Hamiltonian walk in a graph? My algorithm is N factorial and is really slow. ...

In Python, what is the fastest algorithm for removing duplicates from a list so that all elements are unique *while preserving order*?

For example: >>> x = [1, 1, 2, 'a', 'a', 3] >>> unique(x) [1, 2, 'a', 3] Assume list elements are hashable. Clarification: The result should keep the first duplicate in the list. For example, [1, 2, 3, 2, 3, 1] becomes [1, 2, 3]. ...