## What is an efficient algorithm to find whether a singly linked list is circular/cyclic or not? [duplicate]

The standard answer is to take two iterators at the beginning, increment the first one once, and the second one twice. Check to see if they point to the same object. Then repeat until the one that is incrementing twice either hits the first one or reaches the end. This algorithm finds any circular link … Read more

## Algorithm to group sets of points together that follow a direction

Note 1: It has a number of settings -> which for other images may need to altered to get the result you want see % Settings – play around with these values Note 2: It doesn’t find all of the lines you want -> but its a starting point…. To call this function, invoke this … Read more

## Implementing a simple Trie for efficient Levenshtein Distance calculation – Java

From what I can tell you don’t need to improve the efficiency of Levenshtein Distance, you need to store your strings in a structure that stops you needing to run distance computations so many times i.e by pruning the search space. Since Levenshtein distance is a metric, you can use any of the metric spaces … Read more

## Sorting an array with minimal number of comparisons

Donald Knuth’s The Art of Computer Programming, volume 3 has a section on exactly this topic. I don’t have the books here with me, but I’m pretty sure Knuth presents the algorithm for 5 elements. As you suspect, there isn’t a general algorithm that gives the minimal number of comparisons for many sizes, but there … Read more

## Minimum number of swaps needed to change Array 1 to Array 2?

As @IVlad noted in the comment to your question Yodaness problem asks you to count number of inversions and not minimal number of swaps. For example: L1 = [2,3,4,5] L2 = [2,5,4,3] The minimal number of swaps is one (swap 5 and 3 in L2 to get L1), but number of inversions is three: (5 … Read more

## How best to sum up lots of floating point numbers?

For “more precise”: this recipe in the Python Cookbook has summation algorithms which keep the full precision (by keeping track of the subtotals). Code is in Python but even if you don’t know Python it’s clear enough to adapt to any other language. All the details are given in this paper.

## What is HTML5 File.slice method actually doing?

The important thing to keep in mind is that File inherits from Blob, File doesn’t actually have a slice method, it gets this method from Blob. File just adds a couple metadata attributes. The best way to think of a Blob (or File) is as a pointer to data, but not the actual data itself. … Read more

## Where can I find information on the D* or D* Lite pathfinding algorithm?

Wikipedia has an article on the topic: http://en.wikipedia.org/wiki/D* Also a D* Lite implementation in C is available from Sven Koenig’s page: http://idm-lab.org/code/dstarlite.tar However I find the impenetrable math much easier to read than the C source code ðŸ˜‰ Another implementation of D* Lite (in C++) is available here: http://code.google.com/p/dstarlite/

## How to find repeating sequence of characters in a given array?

Tongue-in-cheek O(NlogN) solution Perform an FFT on your string (treating characters as numeric values). Every peak in the resulting graph corresponds to a substring periodicity.

## Find all the 4 digit vampire numbers

Or you can use a property of vampire numbers described on this page (linked from Wikipedia) : An important theoretical result found by Pete Hartley: If xÂ·y is a vampire number then xÂ·y == x+y (mod 9) Proof: Let mod be the binary modulo operator and d(x) the sum of the decimal digits of x. … Read more