algorithm

Efficient polynomial evaluation with Horner's Algorithm

I have the equation y = 3(x+1)^2 + 5(x+1)^4. Using Horner's scheme I could evaluate this polynomial in this form, y = 8+x(26+x(33+x(20+5x))), thus requiring 8 arithmetic operations. I could also evaluate it in this form, y = (x+1)^2 * ((5x+10)x+8), requiring 7 operations. I've been told this can be done in 5 operations but Horner's a...

Computing an angle from x,y coordinates

I'm trying to do collision testing between a finite line segment, and an arc segment. I have a collision test which does line segment vs. line segment, so I was going to approximate these arc segments with line segments and run my existing test. The data I have defining the arc segment(s) are three points. Two of which are endpoints th...

Is there an algorithm for solving such projection reconstruction geometric problem?

We have a grid with red squares on it. Meaning we have an array of 3 squares (with angles == 90 deg) which as we know have same size, lying on the same plane and with same rotation relative to the plane they are lying on, and are not situated on same line on plane. We have a projection of the space which contains the plane with squares...

Sorting A List Of Songs By Popularity

For student council this year, I'm on the "songs" committee, we pick the songs. Unfortunately, the kids at the dances always end up hating some of the stupid song choices. I thought I could make it different this year. Last thursday, I created a simple PHP application so kids could submit songs into the database, supplying a song name, a...

Algorithm for iterating over an outward spiral on a discrete 2D grid from the origin

For example, here is the shape of intended spiral (and each step of the iteration) y | | 16 15 14 13 12 17 4 3 2 11 -- 18 5 0 1 10 --- x 19 6 7 8 9 20 21 22 23 24 | | Where the lines are the x and y axes. Here would be the actual values the algorithm would "retur...

how do i convert speed and bearing to azimuth and elevation in c#?

i have no clue to it. can someone help me out? ...

Why java Arrays use two different sort algorithms for different types ?

Hi all, I look at the source code of Arrays.java 's sort method, it uses quicksort for primitive type of array and merge sort for object type of array, what is the consideration ? I believe most of time quicksort is faster than merge sort and costs less memory, and my experiments approve that. Although they are both O(nlogn). So why her...

"Center of Mass" between a set of points on a Toroidally-Wrapped Map that minimizes average distance to all points

edit As someone has pointed out, what I'm looking for is actually the point minimizing total geodesic distance between all other points My map is topographically similar to the ones in Pac Man and Asteroids. Going past the top will warp you to the bottom, and going past the left will warp you to the right. Say I have two points (of ...

Whats the best algorithm for Non Disjoint Set Union ?

Lets say there are two (non disjoint) sets of points (cartesian space), what is the best case complexity algorithm to perform the union of the two sets ? ...

Counting regular working days in a given period of time

Hi guys, need some help. I need to count regular working days for a given date period, for example, in our country, we have 5 regular working days monday to friday, then in code i need to exclude saturdays and sundays when I use it on my computations. I need an algorithm something like this in C#: int GetRegularWorkingDays(DateTim...

Sequentially distribute data from a list to arrays of different weight

How to, Sequentially distribute data from a list to arrays (or some other structure) of fixed size/weight. For example, lets say I have a list of 10 elements. I want to sequentially distribute the elements to 3 arrays A, B, and C. The arrays are given a weight lets say A=3, B=5, and C=2. The element would be distributed in the followi...

How to determine global and local mins and maxs in sql server 2008?

I am trying to figure out the best way to determine global and local mins and maxs for a data set. I think there has got to be an easy way to do this but I cannot figure it out. I am using Sql Server 2008. Lets say I have a data set of subscription dates for users. Start Date Stop Date PersonID 12/31/2007 3/31/2008 ...

Algorithm to find optimal groups

A device contains an array of locations, some of which contain values that we want to read periodically. Our list of locations that we want to read periodically also specifies how often we want to read them. It is permitted to read a value more frequently than specified, but not less frequently. A single read operation can read a conti...

Game of life in C#

Can we represent Conway's game of life using graphs? And is there any example out there? Or any help would be much appreciated. ...

Minimizing the effect of rounding errors caused by repeated operations effectively.

I just recently came across the Kahan (or compensated) summation algorithm for minimizing roundoff, and I'd like to know if there are equivalent algorithms for division and/or multiplication, as well as subtraction (if there happens to be one, I know about associativity). Implementation examples in any language, pseudo-code or links woul...

Any ideas on real life rocks 3d Reconstruction from Single View?

So in general, when we think of Single View Reconstruction we think of working with planes, simple textures and so on... Generally, simple objects from nature's point of view. But what about such thing as wet beach stones? I wonder if there are any algorithms that could help with reconstructing 3d from single picture of stones? ...

Minimal instruction set to solve any problem with a computer program

Years ago, I have heard that someone was about to demonstrate that every computer program could be solved with just three instructions: Assignment Conditional Loop Please I would like to hear your opinion. I mean representing any algorithm as a computer program. Do you agree with this? ...

Help with Shannon–Fano coding

Hello I hope some one will help me with this=): I have a set of some numbers, I need to divide them in two groups with approximately equal sum and assigning the first group with "1", second with "0", then divide each group the same way in to subgroups until subgroups will be one of number from set! Picture explaining this crazy things):...

How to get rotation angles of Image Plane relative to the World Plane?

So we have such situation: In this illustration, the first quadrilateral is shown on the Image Plane and the second quadrilateral is shown on the World Plane. [1] In my particular case the Image Plane has 3 quadrilaterals - projections of real world squares, which, as we know, have same size, lying on the same plane, with same rotat...

"Pyramidizing" an array/list (in Ruby, but general solutions could probably be implemented)

I'm not sure what the best word to use here. By "pyramidizing", I mean: [1,2,3,4].pyramidize # => [1,1,1,1,2,2,2,3,3,4] ["a","b","c","d"].pyramidize # => ["a","a","a","a","b","b","b","c","c","d"] To represent visually, it could be thought of as: [ 1,1,1,1, 2,2,2, 3,3, 4 ] Is there a way to do this that maximizes e...