algorithm

How does this work? Weird Towers of Hanoi Solution

I was lost on the internet when I discovered this unusual, iterative solution to the towers of Hanoi: for (int x=1; x < (1 << nDisks); x++) { FromPole = (x&x-1)%3; ToPole = ((x|x-1)+1)%3; moveDisk(FromPole,ToPole); } This post also has similar Delphi code in one of the answers. However, for the life of me, ...

How to overlay two images (as byte arrays)

People, i'm sure that it's quite easy, but google didn't helped... Here is the task - i have two byte arrays (as ARGB), representing my images. They have the same size. What operation i should perform (byte by byte) to overlay one image to another? Second image has some transparency, which must be considered. To clear, im looking for a...

Two Keys Are Better Than One

I have a widget class: public class Widget { ... public string UniqueID = "856D9PWW"; public int Price = 325; public byte[] Data; ... } I would like a data structure to store my widgets in. Here's the catch - sometimes I need to find a group of widgets based in their price, and sometimes I need to find a specific ...

What Neural Network framework provides the best balance of performance, ease of use, and correctness of results?

I need to try a Neural Network on an interesting research problem I'm faced with. Any language is fine, although I suspect the best NN's are probably in C. I would like to be able to integrate with Java or PHP, but it's not 100% necessary. What is the best choice from the dozens of open-source NN frameworks out there? ...

Combining MD5 hash values

When calculating a single MD5 checksum on a large file, what technique is generally used to combine the various MD5 values into a single value? Do you just add them together? I'm not really interested in any particular language, library or API which will do this; rather I'm just interested in the technique behind it. Can someone expla...

Data mining algorithms comparison

Are there any data mining algorithms comparisons? Comparisons in terms of performance, accuracy and the required amount of data for generating the robust model. It seems that ensemble learning algorithms like bagging and boosting are considered to be the most accurate at this moment. I don't have any specific problem to solve. It's just ...

what is the better way to search in millions of file names with wildcard(GLOB) support

i am working on a small search engine to display a matching file names with full path. and important thing is that i need to provide wildcard(GLOB) search like *.doc or *list*.xlx or *timesheet* or ???.doc or something like that. i found some related solution http://stackoverflow.com/questions/954752/search-for-strings-matching-the-p...

Algorithm: optimal way to rearrange a list from one order to another?

EDIT: I'm not sure that my original question is clear enough. I need an algorithm that will compute the minimal sequence of moves to rearrange an array from one order to another. It is known that both arrays will contain the same elements (no duplicates) and have the same length. For example: reorder( ['d', 'a', 'c', 'b', 'e'], [...

What is the algorithm of converting pcm to adpcm?

What is the algorithm of converting pcm to adpcm? ...

What is wrong with my algorithm?

Alright, I've cooked up some code to reverse hex characters around as part of a fun exercise I made up. Here is what I have at the moment: #include <stdio.h> int main() { char a,b,c; while (1) { c = getchar(); if (!feof(stdin)) { a = c % 16; b = (c - a) / 16; c...

Find the big-O of a function

Please help me on following two functions, I need to simplify them. O(nlogn + n^1.01) O(log (n^2)) My current idea is O(nlogn + n^1.01) = O(nlogn) O(log (n^2)) = O (log (n^2)) Please kindly help me on these two simplification problems and briefly give an explanation, thanks. ...

Can the bigO of an algorithm be found programmatically by analyzing its perfs?

Note that I don't have a "problem" and I'm not looking for "another way to find the big O of my algorithm". What I'd like to know is if it would be possible write a program to which you'd pass data points that would all be perfs measurements of an algorithm for various input size: (n,time taken to solve problem for n) and that would the...

Finding the intersecting node from two intersecting linked lists.

Suppose there are two singly linked lists both of which intersect at some point and become a single linked list. The head or start pointers of both the lists are known, but the intersecting node is not known. Also, the number of nodes in each of the list before they intersect are unknown and both list may have it different i.e. List1 ma...

Construct a binary tree such that the Post-order traversal should give the sorted result

Hi, I know that In-order traversal(VISIT LEFT, VISIT ROOT, VISIT RIGHT) on a binary search tree gives me a sorted result. But I need to do a Post-order traversal (VISIT LEFT, VISIT RIGHT, VISIT ROOT) on a binary tree and the result should give me sorted values. In order to achieve that, how should I construct my binary tree? ...

Interview question: Design a datastructure to support stack operations and to find minimun

Design a data structure which has the following features push the data pops the last inserted data [LIFO] Gives the minimum All of the above operations should have a complexity of O(1) ...

Smallest sum of pairs

Given 2N-points in a 2D-plane, you have to group them into N pairs such that the overall sum of distances between the points of all of the pairs is the minimum possible value.The desired output is only the sum. In other words, if a1,a2,..an are the distances between points of first, second...and nth pair respectively, then (a1+a2+...an...

Specific Path Algorithm with Speed Considered

I need to create an algorithm where a "vehicle" covers a 1262 m x 1262 m area with 20% overlap between each "leg". The width of each leg is 103 m, which by my calculations gives 16 "legs" needed to cover this area. At the end of each leg, the vehicle does a 180 degree turn, and completes the next search leg. The vehicle is traveling a...

Arrays.sort(Object[] a) - how is it implemented?

Are there any resources on how the mergeSort used by Arrays.sort(Object[] a) is implemented? While it is documented quite good, I have a hard time understanding it (especially why the src and dest are are switched when mergeSort() get's recursively called). ...

Dijkstra recurisve

Hi i'm having trouble doing an homework , i've to make recursive version of Dijkstra Algorithm , can somebody help me? ...

Any distributed parallel tree search algorithm suggestions?

Hello there, I'm writing a distributed Go/Gomoku bot. Basically the point is to distribute tree search onto many computers. With basic tree search algorithms like DFS this would be very simple, as I could just partition search space into subtrees. Though I'd rather have something more efficient, like mini-max with alpha-beta pruning - ...