algorithm

How should I cluster items into an ordered collection that makes sense graphically?

I've got an an application wherein I will be provided with an unordered collection of items (objects that can basically be represented as rectangles) and need to put them into a larger rectangular shape (a cluster) based off of their physical location. There may be more than one cluster of items, and some items may be in a cluster by the...

find four elements in array whose sum equal to a given number X

hello, I need help to find an algorithm that finds: four elements in array whose sum equal to a given number X in O(n^2*log(n)) prefer in pseudo-code or c,c++ thanks moti ...

How to decompose an integer in two for grid creation

Given an integer N I want to find two integers A and B that satisfy A B N with the following conditions: The difference between A B and N is as low as possible. The difference between A and B is as low as possible (to approach a square). Example: 23. Possible solutions 3 8, 6 4, 5 5. 6 4 is the best since it leaves just one em...

Question about Binary Search Tree?

Today, in class my professors said there's a balance binary search tree which I never heard of it before. I would like to know is there a Balance Binary Search tree without rotation? From my understanding, Balance Binary Search Tree is AVL tree. Besides that I don't think it's possible to build a 'Balance Binary Search Tree'. But if in ...

Interview Question: Find Median From Mega Number Of Integers

There is a file that contains 10G(1000000000) number of integers, please find the Median of these integers. you are given 2G memory to do this. Can anyone come up with an reasonable way? thanks! ...

OCR rotated image

Hi I have a couple of images including labels that have angles between 0 and 180 degrees. Any way to detect them using existing OCR tools or any algorithm for that? ...

Most efficient way to visit nodes of a DAG in order

I have a large (100,000+ nodes) Directed Acyclic Graph (DAG) and would like to run a "visitor" type function on each node in order, where order is defined by the arrows in the graph. i.e. all parents of a node are guaranteed to be visited before the node itself. If two nodes do not refer to each other directly or indirectly, then I don'...

How to find out if a sentence is a question (interrogative)?

Is there an open source Java library/algorithm for finding if a particular piece of text is a question or not? I am working on a question answering system that needs to analyze if the text input by user is a question. I think the problem can probably be solved by using opensource NLP libraries but its obviously more complicated than s...

Is there a nice Java object to hold a 2D grid of doubles?

Is there a data type that simply holds a 2D grid of doubles? Preferably in the JDK but I'm happy to use an open source 3rd party library like apache commons etc. I'm looking for a class, and/or complimentary helper classes, that allow methods like these: Grid g = new DoubleGrid(100, 100); double min = g.getMinValue(); double someCell...

Weighted Interval Scheduling problem & Dynamic program

Hi guys! My question is related to this other discussion. I'm trying to implement that algorithm using the dynamic program into a recursive call. Problem statement: Job j starts at sj, finishes at fj,and has weight or value vj. Two jobs compatible if they don't overlap. Goal: find maximum weight subset of mutually compatible jobs. ...

Algorithm to balance variably-sized items into roughly-balanced sets

I'm seeking an algorithm to split a list of items of varying sizes into "N" number of similarly-sized groups. Specifically, I'm working on an ASP.NET site in C# where I have a (database-retrieved) list of strings. The strings are of varying lengths. I have a set of columns which need to display the strings. I need an algorithm that will...

String similarity algorithims?

I need to compare 2 strings and calculate their similarity, to filter down a list of the most similar strings. Eg. searching for "dog" would return dog doggone bog fog foggy Eg. searching for "crack" would return crack wisecrack rack jack quack I have come across: QuickSilver LiquidMetal Do you know of any more string simila...

Dependency between group or radiobuttons, best practices?

Hello, Let's imagine that we have privacy options page in social network; two group of radio buttons. Allow to post on wall p f c (groupA) Allow to view wall p f c (groupB) p = public f = only friends c = closed It is obvious that there is a dependency between this groups of checkboxes. For example, we should automaticall...

Truncating Strings in Java by Bytes

Hey all. I create the following for truncating a string in java to a new string with a given number of bytes. String truncatedValue = ""; String currentValue = string; int pivotIndex = (int) Math.round(((double) string.length())/2); while(!truncatedValue.equals(currentValue)){ currentValue ...

Elegant way of finding two consecutive values in sorted array that bound a given value?

I have an array of sorted integers, and I'd like to get the two consecutive indices of elements that bound a particular value I pass in. To illustrate, because it's hard to describe in words, let's say I have an array (regular zero-indexed): 1 3 4 5 7 9 I want to get the two indices that bound, say, the value 6. In this case, the arra...

Efficient algorithm to find additions and removals from 2 collections

Hi I would like to implement an efficient algorithm to handle the following case: Lets assume we have 2 lists with the following elements: Source: [a,b,c,d,e] New: [d,e,f,g] Now I have to update source with the new information. The algorithm should be able to find that 'f' and 'g' are new entries, that 'a', 'b' and 'c' has been remove...

What graph traversal algorithm should I use for this?

Hello, I need to traverse a directed graph in a certain way and I'm not sure the algorithm to use. Perhaps Stackoverflow can help. The situation - I have a directed graph where the edges have a number associated with them. Let's assume this number is a distance measured in feet, miles, ..., whatever. I'd like to traverse from a start no...

What's the algorithm behind minesweeper generation

Well I have been through many sites teaching on how to solve it, but was wondering how to create it. I am not interested much in the coding aspects of it, but wanted to know more on the algorithms behind it. For example, when the grid is generated with 10 mines or so, I would use any random function to distribute itself across the grid,...

What's an Efficient Inversion of the Convert-to-Arbitrary-Base C# Function?

I need to convert an integer into a base64-character representation. I'm using OxA3's answer on this thread: http://stackoverflow.com/questions/923771/quickest-way-to-convert-a-base-10-number-to-any-base-in-net How do I inverse this to get my original integer back, given a string? ...

Prevent webservice to be called from different Client App

I have this webservice at work. For that webservice our department have developed a client to consume the webservice. What we want to prevent is, that they develop any other client to consume it. Is there any algorithm, practice that we can improve in our client and webservice communication to validate that the consuming client is our...