algorithm

Algorithm for converting Binary tree to post-fix mathematical expression?

I have a Binary tree for a mathematical expression(infix), i want to convert directly this TREE to a postfix(Stack) can any body suggest the algorithm? ...

Which algorithm can I use for distributing weighted objects equally in n portions?

I want to distribute x(i) objects (x E {1...n}), where each object has weight w(i), into n portions. The distribution should be done in such a way, that for all the portions the sum of weights is as equal as possible. Cheers! Pratik ...

WPF 3D algorithm question: what model does it use?

Please refer to Wiki definitions about 3d modeling, what modeling algorithm WPF 3d use? Polygon or NURBS? Thanks Mike ...

Rasterizing a 2D polygon

I need to create a binary bitmap from a closed 2D polygon represented as a list of points. Could you please point me to efficient and sufficiently simple algorithms to do that, or, even better, some C++ code? Thanks a lot! PS: I would like to avoid adding a dependency to my project. However if you suggest an open-source library, I can ...

qsort crashing program - C

Trying to follow this example. (Section String sorting...) Is there anything obvious that would make this crash in stdlib's qsort.c? I also tried *cstring_cmp* with strncmp specifying 30 chars max, much more than I have. *fileArray[20] seems to be correctly populated with strings. Thanks. char* ptr_fileName; char* fileArray[20];//num...

Algorithm to permute elements in Array

Consider the following scenario. I have an array of numbers: [ 1,2,3,4 ] If this array was joined i would have the number 1234. I want to swap the numbers around to achieve the clossest higher number. 1234 will become 1243, which will become 1324, which will become 1342 and so forth.. What algorithm would i need use to make this...

Natural sort in C - "array of strings, containing numbers and letters"

Looking for a proven to work algorithm for production. Did see this example but not finding much else on the web or in books. i.e. file_10.txt > file_2.txt Thanks. ...

Placing exceptions in code or in the data

Most code (and most bugs) are caused by exception handling, such as: if a is checked then input fields 1, 5, 8, and 9 are required else if b is entered then input fields 3, 4, 8 are required else if a is checked and b is checked then fields 1, 3 and 8 are required (the above is an example of buggy code since the code with the last condi...

Algorithms: Rearrange 2D Matrix (through element 'flipping')

Hello, I'm wondering about an algorithm solving the following (efficiently): A 2D matrix of numbers [1..9] which need to align in horizontal lines from top (1) to bottom (9), but only through flipping either vertically or horizontally with another number. Example Input Matrix: 1 8 2 6 1 6 9 2 5 1 6 2 3 6 9 2 9 8 5 1 7 4 2 8 4 2 7 6 9...

Efficient way to insert a number into a sorted array of numbers?

I have a sorted javascript array, and want to insert one more item into the array such the resulting array remains sorted. I could certainly implement a simple quicksort-style insertion function: var array = [1,2,3,4,5,6,7,8,9]; var element = 3.5; function insert(element, array) { array.splice(locationOf(element, array)+1, 0, element...

Solving a picture jumble!

What algorithm would you make a computer use, if you want to solve a picture jumble? You can always argue in terms of efficiency of the algorithm, but here I am really looking at what approaches to follow. Thanks ...

Shortest branch in a binary tree?

A binary tree can be encoded using two functions l and r such that for a node n, l(n) give the left child of n, r(n) give the right child of n. A branch of a tree is a path from the root to a leaf, the length of a branch to a particular leaf is the number of arcs on the path from the root to that leaf. Let MinBranch(l,r,x) be a simple ...

Algorithm for placing nodes on a circle considering their distance to eachother

I have the following problem. I have brain regions and correlations between them. The brain regions I know the distances of. Now, we expect the correlations to be negatively correlated to the distance between the brain regions. So when we increase distance correlation goes down to zero. The expectation is that this is by 1/D^2. I want ...

Is there any way to find arithmetic mean "better" than sum()/N?

Suppose we have N numbers(integers, floats, whatever you want) and want to find their arithmetic mean. Simplest method is to sum all values and divide by number of values: def simple_mean(array[N]): # pseudocode sum = 0 for i = 1 to N sum += array[i] return sum / N It works fine, but requires big integers. If we don...

Any idea about constructing a higher order Quine program?

Here is a special Haskell program which outputs a Python program that outputs a Ruby program that outputs the original Haskell program (from http://blog.sigfpe.com/2008/02/third-order-quine-in-three-languages.html) To be more exactly, the output is of this Haskell program q a b c=putStrLn $ b ++ [toEnum 10,'q','('] ++ show b ++ [','] +...

Finding patterns in Puzzle games.

I was wondering, which are the most commonly used algorithms applied to finding patterns in puzzle games conformed by grids of cells. I know that depends of many factors, like the kind of patterns You want to detect, or the rules of the game...but I wanted to know which are the most commonly used algorithms in that kind of problems... ...

Finding all disconnected subgraphs in a graph

I have a graph which contains an unknown number of disconnected subgraphs. What's a good algorithm (or Java library) to find them all? ...

Linearly increasing color darkness algorithm

Hi, I want to write a function in ruby that given a number between 1 and 500 will output a 6 digit hex color code that gets linearly darker for higher numbers. This doesn't seem that hard but I'm not sure where to begin. How can I implement this? edit Hue seems like a more reliable way to go. I'd like to give a reference color, say a...

Search form url structure

We are building a large search interface with close to 70 properties. Most of these properties are boolean (only hold 0 or 1), around 12 are with int values and some are string. goal: http://www.example.com/q/test_search/fdgREGd3vfS323 want to avoid: http://www.example.com/q/test_search/?val_12=1000&val_120=0&val_4=XY.... Our ...

Lucene search results sort by custom order list (unique to each user)

I have authenticated users in my application who have access to a shared database of up to 500,000 items. Each of the users has their own public facing web site and needs the ability to prioritize the items on display (think upvote) on their own site. out of the 500,000 items they may only have up to 200 prioritized items, the order of ...