algorithm

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, it appears to work quite well. I knew beforehand that the framework provides a built-in Quicksort implementation in List<>.Sort (via Array....

What are some good resources on flocking and swarm algorithms?

Awhile ago I read the novel Prey. Even though it is definitely in the realm of fun science fiction, it piqued my interest in swarm/flock AI. I've been seeing some examples of these demos recently on reddit such as the Nvidia plane flocking video and Chris Benjaminsen's flocking sandbox (source). I'm interested in writing some simulati...

Fastest Algorithm to scale down 32Bit RGB IMAGE.

which algorithm to use to scale down 32Bit RGB IMAGE to custom resolution? Algorithm should average pixels. for example If I have 100x100 image and I want new Image of size 20x50. Avg of first five pixels of first source row will give first pixel of dest, And avg of first two pixels of first source column will give first dest column pi...

I need an alternative to the first fit decreasing bin packing algorithm that always finds an optimal solution

I have implemented the First-Fit-Decreasing bin packing algorithm to split a list of numbers into two 'bins' of equal size. The algorithm almost always finds the optimal packing arrangement but occasionally it doesn't. For example: The set of numbers 4, 3, 2, 4, 3, 2 can obviously be split into this arrangement: 1) 4, 3, 2 2) 4, 3, 2 ...

Grokking Timsort

There's a (relatively) new sort on the block called Timsort. It's been used as Python's list.sort, and is now going to be the new Array.sort in Java 7). There's some documentation and a tiny Wikipedia article describing the high-level properties of the sort and some low-level performance evaluations, but I was curious if anybody can pro...

Finding the spin of a sphere given X, Y, and Z vectors relative to sphere

I'm using Electro in Lua for some 3D simulations, and I'm running in to something of a mathematical/algorithmic/physics snag. I'm trying to figure out how I would find the "spin" of a sphere of a sphere that is spinning on some axis. By "spin" I mean a vector along the axis that the sphere is spinning on with a magnitude relative to the...

Where can I get C/C++ sample code for merge sort a link list?

Where can I get a sample code for merge sort a link list? ...

What is the best way to sort link list?

What is the best algorithm to sort a link list [in C/C++]? ...

What is Knowledge Discovery and Data Mining?

I suppose SQL queries fetch "raw data"... Is there any good point to start regarding data mining in SQL server? Are there any available KDD ready-to-go, algorithms in MS-SQL server 2005, 2008? ...

How to add/merge several Big O's into one

If I have an algorithm which is comprised of (let's say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do I theoretically estimate the O() for the entire algorithm? I.e. not clocking it or performing any other practical measurement. Is there...

What is the complexity of inserting into sorted link list in big-O notation?

What is the complexity of inserting into sorted link list in big-O notation? Let say I have 5 elements and what is the complexity to insert all of them. Thank you very much ...

Dijkstra's Bankers Algorithm

Could somebody please provide a step-through approach to solving the following problem using the Banker's Algorithm? How do I determine whether a "safe-state" exists? What is meant when a process can "run to completion"? In this example, I have four processes and 10 instances of the same resource. Resources Allocated | Resour...

Running a fastest-algorithm competition

I'd like to run competitions like code golf competitions, but the winner would have the fastest algorithm, not the smallest code. One fair way to measure speed of an algorithm is to use a neutral virtual machine, like Java's JVM. Is there an easy way to know the total number of JVM instructions executed? (If the entry uses multiple t...

Any great books of algorithm puzzles to practice whiteboard coding with?

I'm looking to get some practice coding solutions to algorithm puzzles on a whiteboard. A friend is going to read puzzles to me (as if he were interviewing me), and I'll solve them on a whiteboard. Does anyone know any great books with algorithm puzzles that would be useful for this? I found a book called Puzzles for Programmers and Pro...

computer algebra soft to minimize the number of operations in a set of polynomials

hello I have systems of polynomials, fairly simple polynomial expressions but rather long to optimize my hand. Expressions are grouped in sets, and in a given set there are common terms in several variables. I would like to know if there is a computer algebra system, such as Mathematica, Matlab, or sympy, which can optimize multiple p...

How do I find the nth ancestor of a node in a binary search tree?

I got asked this at a job interview. Here's my O(log n) solution. Find the depth of the node. Repeat the search, but stop at depth - n. Is there a way to do this without the second pass? ...

Longest circle in graphs

Hi folks, I want to solve the following problem: I have a DAG which contains cities and jobs between them that needs to be done. The jobs are for trucks which can load a definied limit. The more the truck is loaded the better is the tour. Some jobs are for loading something in and some are for loading defined things out. You can always...

Fixed point inverse sine

Does anyone know a (preferably fast) way to calculate the sine of an angle in 4.12 fixed point? (where the result is either 32768ths of a circle or degrees) 4.12 fixed point means the number is 16 bits and is left shifted 12, so 1.0 becomes (1 << 12) or 4096. 0.5 is (0.5 << 12) == 2048, etc. ...

Starting with an empty tree, what is the complexity of inserting into Red Black Tree in big-O notation?

If I have 10 elements and starting with an empty tree, What is the complexity of inserting 10 elements into Red Black in big-O notation? Is it going to be more than O(log 10) because each time it inserts an element, it has to search for appropriate location for the element and performs a series of rotations between ancestor nodes and c...

circle-circle collision

I am going to develop a 2-d ball game where two balls (circles) collide. Now I have the problem with determining the colliding point (in fact, determining whether they are colliding in x-axis/y-axis). I have an idea that when the difference between the y coordinate of 2 balls is greater than the x coordinate difference then they collid...