algorithm

Sphere - sphere collision detection -> reaction

Hi guys, I need to make an algorithm that detects when two spheres collide, and, the direction that wich one will take an instant after the collision. Let say, Imagine like when you open your table in a pool match, all the balls are colliding one to another "randomly". So, before starting to write the code myself, I was thinking if th...

Algorithm to build syntax tree from prefix order expression

What type of algorithm would be used to construct a syntax tree from an expression represented in prefix order notation? ...

Elegant/Clean (special case) Straight-line Grid Traversal Algorithm?

I'm dusting off an old project of mine. One of the things it had to do was -- given a Cartesian grid system, and two squares on the grid, find a list of all squares that a line joining the center of those two squares would pass through. The special case here is that all start and end points are confined to the exact center of squares/c...

Calculating Area Between Sprites

I am working on a simple 2D soccer game, while passing the ball between my players I would like to check if any of the enemy players can intercept the ball, what I would like to do is calculate a list of coordinates between my players a corridor so to speak and then check if any enemy players are in this region, -----------------------...

Maximize the number of lines that end in a certain character

You are given a line of strings, each words are seperated by spaces. You can only insert new lines in the 5-10th column of your string. Your goal is to maximize the number of lines that end with the character x. How would you do this for example. Edit: The words can end with any character, Say you are given the text abcdfg cdx abcdx a...

Algorithm to find minimum number of weightings required to find defective ball from a set of n balls

Okay here is a puzzle I come across a lot of times- Given a set of 12 balls , one of which is defective (it weighs either less or more) . You are allow to weigh 3 times to find the defective and also tell which weighs less or more. The solution to this problem exists, but I want to know whether we can algorithmically determine if given ...

calendar scheduler algorithm

I'm looking for an algorithm that, given a set of items containing a start time, end time, type, and id, it will return a set of all sets of items that fit together (no overlapping times and all types are represented in the set). S = [("8:00AM", "9:00AM", "Breakfast With Mindy", 234), ("11:40AM", "12:40PM", "Go to Gym", 219), ...

fastest search algorithm

hello I'm trying to implement an algorithm to search multiple XML files for a certain record. known that the records are not sorted ( i don't have an indexed id) . what is the fastest algorithm to search for that record ?. please let me know if anything was unclear thanks in advance ...

What is the best sort algorithm for a random set of floats?

A colleague of mine just put that question out in the air this afternoon, and somewhat left me curious. I'm versed with sorting algos, but lacking a formal degree in compsci / compeng (something I'm sorta averse to admitting), can't really place my finger on this one. :p And oh yeah, this is mildly in the context of a C#/.NET implementa...

Fast undo facility for bitmap editor application

I'm trying to make a bitmap editor app for the iphone which would be similar to Brushes or Layers or a cut-down version of Photoshop. I'd like to be able to support 1000x1000 resolution images with about 4 layers if possible. I'm trying to design my undo/redo system before I write too much code and I'm having real issues coming up with ...

How to calculate indefinite integral programmatically

I remember solving a lot of indefinite integration problems. There are certain standard methods of solving them, but nevertheless there are problems which take a combination of approaches to arrive at a solution. But how can we achieve the solution programatically. For instance look at the online integrator app of Mathematica. So how do...

Generating random points within a hexagon for procedural game content

I'm using procedural techniques to generate graphics for a game I am writing. To generate some woods I would like to scatter trees randomly within a regular hexagonal area centred at <0,0>. What is the best way to generate these points in a uniform way? ...

question about common 1 bit

i have question suppose there is gven two number we should find how many common 1 bit is in these number for example 5 and 6 5//101 6//110 there is 1 common bit at the same position i have following code #include <iostream> using namespace std; int main(){ int a,b; int count=0; cin>>a>>b; while ((a & b)!=0){ ...

Philosophers Synchronization Algorithm

I was reading new materials ahead I came to know the term "Philosophers Synchronization Algorithm", but I could not understand it. Can anyone help me understand it what is it? Thanks ...

Generating uniformly random curious binary trees.

A binary tree of N nodes is 'curious' if it is a binary tree whose node values are 1, 2, ..,N and which satisfy the property that Each internal node of the tree has exactly one descendant which is greater than it. Every number in 1,2, ..., N appears in the tree exactly once. Example of a curious binary tree 4 / \ 5 2 / \ ...

Algorithm to locate local maxima

I have data that always looks something like this: I need an algorithm to locate the three peaks. The x-axis is actually a camera position and the y-axis is a measure of image focus/contrast at that position. There are features at three different distances that can be in focus and I need to determine the x-values for these three poi...

Selecting an optimum set according to ranked criteria

I am given a string, and a set of rules which select valid substrings by a process which isn't important here. Given an enumeration of all valid substrings, I have to find the optimum set of substrings according to a set of ranked criteria, such as: Substrings may not overlap All characters must be part of a substring if possible Use a...

Algorithm to find the maximum sum in a sequence of overlapping intervals

The problem I am trying to solve has a list of intervals on the number line, each with a pre-defined score. I need to return the maximum possible total score. The catch is that the intervals overlap, and of the overlapping intervals I can use only one. Here is an example. Intervals - Score 0- 5 - 15 4- 9 - 18 ...

Intersecting rectangles

This is an analytical geometry kind of question.I am not sure I can post it here.However I have to come up with a Java function to do this functionality.I have multiple rectangles in a page/swing container.I know the bounds of the rectangles.Now I need to find which rectangles are intersecting each other.One good thing here intersecting ...

Induction Proof in Algorithms

Assume an arbitrary r T(n) <= cn + T(n/r) + T (3n/4) show T(n) <= Dcn for some constant D by reworking the induction proof, use the expression to argue that: T(n) <= Dcn does not hold for r=3. ...