I have a process that generates values and that I observe. When the process terminates, I want to compute the median of those values.
If I had to compute the mean, I could just store the sum and the number of generated values and thus have O(1) memory requirement. How about the median? Is there a way to save on the obvious O(n) coming f...
Setup:
I have a boolean matrix e.g.
1 0
1 1
0 1
where rows are named m1, m2, m3 (as methods) and columns t1 and t2 (as tests).
Definition:
An explanation is a set of rows (methods) which in union have at least one "1" in any column (every test hast to be matched by at least one method).
in our example, the set of explanations ...
How does this work?
I know to use it you pass in:
start: string (e.g. "Item 1, Item 2, Item 3")
delim: delimiter string (e.g. ",")
tok: reference to a string which will hold the token
nextpos (optional): reference to a the position in the original string where the next token starts
sdelim (optional): pointer to a character which will ...
What's the fastest/cleanest way to find the bit offset of the first unset bit in an array of arbitrary length?
Assume the prototype for your function is something like this size_t first_unset_bit(char unsigned const *buf, size_t bit_count, size_t start_bit); and that it may be called several times in quick succession on the same buffer....
Hi:
Does anyone know any good data structure and algorithm for searching with multiple predicate.
eg. suppose I have a set of tcp header data (assuming no duplicate). If I were searching for an tcp header of the list by src ip, I could sort the set by src IP and do binary search.
What kind of data structure/algorithm should I use if I...
Recently, I found several web site have something like : "Recommended for You", for example youtube, or facebook, the web site can study my using behavior, and recommend some content for me... ...I would like to know how they analysis this information? Is there any Algorithm to do so? Thank you.
...
I have been hearing a lot about Project Euler so I thought I solve one of the problems in C#. The problem as stated on the website is as follows:
If we list all the natural numbers
below 10 that are multiples of 3 or 5,
we get 3, 5, 6 and 9. The sum of these
multiples is 23.
Find the sum of all the multiples of 3
or 5 be...
I know there's a worst-case O(n log n) algorithm for finding the convex hull of a complex polygon and a worst-case O(n) algorithm for finding the convex hull of a simple polygon. Is there a worst-case O(n) algorithm for finding the convex hull of a complex polygon?
A complex polygon is a polygon where the line segments may intersect. ...
Hi,
I have a collection of strings that I want to filter. They'll be in this pattern:
xxx_xxx_xxx_xxx
so always a sequence of letters or numbers separated by three underscores. The max length of each string will be 60 characters. I might have a few million of these in my collection.
What data structure could I use to efficiently do ...
Hi,
This article show that there is some regexp that is O(2^n) when backtracking.
The example is (x+x+)+y.
When attempt to match a string like xxxx...p it going to backtrack for a while before figure it out that it couldn't match.
Is there a way to detect such regexp?
thanks
...
This is a spin off of this StackOverflow question.
Assume that you have a fixed number k of storage locations, and space for two counters. You will receive n items in random order (all permutations of the n items are equally likely). After receiving each item you can either store it in one of the k locations (discarding one of the pre...
It is well-known how one gets from an NFA for a regular language to a minimal DFA. However, the DFA might have an exponentially larger number of states.
What I need is a way to reduce an NFA, giving again an NFA but with a smaller number of states. T.i. I don't need the result to be deterministic, but I'd like it to be as small as possi...
In the minmax algorithm,How to determine when your function reaches the end of the tree and break the recursive calls.
I have made a max function in which I am calling the min function. In the min function , what shud I do?? For max function, I am just returning the bestscore.
def maxAgent(gameState, depth):
if (gameState.isWin()...
I have the following function:
void CGlEngineFunctions::GetBezierOpposite( const POINTFLOAT &a,const POINTFLOAT ¢er, POINTFLOAT &b, float blength )
{
POINTFLOAT v;
v.x = a.x - center.x;
v.y = a.y - center.y;
float alength = GetDistance(a,center);
if(blength == 0)
{
blength = alength;
}
fl...
I have an undirected unweighted graph G = (V, E) and a randomly chosen subset S of its vertices. I want to check whether the vertices in S are mutually adjacent (i.e. form a complete subgraph/a clique).
I have the following algorithm (pseudo-code):
foreach vertex in S {
// Check that the vertex has enough edges
if (vertex.edges.cou...
I'm working on implementing bezier handles into my application. I have points and I need to figure out weather the current direction of the new point is clockwise or counter clockwise. This is because my bezier interpolation algorithm calculates the handles from right to left.
Therefore no matter what it interpolates:
P1 P1.righthandle ...
I have my own, very fast cos function:
float sine(float x)
{
const float B = 4/pi;
const float C = -4/(pi*pi);
float y = B * x + C * x * abs(x);
// const float Q = 0.775;
const float P = 0.225;
y = P * (y * abs(y) - y) + y; // Q * y + P * y * abs(y)
return y;
}
float cosine(float x)
{
return sine...
Hello,
I have an array of strings in C and an integer indicating how many strings are in the array.
char *strarray[MAX];
int strcount;
In this array, the highest index (where 10 is higher than 0) is the most recent item added and the lowest index is the most distant item added. The order of items within the array matters.
I need a...
I was given an English vocabulary assignment by my teacher.
Choose a random alphabet, say 'a'
Write a word from the alphabet, say
'apple' Take the last word 'e' Write a
word from e, say elephant Now from 't'
and so on.. No repetition allowed
Make a list of 500 words.
Mail the list to the teacher. :)
So Instead of doing it ...
Hi, This is just to work out a problem which looks pretty interesting. I tried to think over it, but couldn't find the way to solve this, in efficient time. May be my concepts are still building up... anyways the question is as follows..
Wanted to find out all possible permutation of a given string....... Also, share if there could be a...