algorithm

Function derivatives

I have some function, int somefunction( //parameters here, let's say int x) { return something Let's say x*x+2*x+3 or does not matter } How do I find the derivative of this function? If I have int f(int x) { return sin(x); } after derivative it must return cos(x). ...

parallel sorting methods

in book algorithm in c++ by robert sedgewick there is such kind of problem how many parallel steps would be required to sort n records that are distributed on some k disks(let say k=1000 or any value ) and using some m processors the same m can be 100 or arbitrary number i have questions what we should do in such ...

Is it possible to create thread-safe collections without locks?

This is pure just for interest question, any sort of questions are welcome. So is it possible to create thread-safe collections without any locks? By locks I mean any thread synchronization mechanisms, including Mutex, Semaphore, and even Interlocked, all of them. Is it possible at user level, without calling system functions? Ok, may b...

Space requirements of a merge-sort

I'm trying to understand the space requirements for a Mergesort, O(n). I see that time requirements are basically, amount of levels(logn) * merge(n) so that makes (n log n). Now, we are still allocating n per level, in 2 different arrays, left and right. I do understand that the key here is that when the recursive functions return the sp...

What would be a good general algorithm for approaching integer sequence problems?

Say the input will always be the same number N of numbers (e.g., 5) and assume the integers actually have a mathematical relation (no lengths of the numbers 'one', 'two', days in the nth month, etc.). The output would be either the next integer and the rule discovered or a message that no rule could be detected. I was thinking to have in...

Recursive breadth-first travel function in Java or C++?

Here is a java code for breadth-first travel: void breadthFirstNonRecursive(){ Queue<Node> queue = new java.util.LinkedList<Node>(); queue.offer(root); while(!queue.isEmpty()){ Node node = queue.poll(); visit(node); if (node.left != null) queue.offer(node.left); if (node.right != n...

Most elegant way to expand card hand suits

I'm storing 4-card hands in a way to treat hands with different suits the same, e.g.: 9h 8h 7c 6c is the same as 9d 8d 7h 6h since you can replace one suit with another and have the same thing. It's easy to turn these into a unique representation using wildcards for suits. THe previous would become: 9A 8A 7B 6B My question is - ...

collision detection of cannon balls with wall and target

I am seeking a good algorithm detecting if a moving ball is touching either a static wall or a static target. A classic Firing game logic. Anyone seen a good algorithm other than just loop them all? EDIT: i have no idea which is the best solution, BSP tree or grid based calculation, but my implementation will be on javascript and contr...

how to develop a program to minimize errors in human transcription of hand written surveys

I need to develop custom software to do surveys. Questions may be of multiple choice, or free text in a very few cases. I was asked to design a subsystem to check if there is any error in the manual data entry for the multiple choices part. We're trying to speed up the user data entry process and to minimize human input differences bet...

An algorithm for sorting & grouping a list of weighted objects

I have a number of chunks of data. For arguments sake we'll say they are File 1 - 150Kb File 2 - 50Kb File 3 - 70Kb File 4 - 60Kb File 5 - 70Kb File 6 - 100Kb File 7 - 90Kb For transmission, I can package these up into a max payload of 300Kb. If you just iterate through them in order you'd get TRANS1: 150Kb + 50Kb + 70Kb = 270...

Which clustering method is suitable for which kind of data?

I would like to know K-means is best suited for clustering of which type of data? When k-means fails? for which type of data set k-means does not give accurate answer? COBWEB is best suited for clustering of which type of data? When COBWEB fails? for which type of data set COBWEB does not give accurate answer? ...

Given a vector of maximum 10 000 natural and distinct numbers, find 4 numbers(a, b, c, d) such that a + b + c = d.

Hi, I solved this problem by following a straightforward but not optimal algorithm. I sorted the vector in descending order and after that substracted numbers from max to min to see if I get a + b + c = d. Notice that I haven't used anywhere the fact that elements are natural, distinct and 10 000 at most. I suppose these details are the...

question about triangle

i have following dynamic problem we should have construct following triangle 1 2 3 4 6 9 8 12 18 27 16 24 36 54 81 32 48 72 108 162 243 64 96 144 216 324 486 729 please can anybody help me to write algorithm for solve this problem? ...

Map generation algorithms

Hi, I am currently working on a game in C# Xna, which works with (X,Y,Z) coordinates. Each unit, contains some information about what is placed at that position, etc dirt, rock or nothing. But I am pretty new into 3D game development, and I need some ideas for 3D map generation algorithms. I thought of interpolation or perlin noise, but...

Practical rules for premature optimization

It seems that the phrase "Premature Optimization" is the buzz-word of the day. For some reason, iphone programmers in particular seem to think of avoiding premature optimization as a pro-active goal, rather than the natural result of simply avoiding distraction. The problem is, the term is beginning to be applied more and more to cases...

Alternative to a large database

Hi, I am having a database with tables having billions of rows in a single table for a month and I am having data for the past 5 years. I tried to optimize the data in all possible ways, but the latency is not decreasing. I know there are some solutions like using horizantal shrading and vertical shrading. But I am not sure about any op...

online lobby system - games list

Hi! Been reading a bit about the subject, and out of curiosity, online games which maintain a "lobby" system that lists games; How do they keep each client synchronized with the current games list state? I'm talking in a "client asks for the games list update" terms and not in event driven terms (game's state changes and immediately br...

I am looking for a radio advertising scheduling algorithm / example / experience

Hi Everyone, Tried doing a bit of research on the following with no luck. Thought I'd ask here in case someone has come across it before. I help a volunteer-run radio station with their technology needs. One of the main things that have come up is they would like to schedule their advertising programmatically. There are a lot of nea...

Algorithm for neatly printing a paragraph on a printer

First of all, this is not homework, so please don't tag it as homewrok I did not understand this problem. Can anybody explain it to me? It is not the english that I do not understand, but rather the general gist of the problem. ...

select k th mimimum from array a[0..n-1]

i have done folloing code from progrmming pearls here is code import java.util.*; public class select { public static int select1(int x[],int l,int u,int k){ //pre l<=k<=u //post x[l..k-1]<=x[k]<=x[k+1..u] Random r=new Random(); int t=r.nextInt(u-1-l)+l; if (l>=u) return -1 ; swap(l,t); int s=x[l]; int ...