algorithm

Binary Trees question. Checking for similar shape

Hi I'm stuck doing this, not sure how to go about it. If I have two binary trees, how would I check if the have the same shape? Data in the nodes doesn't matter, just if the tree structures are equal. Any ideas on how to solve this problem? ...

How to code a URL shortener?

I want to create a URL shortener service where you can write a long URL into an input field and the service shortens the URL to "http://www.example.org/abcdef". Instead of "abcdef" there can be any other string with six characters containing a-z, A-Z and 0-9. That makes 56 trillion possible strings. My approach: I have a database table...

How to design an approximate path solution?

Hello everyone. I am attempting to write (or expand on an existing) graph search algorithm that will let me find the path to get closest to destination node considering there is no guarantee that the nodes will be connected. To provide a realistic application of this, let's say I need to get from Brampton, Ontario to Hamilton, Ontario....

Pathfinding Algorithm for Robot

I have a robot that uses an optical mouse as a position track. Basically, as the robot moves it is able to track change in X and Y directions using the mouse. The mouse also tracks which direction you are moving - ie negative X or positive X. These values are summed into separate X and Y registers. Now, the robot rotates in place and m...

Entropy repacking

I have been tossing around a conceptual idea for a machine (as in a Turing machine) and I'm wondering if any work has been done on this or related topics. The idea is a machine that takes an entropy stream and gives out random symbols in any range without losing any entropy. I'll grand that is a far from rigorous description so I'll g...

Algorithm about number combination problem

Write a function that given a string of digits and a target value, prints where to put +'s and *'s between the digits so they combine exactly to the target value. Note there may be more than one answer, it doesn't matter which one you print. Examples: "1231231234",11353 -> "12*3+1+23*123*4" "3456237490",1185 -> "3*4*56+2+3*7+490" "3...

Shorten a text and only keep important sentences

Hello! The German website nandoo.net offers the possibility to shorten a news article. If you change the percentage value with a slider, the text changes and some sentences are left out. You can see that in action here: http://www.nandoo.net/read/article/299925/ The news article is on the left side and tags are marked. The slider...

PCP Theorem

Could somebody describe the PCP Theorem in layman's terms? [edit:Im a computer science student beginning theory.] ...

Fast WPF Particle Background

Hello, I am building a WPF application and I want its background to be filled with particles with random: Opacity/z-order Size Velocity "Fuzziness" (blur effect) Directions (or path) I've found a really good example of what I'd like it to be, but unfortunately it's in Flash and it's not free... I've tried to implement it but I can'...

Which FIPS compatible algorithm is better in dotNet 2.0?

I used Rijndael algorithm to encrypt/decrypt my data. But it is not FIPS compatible. I want to change it to another one. Could you please give me a suggestion that which one is better? Better means: FIPS compatible High security level This algorithm should came from dotnet 2.0 framework which provided by Microsoft. Thanks -Jamebo ...

What does it mean to 'hash cons'?

When to use it and why? My question comes from the sentence: "hash cons with some classes and compare their instances with reference equality" ...

Algorithm to classify a list of products? Take 2.

Hello all, I asked a question similar to this one a couple of weeks ago, but I did not ask the question correctly. So I am re-asking here the question with more details and I would like to get a more AI oriented answer. I have a list representing products which are more or less the same. For instance, in the list below, they are all S...

[YAAQ] Array of size n, with one element n/2 times..

Given an array of n integers, where one element appears more than n/2 times. We need to find that element in linear time and constant extra space. YAAQ: Yet another arrays question. ...

How to find list of possible words from a letter matrix [Boggle Solver]

Lately I have been playing a game on my iPhone called Scramble. Some of you may know this game as Boggle. Essentially, when the game starts you get a matrix of letters like so: F X I E A M L O E W B X A S T U The goal of the game is to find as many words as you can that can be formed by chaining letters together. You can start with an...

Best Algorithm for Bit Reversal ( from MSB->LSB to LSB->MSB) in C

What is the best algorithm to achieve the following: 0010 0000 => 0000 0100 The conversion is from MSB->LSB to LSB->MSB. All bits must be reversed; that is, this is not endianness-swapping. ...

[YAAQ] Monotonically increasing 2-d array.

Give an algorithm to find a given element x (give the co-ordinates), in an n by n matrix where the rows and columns are monotonically increasing. My thoughts: Reduce problem set size. In the 1st column, find the largest element <= x. We know x must be in this row or after (lower). In the last column of the matrix, find the smallest el...

Is the normal union/find algorithm thread safe without any extra work?

The standard union/find or Disjoint-set data structure has very good running times (effectively O(1)) for single threaded cases. However what is it's validity/performance under multi-threaded cases? I think that it is totally valid even without locking or any atomic operations aside from atomic pointer sized writes. Does anyone see any ...

Algorithm for finding total idle time given array of start/end times

Say you're given a start and end time. Also you're given an array of jobs, described by their start and end times. These jobs may overlap (ie, there can be multiple jobs running at once). I need to find a way to determine how much time was spent idle and not running any job. Of course, if only one job can be running at any time, I cou...

Finding best position for element in list

Hello, I have List collection that is populated in specific order (the requirement is that, this order can not be changed). This list contains entity type objects. After initial population of the list, I need to insert few more object, that are coming from another data source. These objects need to be inserted at specific position, so...

Sorting in linear time?

Given an input set of n integers in the range [0..n^3-1], provide a linear time sorting algorithm. This is a review for my test on thursday, and I have no idea how to approach this problem. ...