Suppose you have several functions y1 = f1(x), y2 = f2(x), etc. and you want to plot their graphs together on one plot.
Imagine now that for some reason it is easier to obtain the set of x for a given y; as in, there exists an oracle which given a y, will return all the x1, x2, etc. in increasing order for which y = f1(x1), y = f2(x2), e...
Let's say I have a graph with "heavy" nodes, that is each node is an object that is already carrying a lot of data. I want to do a graph transformation that requires me to calculate a special property for each node. This property only needs to be remembered temporarily to apply the transformation. How can I store this property efficie...
I'm working on an interactive job scheduling application. Given a set of resources with corresponding capacity/availabilty profiles, a set of jobs to be executed on these resources and a set of constraints that determine job sequence and earliest/latest start/end times for jobs I want to enable the user to manually move jobs around. Esse...
How do I quickly generate a random prime number, that is for sure 1024 bit long?
...
I currently have a system where the server tells all client applications when to next connect to the server between a server configured time window (say 12 to 6 am client time).
The current algorithm does a mod of the client's 10 digit ID number(fairly distributed) by the number of seconds in the time window and gives a pretty evenly d...
It is said that through LSI, the matrices that are produced U, A and V, they bring together documents which have synonyms. For e.g. if we search for "car", we also get documents which have "automobile". But LSI is nothing but manipulations of matrices. It only takes into account the frequency, not semantics. So whats the thing behind thi...
Assume a boolean array like:
1111
1111
1110
1111
1001
Now you need to find the way of arranging the least rectangles of any size to achieve this shape. So, for example, you'd find this:
+-++
| |+
| |
+-++
+ +
Where + is a corner of a rectangle and |, - borders of a rectangle.
What I thought about doing is starting with the larges...
Is there a generalized procedure or algorithm for transforming a SQL subquery into a join, or vice versa? That is, is there a set of typographic operations that can be applied to a syntactically correct SQL query statement containing a subquery that results in a functionally equivalent statement without a subquery? If so, what are they (...
Given a DAG, in which each node belongs to a category, how can this graph be transformed into a table with a column for each category? The transformation doesn't have to be reversible, but should preserve useful information about the structure of the graph; and should be a 'natural' transformation, in the sense that a person looking at t...
What's the easiest way to draw a hex grid algorithmically? How should I present them in data?
For example, in a square grid, I could just save x-y coordinates..
...
I have problem with circle-rectangle intersection.Though A number
of discussion i found about it ,i could not get my answer.My problem is -I have a rectangle lower portion(100-200,0-50) of my view/window(320 X 480).And a ball is moving here and there.And
sometimes it collides with the rectangle and bounce back.And my problem is how will...
Typical strlen() traverse from first character till it finds \0.
This requires you to traverse each and every character.
In algorithm sense, its O(N).
Is there any faster way to do this where input is vaguely defined.
Like: length would be less than 50, or length would be around 200 characters.
I thought of lookup blocks and all but d...
Hi,
I'm stuck with this little problem and my algorithm to solve this doesn't hold for all cases. Does anybody has an idea how to solve this?
Here's an example polygon:
Formal description
We have a list of points in CW order defining the polygon. We also can query whether a point is a cutting point with is_cut(p), where p is a giv...
Possible Duplicate:
are there any O(1/n) algorithms?
I've been reading up on various algorithms recently, and have gotten very used to seeing things with O([some combination of n, n^2 and log n). It seems pretty normal for algorithms to increase in running time with more input, so this doesn't really bother me, but are there man...
Hello All,
I'm currently finding the longest path in a directed acyclic positive-weighted graph by negating all edge weights and running Bellman Ford. This is working great. However, I'd like to print the trace of which nodes/edges were used. Any help? The program takes as input the number of nodes, a source, destination and edge weight...
I am given an array of real numbers, A. It has n+1 elements.
It is known that there are at least 2 elements of the array, x and y, such that:
abs(x-y) <= (max(A)-min(A))/n
I need to create an algorithm for finding the 2 items (if there are more, any couple is good) in O(n) time.
I've been trying for a few hours and I'm stuck, any c...
In Prolog, problems are solved using backtracking. It's a declarative paradigm rather than an imperative one (like in C, PHP or Python). In this kind of languages is it worth to think in terms of complexity?
The natural way you think problems seems to be O(N^2) as someone pointed in this question.
...
Question:
Given the following code snippet:
bool foo(int n) {
for(int i=3;i<sqrt(n)+0.5;i+=2)
{
if((n%i)==0){
return false;
}
}
return true;
}
Can you figure out what is the purpose of the function foo ?
Well,On first look it may seems that foo is checking for prime numbers but it is not...
Possible Duplicate:
Best algorithm to count the number of set bits in a 32-bit integer?
Given a 32-bit integer N,Devise an algorithm to find the number of zeros in the binary bit representation of N.
The simplest algorithm I can think of is to check the binary representation for Zeros,in C something like this:
int num_of_zero(...
I was looking for something over the web when I came across this question. Have no idea of how to solve it. Help me out please.
Suppose we have an array
a1,a2,... ,an, b1,b2,..., bn
How to change this array to
a1,b1,a2,b2, ..., an,bn in O(n) time and in O(1) space.
...