algorithm

Is storing Image File in database good in desktop application running in network?

hi, I recently came across a problem for image file storage in network. I have developed a desktop application. It runs in network. It has central database system. Users log in from their own computer in the network and do their job. Till now the database actions are going fine no problem. Users shares data from same database server. ...

generate unique 5 digit number

i was told to write program which generate unique 5 digit number ( for example 12345 is unique and 11234 not) i have write following code #include <iostream> #include <stdlib.h> #include <map> using namespace std; using std::rand; const int k=99999-10234; bool unique(int t){ map<int,int>my; map<int,int>::iterator it; ...

Draw a point a set distance away from a base point

Hey, I'm trying to figure out an algorithm for finding a random point a set distance away from a base point. So for example: This could just be basic maths and my brain not working yet (forgive me, haven't had my coffee yet :) ), but I've been trying to work this out on paper and I'm not getting anywhere. Thanks, Niall. ...

Modulo of negative numbers

Possible Duplicate: Mod of negative number is melting my brain! I was wondering if there was a nicer algorithm for what I'm trying to do: wrapIndex(-6, 3) = 0 wrapIndex(-5, 3) = 1 wrapIndex(-4, 3) = 2 wrapIndex(-3, 3) = 0 wrapIndex(-2, 3) = 1 wrapIndex(-1, 3) = 2 wrapIndex(0, 3) = 0 wrapIndex(1, 3) = 1 wrapIndex(2, 3) = 2 w...

Compress 21 Alphanumeric Characters in to 16 Bytes

I'm trying to take 21 bytes of data which uniquely identifies a trade and store it in a 16 byte char array. I'm having trouble coming up with the right algorithm for this. The trade ID which I'm trying to compress consists of 2 fields: 18 alphanumeric characters consisting of the ASCII characters 0x20 to 0x7E, Inclusive. (32-126) A ...

How to assign "levels" to vertices of an acyclic directed graph?

I have an acyclic directed graph. I would like to assign levels to each vertex in a manner that guarantees that if the edge (v1,v2) is in the graph, then level(v1) > level(v2). I would also like it if level(v1) = level(v3) whenever (v1,v2) and (v3,v2) are in the graph. Also, the possible levels are discrete (might as well take them to...

Algorithm to find which number in a list sum up to a certain number.

I have a list of numbers. I also have a certain sum. The sum is made from a few numbers from my list (I may/may not know how many numbers it's made from). Is there a fast algorithm to get a list of possible numbers? Written in Python would be great, but pseudo-code's good too. (I can't yet read anything other than Python :P ) Example l...

Prim's MST algorithm in O(|V|^2)

Time complexity of Prim's MST algorithm is O(|V|^2) if you use adjacency matrix representation. I am trying to implement Prim's algorithm using adjacency matrix. I am using this as a reference. V = {1,2...,n} U = {1} T = NULL while V != U: /* Now this implementation means that I find lowest cost edge in O(n)....

Algorithm of JavaScript "sort()" Function

Recently when I was working with JavaScript "sort()" function, I found in one of the tutorials that this function does not sort the numbers properly. Instead to sort numbers, a function must be added that compares numbers, like the following code:- <script type="text/javascript"> function sortNumber(a,b) { return a - b; } var n = [...

Algorithm to find the closest segment to a point among many segments (Reverse Geocoding)

Hey guys!! I have a set of segments defined by two points. Given a point how can I discover the closest segment to such point? I have already written an algorithm that computes the distance between a point and a segment. Anyway calculating such distance for each segment and then choose the segment with the lowest distance is not really...

compressed vector/array class with random data access.

I would like to make "compressed array"/"compressed vector" class (details below), that allows random data access with more or less constant time. "more or less constant time" means that although element access time isn't constant, it shouldn't keep increasing when I get closer to certain point of the array. I.e. container shouldn't do ...

Help with this problem?

I'm trying to figure out how to do this. Essentially I have points A and B which I know the location of. I then have point C and point D which I only know the coordinates of C. I know the length of C-D and know that C-D must be parallel to A-B. How could I generally solve for D given A,B,C and length of C-D. Thanks ...

PHP algorithm for CDN distribution

IGNORE THE QUESTION: The CSS File I was including pulled in the the other files hence the correlation *facepalm* We have the following code for picking a CNAME CDN reference per filename. It must return the same URL everytime based on a given filename. We thought this would be sufficiently random: <?php function cdn_prefix($fileN...

Storing elements in the list, in the ascending order

Goal is, I've multiple lists of elements available, and I want to be able to store all of these elements into a resultant list in an ordered way. Some of the ideas that comes to my mind are a) Keep the result as a set (std::set), but the B-tree , needs to rebalanced every now and then. b) Store all the elements in a list and sort the li...

Day Change Update Problem

C# - Winforms - SQL Server i am building an application which displays some data on the screen of the current day which it gets from the database... the application is like a desktop widget so the data is always visible on the desktop the scheme i implemented is when user commits some change to the data, after the update query i ...

How to detect points which are drastically different than their neighbours

Hey I'm doing some image processing, and am trying to keep track of points similar to those circled below, a very dark spot of a couple of pixels diameter, with all neighbouring pixels being bright. I'm sure there are algorithms and methods which are designed for this, but I just don't know what they are. I don't think edge detection wo...

Performance of extra string comparisons vs HashMap lookups

Assume I am running either of the code snippets below for a list of 1000 Event entries (in allEventsToAggregate). Would I see a performance improvement in the first implementation if the events in allEventsToAggregate are sorted by customerId, with each customer having roughly 3 events? This is essentially a question of string comparison...

How to calculate the max. number of combinations possible?

Possible Duplicates: Display possible combinations of string algorithm that will take numbers or words and find all possible combinations If I have 3 strings, such as: "abc def xyz" And I want to find the max number of combinations I can generate by rearranging these strings, e.g: abc xyz def def xyz abc xyz abc def e...

How to write Image Mosaic Generator

Task is following: how to create selected picture mosaic from large number of images. My first shot would be using evolutionary algorithm. Where genotype represents mapping of original images to positions in mosaic grid, and individual is evaluated according to similarity to original picture. Actually in basic approach each tile can be t...

All possible combinations of a list of a list

Hi I am in desperate need for some algorithm help when combining lists inside lists. Assuming that I have the following data structure: fields = [ ['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3'], ['d1', 'd2', 'd3'] ] I am trying to write a generator (Python) that will yield each possi...