algorithm

Optimize algorithm for creating a list of items rated together, in Python.

given a list of purchase events (customer_id,item) 1-hammer 1-screwdriver 1-nails 2-hammer 2-nails 3-screws 3-screwdriver 4-nails 4-screws i'm trying to build a data structure that tells how many times an item was bought with another item. Not bought at the same time, but bought since I started saving data. the result would look like ...

recursive creation of an unlimited 7-gon

hey, i wondered if there's an algorithm to create a polygon, composed of triangles, to look like this: http://homepages.wmich.edu/~drichter/images/mathieu/numberedvertices.jpg the numbering of the vertices is not important, just the method how to get the points. notice that every point is connected to exactly 7 others. ...

Object to Object Property mapping in collections

Im creating a collection of (dynamically generated type) for display in a silverlight grid and one of the processes involves creating an import (dynamically generated type) type then mapping the properties on the import type to the collection of (dynamically generated type) both types share a Id property that identifies the item ( be it ...

how to implement a step-by-step button in c#?

I implemented an algorithm in c# and I want to make a gui for it, in my gui i want to put a button that with any click the gui shows a step forward in algorithm, so i think i need to put something like pause? statements in my code that with any click it can resume. how should i do that? or is there any other suggestion for implementing t...

Would there be any advantage in comparing pattern and text characters right-to-left instead of left-to-right?

Hi all, This is the exercise in "Introduction to The Design and Analysis of Algorithms". It's a string matching issue. Say I have string ABCD, and have a pattern XY. And want to see if the string contains the pattern. We just assume to use brute-force here, so the left-to-right comparison is comparing A with X, next is comparing B with...

Generating a random cubic graph with uniform probability (or less)

While this may look like homework, I assure you it's not. It stems from some homework assignment I did, though. Let's call an undirected graph without self-edges "cubic" if every vertex has degree exactly three. Given a positive integer N I'd like to generate a random cubic graph on N vertices. I'd like for it to have uniform probabilit...

Massively Parallel algorithm to propagate pixels

I'm designing a CUDA app to process some video. The algorithm I'm using calls for filling in blank pixels in a way that's not unlike Conway's game of life: if the pixels around another pixels are all filled and all of similar values, the specific pixel gets filled in with the surrounding value. This iterates until all the number of pixel...

Interesting graph traversal optimization problem

Suppose you have a set of nodes connected into a tree structure with one root node and any node may have any number of child nodes. You can only traverse the tree starting at the root node or from your current position along direct connections. I.e., no random access to a specific node, but the structure of the graph is already known an...

How to return the best first level in this F# minimax?

Hello folks, This question is more a semantic-algorithmic-data-structure question than a F# syntactically question. I have a Minimax algorithm. The minimax algorithm should return the best next move, from a start position. To do this, it calculus all next moves, then the next-next-moves until a determined depth or until there is no more...

how to solve the linear programming relaxed MKP

Hi guys, I am studying about Knapsack problem. So i do not understand one thing here. the profit/pseudo-resource consumption ratios Uj=Pj/Wj with Wj=Rji*Aj; I hope so you people know this equation thus i think no need more explanation. I wanted to calculate Aj here. What is that LP relaxation . How they are calculating using total capa...

Random Tile layout

I need to place tiles on a large grid radiating from a central point in a way that looks organic and random. New tiles will need to find an open space on the grid that is touching at least 1 other tile. Can anyone point me in the right to direction to anything that might help with this? Or some basic concepts I can read up on that are i...

Finding a submatrix with the maximum possible sum in O(n^2)

Hi, I'm trying to write a program in Java that when given an MxN matrix it will find the (contiguous) submatrix with the biggest sum of numbers. The program then needs to return the top left corner coordinates of the submatrix and the bottom right corner coordinates. The matrix can include negative numbers and both the matrix and submat...

Is this problem np-complete?

Say there is a line of x bins filled with trinkets (random amount), in plain-sight (you can see how many trinkets there are in each bin). Now there are two players who can when it's their turn pick a bin from either end. They cannot forgo a turn. Come up with a strategy for a player to get the maximum amount of trinkets. x is even. Is ...

Generate uint64_t hash key with several uint32_t integers

Hi everyone, I'm facing the same problem than Eduardo (http://stackoverflow.com/questions/539311/generate-a-hash-sum-for-several-integers) but mine is a little bit different as said in the title. I have four 32bits integers and I need to generate a 64bits unique key. What I have done for now is to generate a string concatenation of the ...

question about almost integer

there is given real number how find by programming if it is Almost integer? http://mathworld.wolfram.com/AlmostInteger.html thanks ...

Indexing count of buckets

So, here is my little problem. Let's say I have a list of buckets a0 ... an which respectively contain L <= c0 ... cn < H items. I can decide of the L and H limits. I could even update them dynamically, though I don't think it would help much. The order of the buckets matter. I can't go and swap them around. Now, I'd like to index the...

Generate all subset sums within a range faster than O((k+N) * 2^(N/2))?

Is there a way to generate all of the subset sums s1, s2, ..., sk that fall in a range [A,B] faster than O((k+N)*2N/2), where k is the number of sums there are in [A,B]? Note that k is only known after we have enumerated all subset sums within [A,B]. I'm currently using a modified Horowitz-Sahni algorithm. For example, I first call it t...

Balancing sets of values

So I'm working on a fun little program and ran across this rather interesting problem: I have several sets of values of pre-defined set sizes. These are all a unique subset of a larger pool of values. The averages of each subset of numbers should be as close to each other as reasonably possible. This does not need to be perfect, but shou...

Is this an ambiguous grammar? How should I resolve it?

To preface this, my knowledge of this kind of stuff is puny. Anyways, I've been developing a context-free grammar to describe the structure of alegbraic expressions so I can teach myself how the CYK parsing algorithm works. I understand how such a structure can work with only infix algebraic expressions, but I cannot understand how to d...

Problem with Quick Sort Algorithm

Hey all, I'm working on a quick sort algorithm in C#, but I'm facing a strange problem which is, among 10 times of executing the algorithm on random numbers, I got 2 or 3 wrong sorting answers. I mean: this code can sort about 7 out of 10 examples; why? I couldn't figure out what's the problem, can you help me? public void quicksor...