algorithm

Determining if a dataset approximates a sine wave

Is there an algorithm that can be used to determine whether a sample of data taken at fixed time intervals approximates a sine wave? ...

Matching algorithm

Odd question here not really code but logic,hope its ok to post it here,here it is I have a data structure that can be thought of as a graph. Each node can support many links but is limited to a value for each node. All links are bidirectional. and each link has a cost. the cost depends on euclidian difference between the nodes the mini...

LRU cache implementation in Javascript

Java has LinkedHashMap which gets you 99% there to an LRU cache. Is there a Javascript implementation of an LRU cache, preferably from a reputable source, that is: understandable efficient (amortized O(1) get/put/delete) ? I've been searching on the web but couldn't find one; I thought I found one on Ajax Design Patterns but it glos...

How to determine if a Delaunay triangle is internal or external?

I am writing a program that requires a implementation of Medial Axis extraction, of which Delaunay triangulation is a step. External medial axis is unwanted so the corresponding external triangles are intended to be removed. Luckily I came upon a page with a lot of diagrams, also a hint of a method to determine internal and external Dela...

Performance of Bellman–Ford shortest path algorithm

I implemented the solution of Bellman - Ford algorithm with a queue and I compared its performance with the Dijkstra algorithm. They were pretty close and that was a surprise for me because the complexity of Bellman - Ford is O(NM). I know that the complexity is for the worst case, but still the result was surprising. I searched for some...

What is image hashing used for?

I hear this term sometimes and am wondering what it is used for? ...

Is there an easy way to chunk a text file into brace-balanced sections?

I'm trying to parse some data out of a file using Perl & Parse::RecDescent. I can't throw the full data file at the perl script because RecDescent will take days poring over it. So I split up the huge datafile into RD-sized chunks to reduce the runtime. However, I need to extract sections within balanced brackets and the routine I hav...

What sorting technique will you use?

If you have 65536 random English words with length 1-32 per word that you need to count for appearance and sort based on dictionary or appearance rank, how do you structure the data and what sorting technique would you use to process it the fastest? ...

php list into a table

I asked a question yesterday and the answer I got has answered the first part of my problem - I now have a query that generates a list similar to this: fname, sname, uname, assignment, task, grade joe, blogs, joe.blogs, 1, 1, 52 joe, blogs, joe.blogs, 1, 2, 58 jim, blogs, jim.blogs, 1, 1, 95 jim, blogs, jim.blogs, 1, 2, 86 amy, blogs, a...

Goal Seek functionality in PHP

I want to implement functionality in PHP similar to what is available as Goal Seek in Microsoft Excel. Is such a thing possible to implement in PHP? Here is the story in detail We are writing a Personal Loan Management application for a financial company. They are at present using Excel sheets to do all kind of load, EMI, etc. calcula...

books/sites to get good at algorithm competitions

Hi, I've been practicing doing topcoder and acm contests(local ones and practice sets). But I'm hitting a brick wall in terms of performance. I can solve the first topcoder problem, but almost never the second one. I need some solid theory and memory of common strategies/algos/structures involved in these types of competitions. Just try...

Detecting endianness programmatically in a C++ program

Is there a programmatic way to detect whether or not you are on a big-endian or little-endian architecture? I need to be able to write code that will execute on an Intel or PPC system and use exactly the same code (i.e. no conditional compilation). ...

Consuming a queue's messages with the processing resource varying by message type

I'm having some trouble putting together an algorithm for an asynchronous queue consumer thread, that is reading items off of a single queue that need to be dispatched to do some long running (several seconds at least) work. Basically the queue can look as follows: A, A, A, A, A, B, B, A, B, A, A, A, A, A, C, B, A. Ie. the A messages a...

Searching geocoded information by distance

I have a database of addresses, all geocoded. What is the best way to find all addresses in our database within a certain radius of a given lat, lng? In other words a user enters (lat, lng) of a location and we return all records from our database that are within 10, 20, 50 ... etc. miles of the given location. It doesn't have to be v...

Time frames for Standard score

For finding trending topics, I use the Standard score in combination with a moving average: z-score = ([current trend] - [average historic trends]) / [standard deviation of historic trends] (Thank you very much, Nixuz) Until now, I do it as follows: Whatever the time is, for the historic trends I simply go back 24h. Assuming we have...

Algorithms for Optimization with Fast Disk Storage (SSDs)?

Given that Solid State Disks (SSDs) are decreasing in price and soon will become more prevalent as system drives, and given that their access rates are significantly higher than rotating magnetic media, what standard algorithms will gain in performance from the use of SSDs for local storage? For example, the high random read speed of SS...

What algorithm could be used to identify if images are the "same" or similar, regardless of size?

TinEye, the "reverse image search engine", allows you to upload/link to an image and it is able to search through the billion images it has crawled and it will return links to images it has found that are the same image. However, it isn't a naive checksum or anything related to that. It is often able to find both images of a higher res...

Removing cycle dependencies on a directed graph with fixed edges

I have a directed cyclic graph. Some edges are FIXED and may not be removed. The other edges may be removed to break a cycle. What is the best way to do remove the cycles in this graph? The traversal should be as much as a DFS as possible and start at a given node. ...

How do I build a list of all possible tuples from this table?

Suppose I have a set of column definitions: Col1: value11 value12 value13 Col2: value21 value22 Col3: value31 value32 value33 ... Given some subset of columns -- 2 or more -- I want to find all possible values for those columns. Suppose I choose columns 1 and 2, above: (value11 value21) (value11 value22) (value12 value21) (value12 ...

Probabilistic hashing -- is there such a thing?

Say you want to implement a click tracker where you want to only count a click to a link from any IP address once, but the number of links and clients is very large and you don't want to keep a table of every single IP-click. Say that you might need this as part of something that runs live against every click and don't want to do a looku...