algorithm

What is No of hamiltonian cycles in a complete graph`

Please explain How to derive formula for number of hamiltonian cycles in a complete undirected graph. at wikipedia it is given that it is (n-1)!/2 but when I calculated K3 has only one cycle and K4 has 5. Or I am wrong. Please elaborate ...

What is dynamic programming algorithm for finding a Hamiltonian cycle?

What is dynamic programming algorithm for finding a Hamiltonian cycle in a undirected graph? I have seen somewhere that there exists a algorithm with O(n*2^n) time complextity ...

Graph algorithm - Looking to improve scalability

I've written an algorithm which calculates and stores all paths of a DAG, and it works nicely on small graphs - but now i'm looking to improve it's efficiency to run over larger graphs. The core logic of the algorithm is in createSF() and makePathList() below, the other methods are helpers - I can see that append is a bottleneck. Howeve...

How to spot and analyse similar patterns like Excel does?

You know the functionality in Excel when you type 3 rows with a certain pattern and drag the column all the way down Excel tries to continue the pattern for you. For example Type... test-1 test-2 test-3 Excel will continue it with: test-4 test-5 test-n... Same works for some other patterns such as dates and so on. I'm trying...

How to sort nearly sorted array in the fastest time possible? (Java)

I have an array of values which is almost, but not quite sorted, with a few values displaced (say, 50 in 100000). How to sort it most efficiently? (performance is absolutely crucial here and should be way faster than O(N)). I know about smoothsort, but I can't find Java implementation. Does anyone know whether it is already implemented?...

How do I select all elements in a list that are out-of-order?

This question arose from the discussion in the comments of this answer. First, let's say it's quite difficult to define what out-of-order is. Taking the example Pavel Shved gave, in the list [1,5,10,2,3,4,5,6,7,8,9,10,11] we can "clearly" see that 5 and 10 (indices 1 and 2) are out of order. But a naïve algorithm that simply checks some...

Rabin-Karp Algorithm in PHP

Hey people! I was wondering if anyone can share a source for Rabin-Karp algorithm? Thanks ...

Best articles to start learning about edge detection/image recognition

Hi, I am involved in a personal project which will require pretty extensive knowledge of edge detection and image segmentation/object recognition. I know the importance of planning/understanding before writing code and with this in mind, what is the best place to start, to learn about these areas of computing? I am ideally looking for ...

Finding a minimum number of transformation

I need an algorithm which calculates something similar to the Levenshtein distance. It should calculate the minimal possible number of transformations to get from one sequence to another. The allowed transformations are deletion, insertion and move: Deletion of 3: before {1, 2, 3, 4}, after {1, 2, 4} Insertion of 5: before {1, 2, 3, 4}...

Parallel Programming and Numerical Methods References / Books

I am looking for strong references on parallel computing and numerical methods. While there are a lot of questions and posted references on these topics independently, I would like to find a body of knowledge dedicated to their intersection. For example What algorithms (such as an eigen decomposition or a matrix inverse) are well sui...

Canny Edge Detector in C

I am looking for a bit of clarification on how the algorithms implemented in Canny edge detection - Wikipedia entry - work. It seems pretty straightforward to perform noise reduction using a 2D Gaussian filter, but I have heard that using two 1D filters - how is this accomplished? It's also simple to calculate the gradient and edge dir...

Algorithm to generate bit mask

I was facing this unique problem of generating a bit-mask based on the input parameter. For example, if param = 2, then the mask will be 0x3 (11b) if param = 5, then the mask will be 0x1F (1 1111b) This I implemented using a for-loop in C, something like int nMask = 0; for (int i = 0; i < param; i ++) { nMask |= (1 << i); } I ...

how to display something one time every hour in asp.net ?

how to display something one time every hour in asp.net ? example for show messeage in Begining hour one time only? i use for asp.net ajax timer control? protected void Timer1_Tick(object sender, EventArgs e) { MessageBoxShow(Session["playsound"].ToString()); Session["playsound"] = 1; } but alway null? -------------...

Space efficiency of algorithms...

It seems like none of the algorithm textbooks mentions about space efficiency as much, so I don't really understand when I encounter questions asking for an algorithm that requires only constant memory. What would be an example of a few examples of algorithms that uses constant memory and algorithms that doesn't use constant memory? ...

C# rounding DateTime objects

I want to round dates/times to the nearest interval for a charting application. I'd like an extension method signature like follows so that the rounding can be acheived for any level of accuracy: static DateTime Round(this DateTime date, TimeSpan span); The idea is that if I pass in a timespan of ten minutes, it will round to the near...

The algorithm to check private message in a SNS website.

Currently,I do it in a straightforward way, that is, when user loads every page, we check once. we check it by directly query the private_message table. Any better/efficiency way? ...

Are AVL Trees Evil?

I was reading the article from Steve Yegge about singletons. In it he mentions his teacher told him AVL Trees were evil. Is it just that red and black trees are a better solution? ...

What can be the efficient approach to solve the 8 puzzle problem?

The 8-puzzle is a square board with 9 positions, filled by 8 numbered tiles and one gap. At any point, a tile adjacent to the gap can be moved into the gap, creating a new gap position. In other words the gap can be swapped with an adjacent (horizontally and vertically) tile. The objective in the game is to begin with an arbitrary config...

Regular space subdivision

I am writing an application which subdivides an N-dimensional axis aligned bounding box into smaller N-dimensional bounding boxes, I need an algorithm which will do this. For example: in 1 dimension a "bounding box" is simply a length e.g. { Min=0, Max=100 } which would be subdivided into {Min=0, Max=50} and {Min=50, Max=100} in 2 dim...

Determining Perfect Hash Lookup Table for Pearson Hash

I'm developing a programming language, and in my programming language, I'm storing objects as hash tables. The hash function I'm using is Pearson Hashing, which depends on a 256-bit lookup table. Here's the function: char* pearson(char* name, char* lookup) { char index = '\0'; while(*name) { index = lookup[index ^ ...