algorithm

How to print string association from phone number as text?

I need some help with a method i'm writing for a project. the method changes a phone number into a list of text strings. You know that 2-9 have letters associated with them on a phone. i would like to make a converter that will change a 7 digit number to a list of strings. i would like to see all possibilities. i already cut out all th...

Finding the closest point from a set of points on plane

Given n points on a 2-D plane, what is the point such that the distance from all the points is minimized? This point need not be from the set of points given. Is it centroid or something else? How to find all such points(if more than one) with an algorithm? ...

The perverse hangman problem

Perverse Hangman is a game played much like regular Hangman with one important difference: The winning word is determined dynamically by the house depending on what letters have been guessed. For example, say you have the board _ A I L and 12 remaining guesses. Because there are 13 different words ending in AIL (bail, fail, hail, jail, ...

Minimising distance: distance formula

I am writing a program in C. I want to find a solution by minimizing expression D1+D2+......+Dn where Di's are distances calculated by distance formula between 2 points. The above expression is in x & y variables Now I will differentiate this expression and find the solution. My doubt is: since in the above expression, all Di's will...

What is an algorithm to return free space in blocks of largest possible rectangles?

Algorithm Consider this layout: +-------------+ | | | | | +--+ | | |##| | | |##| | | +--+------+ | |######| | |######| +------+------+ The black part is the occupied space. Now I need an algorithm that returns the largest remaining rectangular spaces. (Ordered from top to bott...

Selection of neighbors cells in a hexagonal field

Imagine hexagonal space with 3 dimensions. Each tile has coordinates XYZ. I need to select a given cell neighbors in the same plane. With SQL it's looks like: $tbDir = $y % 2 == 0 ? -1 : 1; $result = db_query('SELECT x,y,z FROM {cells} WHERE x = %d AND y = %d AND z = %d OR x = %d AND y = %d AND z = %d OR ...

Best way string-matching algorithm for same-length strings?

I need to implement a string-matching algorithm to determine which strings most closely match. I see the the Hamming distance is a good matching algorithm when this fixed-length is obtainable. Is there any advantage in the quality of matching if I were to use the Levenshtein distance formula instead? I know this method is less effic...

O(NlogN) finding 3 numbers that have a sum of any arbitrary T in an array

Given an array A of integers, find any 3 of them that sum to any given T. I saw this on some online post, which claims it has a O(NlogN) solution. For 2 numbers, I know hashtable could help for O(N), but for 3 numbers, I cannot find one. I also feel this problem sounds familar to some hard problems, but cannot recall the name and th...

Sieve of Eratosthenes Algorithm

Hi All, I did some searching and was not able to find any information regarding this implementation versus every other one I have seen. function sieve($top) { for($i = 11; $i<$top; $i+=2) { if($i % 3 == 0 || $i % 5 == 0 || $i % 7 == 0) { continue; } echo "$i <br /...

Bitmap compare method on the iPhone (unity3d)

Hi. What would be the best method to compare 2 bitmaps and get the correlation between the 2 (0 being completely different and 1 being exactly the same) in Unity3d on the iPhone? I am using C# since documentation says that using Boo or UnityScript will increase the size of the application. What I need is something similar to the fingerp...

How do you search for logic (algorithm/problem)?

I often find it is difficult to find something that I know the logic sounds familar but cannot recall the name. Using the existing string based search engine just won't get you good result as most of the time the logic is expressed in a totally different way. I understand the generic problem is a unsolvable AI problem. The question ...

Computing overlaps of grids

Say I have two maps, each represented as a 2D array. Each map contains several distinct features (rocks, grass, plants, trees, etc.). I know the two maps are of the same general region but I would like to find out: 1.) if they overlap and 2.) if so, where does this overlap occur. Does anyone know of any algorithms which would help me ...

What is the best single-source shortest path algorithm for programming contests?

I was working on this graph problem from the UVa problem set. It's a single-source-shortest-paths problem with no negative edge weights. From what I've gathered, the algorithm with the best big-O running time for such problems is Dijkstra with a Fibonacci heap as the priority queue, although practically speaking a binary heap is easier t...

N-Queens Problem..How far can we go?

The N-Queens Problem: This problem states that Given a chess board of size N by N. Find the different permutations in which N queens can be placed on the Board without any one killing each other. My question is: What is the maximum value of N for which a program can calculate the answer in reasonable amount of time? Or what is the lar...

Using finite automata as keys to a container

I have a problem where I really need to be able to use finite automata as the keys to an associative container. Each key should actually represent an equivalence class of automata, so that when I search, I will find an equivalent automaton (if such a key exists), even if that automaton isn't structurally identical. An obvious last-resor...

How can I sort a Perl list in an arbitrary order?

Hi Everyone, I have a list of strings whose values come from a fixed set. I need to sort this list in an arbitrary order. The order of the set is specified by another list of all possible strings, sorted in order in an array. Here is an example: my @all_possible_strings_in_order = ('name', 'street', 'city','state', 'postalcode'); ...

Compare the two ArrayLists in java which contains same objects

Hi, I have a two ArrayList given below as sample. AccVO: compareKey,Amount fields List 1: AccVO[001,500] AccVO[002,600] AccVO[003,800] List2: AccVO[001,100] ...

Multithreading - Avoiding and dealing with database deadlocks

I am looking for a good strategy of dealing with database deadlocks from within a Java 6 application; several parallel threads could, potentially, write into the same table at the same time. The database (Ingres RDMBS) will randomly kill one of the sessions if it detects a deadlock. What would be an acceptable technique to deal with the...

Is there an algorithm which prints out a shuffled list without actually modifing the list?

After reading this question I started to wonder: is it possible to have a shuffling algorithm which does not modify or copy the original list? To make it clear: Imagine you are given a list of objects. The list size can be arbitrary, but assume it's pretty large (say, 10,000,000 items). You need to print out the items of the list in ra...

Simple Automatic Classification of the (R-->R) Functions

Given data values of some real-time physical process (e.g. network traffic) it is to find a name of the function which "at best" matches with the data. I have a set of functions of type y=f(t) where y and t are real: funcs = set([cos, tan, exp, log]) and a list of data values: vals = [59874.141, 192754.791, 342413.392, 1102604.284...