algorithm

Angle between 3 vertices

For example, GetAngle((0,0),(100,0),(100,100)) = 90. How could I find the angle between 3 2D Points. ...

What is the mechanism/algorithm involved in functions that perform a fade of some sort?

What is the mechanism/algorithm involved in functions that perform a fade of some sort? What are some links or resources i can check out when it comes to this matter. ...

Senior Project Ideas About Maths and Algorithms

Hi, everybody.I am a senior student in CS.I have not much idea about what to do with my senior project.I think any idea will be very helpful to me.I'm very much interested in algorithms and the math behind them.Thanks for any project idea with this subject. ...

What's the best way to normalize scores for ranking things?

hi all, I'm curious how to do normalizing of numbers for a ranking algorithm let's say I want to rank a link based on importance and I have two columns to work with so a table would look like url | comments | views now I want to rank comments higher than views so I would first think to do comments*3 or something to weight it, howev...

All possible paths in a cyclic undirected graph

I'm trying to develop an algorithm that identifies all possible paths between two nodes in a graph, as in this example. in fact, i just need to know which nodes appear in all existing paths. in the web only got references about DFS, A* or dijkstra, but i think they doesn't work in this case. Does anyone know how to solve it? ...

Doubling a number - shift left vs. multiplication

What are the differences between int size = (int)((length * 200L) / 100L); // (1) and int size = length << 1; // (2) (length is int in both cases) I assume both code snippets want to double the length parameter. I'd be tempted to use (2) ... so are there any advantages for using (1)? I looked at the edge cases when overflow occ...

Do cryptographic hashes provide really unique results?

I was wondering whether md5, sha1 and anothers return unique values. For example, sha1() for test returns a94a8fe5ccb19ba61c4c0873d391e987982fbbd3, which is 40 characters long. So, sha1 for strings larger than 40 chars must be the same (of course it's scrambled, because the given input may contain whitespaces and special chars etc.). D...

question on array and number

i have one problem for example we have array int a[]=new int[]{a1,a2,a3,a4,..........an}: task is fill the same array by elements which are not in the array for example a={1,3,4,5,6,7} should be filled by any numbers {2,8,9,12,13,90}or others but not by elements which are in array this must not be{1,12,13,14,110} because 1 ...

question about saddle point

i have following problem assume that we have a 9*8 matrix A matrix is said to have a "saddle point " if some position is the smalles value in its row and the largest value in its column . IN symbols , a[i][j] is a saddle point if a[i][j]=min a[i][k] ==max a[k][k] 1<=k<=8 1<=k<=9 please help to find to co...

Special simple random number generator

How to create a function, which on every call generates a random integer number? This number must be most random as possible (according to uniform distribution). It is only allowed to use one static variable and at most 3 elementary steps, where each step consists of only one basic arithmetic operation of arity 1 or 2. Example: int myr...

in-place permutation of a array follows this rule

Suppose there is an array, we want to find everything in the odd index (index starting with 0), and move it to the end. Everything in the even index move it to the beginning. The relative order of all odd index items and all even index items are preserved. i.e. if the array is a1 b1 a2 b2 ... an bn after the operation it become...

Is it possible to split a sequence of numbers into two groups based in median value without sorting?

Is there an algorithm to split a sequence of random numbers into two groups based on a median value determined on the fly(without sorting them)? Ex. If I have the sequence 2-3-6-7-1-4-5, the result would be two separated groups: A) 1 2 3 B) 5 6 7 Median value: 4 ...

Position elements without overlap

I have a number of rectangular elements that I want to position in a 2D space. I calculate an ideal position for each element. Now my problem is that many elements overlap as very often the ideal positions are concentrated in one region. I want to avoid overlap as much as possible (doesn't have to be perfect, though). How can I do this? ...

Base X string encoding

I'm looking for a routine that will encode a string (stream of bytes) into an arbitrary base/alphabet (like base64 encoding but I get to choose the alphabet). I've seen a few routines that do base X encoding for a number, but not for a string. ...

Check if a string substitution rule will ever generate another string.

Not homework. Given two strings S and T of same length. Given a set of replacement rules, that find substring A in S and replace it with string B. A and B have the same length. Is there a sequence of rule application, such that it make string S into string T? Example: We have replacement rules cat->dog dog->cut we have string S1:aw...

Continuous vs Discrete artificial neural networks

I realize that this is probably a very niche question, but has anyone had experience with working with continuous neural networks? I'm specifically interested in what a continuous neural network may be useful for vs what you normally use discrete neural networks for. For clarity I will clear up what I mean by continuous neural network a...

How do I generate a random string of up to a certain length?

I would like to generate a random string (or a series of random strings, repetitions allowed) of length between 1 and n characters from some (finite) alphabet. Each string should be equally likely (in other words, the strings should be uniformly distributed). The uniformity requirement means that an algorithm like this doesn't work: al...

looking for a set union find algorithm

I have thousands of lines of 1 to 100 numbers, every line define a group of numbers and a relationship among them. I need to get the sets of related numbers. Little Example: If I have this 7 lines of data T1 T2 T3 T4 T5 T6 T1 T5 T4 T3 T4 T7 I need a not so slow algorithm to know that the sets here are: T1 T2 T6 (because T1 is relat...

What is an efficient way to find a non-colliding rectangle nearest to a location

For a 2D game I am working on, I am using y axis sorting in a simple rectangle-based collision detection. This is working fine, and now I want to find the nearest empty rectangle at a given location with a given size, efficiently. How can I do this? Is there an algorithm? I could think of a simple brute force grid test (with each grid t...

How to optimize this algorithm?

I have two sets of arrays like this for example. $Arr1['uid'][]='user 1'; $Arr1['weight'][]=1; $Arr1['uid'][]='user 2'; $Arr1['weight'][]=10; $Arr1['uid'][]='user 3'; $Arr1['weight'][]=5; $Arr2['uid'][]='user 1'; $Arr2['weight'][]=3; $Arr2['uid'][]='user 4'; $Arr2['weight'][]=20; $Arr2['uid'][]='user 5'; $Arr2['weight'][]=15; $Arr2['ui...