algorithm

storing links of a site in a tree

I am trying to store the links that I scrape from a site in a non binary tree. The links are laid out hierarchically (obviously). The question is how do I generate the tree ? I mean, how am I going to work my way through the pages provided by the link so that I know who is who's child. For now I can get the first and the second level of...

Is there a name for this sort?

What is the name for the sort used in this answer? I Googled for "perfect insertion sort" but didn't find anything. Here is the code from that answer: #this is O(n) instead of O(n log n) or worse sub perfect_insert_sort { my $h = shift; my @k; for my $k (keys %$h) { $k[$h->{$k}{order}] = $k; } return @k; } ...

Interruptible in-place sorting algorithm

I need to write a sorting program in C and it would be nice if the file could be sorted in place to save disk space. The data is valuable, so I need to ensure that if the process is interrupted (ctrl-c) the file is not corrupted. I can guarantee the power cord on the machine will not be yanked. Extra details: file is ~40GB, records are...

efficient longest common subsequence algorithm library?

I'm looking for a (space) efficient implementation of an LCS algorithm for use in a C++ program. Inputs are two random access sequences of integers. I'm currently using the dynamic programming approach from the wikipedia page about LCS. However, that has O(mn) behaviour in memory and time and dies on me with out of memory errors for larg...

Good algorithms to determine whether one number is prime?

Possible Duplicate: Checking if an int is prime more efficiently I need to test some very large integer to see whether it is a prime. Could you provide some good algorithms or library routines? EDIT: C/C++ would be OK. Thanks. ...

Can we compute this in less than O(n*n) ...( nlogn or n)...

This is a question asked to me by a very very famous MNC. The question is as follows ... Input an 2D N*N array of 0's and 1's. If A(i,j) = 1, then all the values corresponding to the ith row and the jth column are going to be 1. If there is a 1 already, it remains as a 1. As an example , if we have the array 1 0 0 0 0 0 1 1 0 0...

Recommendation on big integer calculation library.

Could your recommend some good big integer calculation library in C/C++/Java and it is better to support logarithmetic. Thanks. ...

Priority of learning programming craft and other suggestions

Hello, As I am in my starting career year in software development (C++ & C#) I now see my flaws and what I miss in this sphere. Because of that I came into some conclusions and made myself a plan to fill those gaps and increase my knowledge in software development. But the question I stumbled upon after making a tasks which I need to do...

Matlab partition problem

Hi there, My head gets stucked finding an algorithm for my problem. Assume I have N Numbers (lets say 4) and I want have ALL X-Partitions (X = N/2) Example: 2-Partitions of {1,2,3,4} are: (1,2) (1,3) (1,4) (2,3) (2,4) (3,4) [Simply: all combinations] I don't have a clue how to generate these combinations. If someone of you have an i...

Problem coming up with an array function

Let's say I have an increasing sequence of integers: seq = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4 ... ] not guaranteed to have exactly the same number of each integer but guaranteed to be increasing by 1. Is there a function F that can operate on this sequence whereby F(seq, x) would give me all 1's when an integer in the sequence equals x an...

Competition scoring/ranking algorithm

The gist I'm implementing a website that hosts fitness competitions, and I need a good way to generate a "score" or "rank". How the competitions work Competitions consist of a team of one or more athletes/contestants from a given gym challenging the same number of contestants from one or more other gyms. There isn't any limit to the n...

Optimizing SphereInFrustrum check

I have this SphereInFrustrum function here: 0.49% int FrustumG::sphereInFrustum(Vec3 &p, float radius) { int result = INSIDE; float distance; 2.40% for(int i=0; i < 6; i++) { 7.94% distance = pl[i].distance(p); 12.21% if (distance < -radius) 0.67% return OUTSIDE; 3.67% else if (distance < ...

Picking ranges for splitting up a dataset

I have a few million integers between 0 and 64K. I'd like to split them up into N buckets, where each bucket contains about the same number of items from a contiguous range. So for example, if I only had a single datapoint with each possible value, and 64 buckets, ideally I'd end up with a bucket for 0-1024, one for 1025-2048, etc. ...

Help with this issue

Here is my issue. I'm rendering axis alligned cubes that are all the same size. I created an algorithm that rendered around the player like this: ****** ****** ***p** ****** ****** While this does work, the player does not see this whole radius. I know the player's rotation angle on the Y, so I was hoping to modify my algorithm based ...

Counting English words in a random string

Suppose I have a randomly generated string s=t&^%JHGgfdteam*&HGEdfg, what is the best approach to count the number of English words in that string? (English words as defined in some dictionary file). Obviously brute-force is not a good idea... would a suffix-tri e work? Binary search? Notice that in the case of s, there are two words: "t...

Arranging circuitry paths

Are there any recommended algorithms for placing circuitry? Restrictions: Only perfectly vertical/horizontal lines Can cross at right-angles, but can't run over one another in parallel. Input: A set of input points with output points defined. These points have a radius in which no other circuit wire can pass, except for the one going ...

C program to merge files not finding EOF, stuck in infinite loop!

I'm having some problems trying to run this program I am working on...The requirements say I was not allowed to use a sort function...I had do something myself....etc. Pretty much, the program compiles but hangs after executed...I'm guessing it's stuck in an infinite loop...but I can't seem to find it... :( This program reads to data f...

Book to learn advance concepts in Data Structures and Algorithms

Can any one suggest a book on data structures and algorithms that a programmer needs to cover. ...

How to uniqufy the tuple element?

i have a result tuple of dictionaries. result = ({'name': 'xxx', 'score': 120L }, {'name': 'xxx', 'score': 100L}, {'name': 'yyy', 'score': 10L}) I want to uniqify it. After uniqify operation result = ({'name': 'xxx', 'score': 120L }, {'name': 'yyy', 'score': 10L}) The result contain only one dictionary of each name and the dict shoul...

iphone: how can i synchronize the contents of 2 NSMutableArrays?

I currently have an NSMutableArray which stores a collection of Video objects. Each Video object has an ID and TITLE. I also have another NSMutableArray of video objects generated from parsing an XML API call. When the user hits a 'synchronize' button, I want the system to be able to figure out the minimum number of operations needed ...