I've been going through textbook Introduction to Algorithms, and it's pretty much one of the best I've read. However, I'm at the point where it's not a big challenge. It's definitely far above trivial, but there seems to be a difficulty gap (even though it's more advanced that most undergrad tailored texts) between it and books like Conc...
I know the STL has set_difference, but I need to just know if 2 sets are disjoint. I've profiled my code and this is slowing my app down quite a bit. Is there an easy way to see if 2 sets are disjoint, or do I need to just roll my own code?
EDIT: I also tried set_intersection but it took the same time...
...
I am creating a site similar to reddit and hacker news that has a database of links and votes. I am implementing hacker news' popularity algorithm and things are going pretty swimmingly until it comes to actually gathering up these links and displaying them. The algorithm is simple:
Y Combinator's Hacker News:
Popularity = (p - 1) / ...
Basically, I'm creating a puzzle where you can swap pieces. And I want to make sure that when swapping 2 elements, the selection is valid.
Since the puzzle is only 9 pieces (3x3), I am currently using the code:
function valid_selection(p1, p2) {
if (p1 == 1 && (p2 == 2 || p2 == 4)) return true;
if (p1 == 2 && (p2 == 1 || p2 == ...
I currently work with PHP and Ruby on Rails as a web developer. My question is why would I need to know algorithms and data structures? Do I need to learn C, C++ or Java first? What are the practical benefits of knowing algorithms and data structures? What are algorithms and data structures in layman’s terms? (As you can tell unfortunat...
How can I build an interference graph so I may use it in register allocation ? How do I determine live-ranges?
...
Hi all,
Recently I've been messing about with algorithms on images, partly for fun and partly to keep my programming skills sharp.
I've just implemented a 'nearest-neighbour' algorithm that picks n random pixels in an image, and then converts the colour of each other pixel in the image to the colour of its nearest neighbour in the set ...
Hi All,
Firstly apologies for the title, I don't know if it describes what I am trying to achieve but its the best I've got.
Basically I have an array describing the intensity over a 2D space. I want to then distribute this intensity to neighbors over a given set of iterations, i.e. Lets say I have the following array:
intensity = [ 0...
Like what digg does,when you submit a news,the title and summary is automatically retrieved,how to do it?
...
I have a list of 1 million digits. Every time the user submit an input, I would need to do a matching of the input with the list.
As such, the list would have the Write Once Read Many (WORM) characteristics?
What would be the best way to implement storage for this data?
I am thinking of several options:
A SQL Database but is it suit...
I have heard of this algorithm, but is this algorithm good to use it with Bayesian Belief networks? Hugin is based on it and I'm looking for a book / article on this algorithm.
...
I am looking for ideas on how to translate one range values to another in Python. I am working on hardware project and am reading data from a sensor that can return a range of values, I am then using that data to drive an actuator that requires a different range of values.
For example lets say that the sensor returns values in the range...
I have a list with objects of x type. Those objects have an attribute name.
I want to find if a string matchs any of those object names. If I would have a list with the object names I just would do if string in list, so I was wondering given the current situation if there is a way to do it without having to loop over the list.
...
Assume I have the following information in a flat format, for example a list of objects:
List<Line> lines = new List<Line>
{
new Line{Id = 1, Level = 0},
new Line{Id = 2, Level = 1},
new...
I am trying to implement the GJK-algorithm but I got stuck instantly.
The problem is to implement the Support-function that isn't O(n^2).
As it is now I'm computing the complete Minkowski difference, and then there is really no point in doing the GJK-algorithm. (or is it?)
What I mean by Support-function is the function that returns t...
I am trying to solve a problem which I have reduced down to counting the number of integer solutions to a number of linear inequalities. I need to be able to count the number of solutions for any number of variables c_1, ..., c_n, but for n=3 the equations could be written as:
Now, I know the values of n and r in advance and wish to f...
Suppose you have an NxN grid, and you want to visit every cell exactly once, and in a pseudorandom order. The order doesn't have to be very random, but it does have to be seedable so that a different permutation of the grid cell ordering is possible. Is there a way to do this without simply generating a list of all cell coordinates, rand...
I have been doing a little recreational holiday computing. My mini-project was a simulation of the Italian game of "tomboli". A key building block was a simulation of the following process;
The game is controlled by a man with a bag of 90 marbles, numbered 1 to 90. He draws marbles one by one randomly from the bag, each time calling out...
I have a 3D space (x, y, z) with an additional parameter at each point (energy), giving 4 dimensions of data in total.
I would like to find a set of x, y, z points which correspond to an iso-energy surface found by interpolating between the known points.
The spacial mesh has constant spacing and surrounds the iso-energy surface entirel...
Given a function R which produces true random 32 bit numbers, I would like a function that returns random integers in the range 0 to n, where n is arbitrary (less than 2^32).
The function must produce all values 0 to n with equal probability.
I would like a function that executes in constant time with no if statements or loops, so som...