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

OpenCV / SURF How to generate a image hash / fingerprint / signature out of the descriptors?

The feature data you mention (position, laplacian, size, orientation, hessian) is insufficient for your purpose (these are actually the less relevant parts of the descriptor if you want to do matching). The data you want to look at are the “descriptors” (the 4th argument): void cvExtractSURF(const CvArr* image, const CvArr* mask, CvSeq** keypoints, CvSeq** descriptors, … Read more

What data structure, exactly, are deques in C++?

It’s implementation specific. All a deque requires is constant time insertion/deletion at the start/end, and at most linear elsewhere. Elements are not required to be contiguous. Most implementations use what can be described as an unrolled list. Fixed-sized arrays get allocated on the heap and pointers to these arrays are stored in a dynamically sized … Read more

Difference between HashMap and HashTable purely in Data Structures

In Computing Science terminology, a map is an associative container mapping from a key to a value. In other words, you can do operations like “for key K remember value V” and later “for key K get the value”. A map can be implemented in many ways – for example, with a (optionally balanced) binary … Read more

Is there a standard Java implementation of a Fibonacci heap?

No, the standard Java collections API does not contain an implementation of a Fibonacci heap. I’m not sure why this is, but I believe it is because while Fibonacci heaps are asymptotically great in an amortized sense, they have huge constant factors in practice. The collections framework also doesn’t have a binomial heap, which would … Read more

What are lenses used/useful for?

They offer a clean abstraction over data updates, and are never really “needed.” They just let you reason about a problem in a different way. In some imperative/”object-oriented” programming languages like C, you have the familiar concept of some collection of values (let’s call them “structs”) and ways to label each value in the collection … Read more