algorithm

How can I implement QT (quality threshold) clustering in Perl?

I am having trouble with a QT clustering implementation that I want to implement in Perl. The line beginning with "identify set", the third from the end, is the part I can't figure out. The full paper is available here. ...

C# Binary Search Variation

The list is sorted. I have a List and I d like to do binary search on it. T has members like StartIndex, EndIndex etc. I can do binary search on the list with StartIndex, ie: I have implemented IComparable for this. I need to twist this a little as the following: I want to find a StartIndex that might be OffBy a small value. For exam...

Understanding Bayes' Theorem

I'm working on an implementation of A Naive Bayes Classifier. Programming Collective Intelligence introduces this subject by describing Bayes Theorem as: Pr(A | B) = Pr(B | A) x Pr(A)/Pr(B) As well as a specific example relevant to document classification: Pr(Category | Document) = Pr(Document | Category) x Pr(Category) / Pr(Document...

Compressing GPS Points

I have a device that records GPS data. A reading is taken every 2-10 seconds. For an activity taking 2 hours there are a lot of GPS points. Does anyone know of an algorithm for compressing the dataset by removing redundant data points. i.e. If a series of data points are all in a straight line then only the start and end point are requi...

Fast counting of 2D sub-matrices withing a large, dense 2D matrix?

What's a good algorithm for counting submatrices within a larger, dense matrix? If I had a single line of data, I could use a suffix tree, but I'm not sure if generalizing a suffix tree into higher dimensions is exactly straightforward or the best approach here. Thoughts? My naive solution to index the first element of the dense matrix...

question about merge sort under php

hello, i'v been trying to implement merge sort under php. but seems unsuccessful :( couldn't find source of error. any kind of help is very much appreciated! function merge_sort(&$input, $start, $end) { if($start < $end) { $mid = (int) floor($start + $end / 2); merge_sort($input, $start, $mid); merge_sort($in...

How to find second largest number using Scanner and for loop(no array)

Hi.So I can easily accomplish task to find largest number and then if can be divided by three, print out. But do not know how to find second largest number from users sequence. Thanks for any hints! public class SecondLargest { public static void main(String[] args) { int max = 0; Scanner scan = new Scanner(System.i...

Can we identify a photo in a photo?

I was browsing through some photos uploaded by a friend on Orkut [Orkut has this new feature to tell you how many unnamed people are there in the photo]. There was this particular photo in which there was an advertisement poster with a photo of a person. Orkut displayed that there are two unnamed persons in the photo. Out of curiousity, ...

What is "e" variable in popular implementations of Brent root finding algorithm?

I am reading the standard (Numerical Recipes and GSL C versions are identical) implementation of Brent root finding algorithm, and cannot understand the meaning of variable "e". The usage suggests that "e" is supposed to be the previous distance between the brackets. But then, why is it set to "xm" (half the distance) when we use bisect...

Implementing a Hilbert map of the Internet

In the XKCD comic 195 a design for a map of the Internet address space is suggested using a Hilbert curve so that items from a similar IP adresses will be clustered together. Given an IP address, how would I calculate its 2D coordinates (in the range zero to one) on such a map? ...

Efficiently finding multiple items in a container

I need to find a number of objects from a large container. The only way I can think of to do that seems to be to just search the container for one item at a time in a loop, however, even which an efficient search with an average case of say "log n" (where n is the size of the container), this gives me "m log n" (where m is the number of...

Algorithm for converting Latitude and Longitude to World Coordinates (OpenGL)

I have a set of latitude and longitude co-ordinates which are to be rendered in a GL program I'm working on. I have information such as the number of units per latitude and longitude degree (I have the co-ordinates in decimal degrees, eg, 27.1234) - for example, 15 units per longitude, and 10 units per latitude. However, I've had problem...

Which is the best algorithm to "Estimate and Visulize 2d skeleton using Opencv" from the drawn contour

Which is the best algorithm to "Estimate and Visulize 2d skeleton using Opencv" from the drawn contour Is the Recursive Centroid algorithm the Best? any reference links or docs please provide ...

Calculating the balance factor of a node in avl tree

I want to calculate the balance factor of a node in avl tree without using any recursive procedure. How can i do that? Please tell me method or provide C++ code snippet. ...

How could I refactor this code with performance in mind?

I have a method where performance is really important (I know premature optimization is the root of all evil. I know I should and I did profile my code. In this application every tenth of a second I save is a big win.) This method uses different heuristics to generate and return elements. The heuristics are used sequentially: the first h...

Efficiently estimating the number of unique elements in a large list

This problem is a little similar to that solved by reservoir sampling, but not the same. I think its also a rather interesting problem. I have a large dataset (typically hundreds of millions of elements), and I want to estimate the number of unique elements in this dataset. There may be anywhere from a few, to millions of unique eleme...

Check if a binary number has a '0' or a '1' at a specific position

Hi I'd like to check if a binary number has a '0' or a '1' at a specific position. example: if the binary number is: 101000100 checking at position zero (that is at the rightmost '0') should result in '0'. checking at position 2 should result in '1'. checking at position 3 should result in '0'. checking at position 6 should result i...

Book Recommendation on Graph Theory

Hello, I m sorry this obviously is not a programming questions, hope it s fine. Can you please recommend a book on graph theory? Not a very complicated book, with good explanations and examples. I have already read CLRS and Algorithm Manual. Thanks. ...

Creating a "crossover" function for a genetic algorithm to improve network paths

Hi, I'm trying to develop a genetic algorithm that will find the most efficient way to connect a given number of nodes at specified locations. All the nodes on the network must be able to connect to the server node and there must be no cycles within the network. It's basically a tree. I have a function that can measure the "fitness"...

Data structure for handling intervals

I have got a series of time intervals (t_start,t_end), that cannot overlap, i.e.: t_end(i) > t_start(i+1). I want to do the following operations: 1) Add new (Union of) intervals [ {(1,4),(8,10)} U (3,7) = {(1,7),(8,10)} ] 2) Take intervals out [ (1,7) - (3,5) = {(1,3),(5,7)} 3) Checking whether a point or a interval overlaps with an int...