algorithm

Sorting a text file with over 100,000,000 records

Hi I have a 5gig text file that needs to be sorted in alphabetical order What is the best algorithm to use? constraints: Speed - As fast as possible Memory - A Pc with 1 Gig Ram running windows XP ...

Sorting an array with minimal number of comparisons

I need some help with my CS homework. I need to write a sorting routine that sorts an array of length 5 using 7 comparisons in the worst case (I've proven that 7 will be needed, because of the height of the decision tree). I considered using the decision tree 'hard-coded', but that means the algorithm is really complicated and was hinte...

Fitting a gauss curve to a certain histogram peak in c++

I have two questions concerning fitting a gauss curve to histogram peaks. My first question is a very basic one: How can I fit a gauss curve to a entire histogram? Does this only mean that I have to find out and calculate the mean value(µ) and the deviation(ϭ) of the histogram and put them into the formula for the Gauss curve? Would ...

Higher-order unification

I'm working on a higher-order theorem prover, of which unification seems to be the most difficult subproblem. If Huet's algorithm is still considered state-of-the-art, does anyone have any links to explanations of it that are written to be understood by a programmer rather than a mathematician? Or even any examples of where it works an...

Extract key sentences from a text

Hi, do you know about an effective method for extracting key sentences from a text with their frequency parameters, etc and that can also do "stemming" (search also for similar sentences) ? I wonder also if there is some software implementation Thanks a lot ...

C# algorithm - find least number of objects necessary

Let's say I have the following code. var numberToGetTo = 60; var list = new[] {10, 20, 30, 40, 50}; I want to be able to return 50 & 10 from list to = 60. If the numberToGetTo was 100 I would want to return 50, 50. If the numberToGetTo was 85 I would want to return 50, 40. I want to return the least amount of numbers from the list...

How does the hashlife alg go on forever in Golly?

"In hashlife the field is typically treated as a theoretically infinite grid, with the pattern in question centered near the origin. A quadtree is used to represent the field. Given a square of 22k cells, 2k on a side, at the kth level of the tree, the hash table stores the 2k-1-by-2k-1 square of cells in the center, 2k-2 generations in ...

Need ideas for an algorithm that generates an "echo text" from a given input.

After having some fun in a chatbox on a certain website I had an interesting idea. What would be an algorithm that, given some input text, would generate an "echo" text from it. That is, it generates the echo that you would hear if you shouted the input text in a large empty cave. For example: Input text: Hello! Output text: Hello! ...

C# algorithm - listing all permutations of number

This is sort of a follow up to a question I posted earlier (http://stackoverflow.com/questions/1940980/c-algorithm-find-least-number-of-objects-necessary), but a bit different. Given I have the following code: var max = 80; var list = new[]{10,20,30,40,50, 60); I want to generate a array containing all the possible combinations I can...

convert digital display format

quick question, I have some integrate variable in javascript, say: 123456, or 123456789, it can be any valid number. Now, I would like to convert the number to a string like "123,456" or "123,456,789". Does anyone have a good algorithm for this? Of course, it should work for any numbers. For example: for 2000 ---> 2,000; 123456--->123,45...

How to find 2-approximate solution for maximum acyclic subgraph of an oriented graph?

How can I find 2-approximate solution for a problem of determining a maximum subgraph with no cycles of an oriented graph? Subgraph is "maximum" if it contains the maximal number of edges amongst other graphs that bear the same property. 2-approximate means that we can build 2 times smaller graph than the optimal one. That's quite a b...

Validate double value range and step

I'm trying to construct an algorithm that validates that a double value is a member of a range defined with min, max and step values. The problem is checking that the value obeys the step rule. For integers this can be easily done: boolean validate(int value, int min, int step, int max){ return value >= min && value ...

How to use Boost 1.41.0 graph layout algorithmes

Hi I have problem using boost graph layout algorithmes. boost verision 1_41_0 mingw g++ 4.4.0. So there are issues I have encountered Can you suggest me with them? The function fruchterman_reingold_force_directed_layout isn't compiled. The kamada_kawai_spring_layout compiled but program crashed. Boost documentation to layout algorith...

KD-Trees and missing values (vector comparison)

I have a system that stores vectors and allows a user to find the n most similar vectors to the user's query vector. That is, a user submits a vector (I call it a query vector) and my system spits out "here are the n most similar vectors." I generate the similar vectors using a KD-Tree and everything works well, but I want to do more. I ...

Arrange the numbers such that numbers in a block are unique

Given a string of numbers say "5556778", and a num N(say 2), rearrange the string such that numbers in any continuous block of size N are unique. e.g: for the above string and N=2, one rearrangement can be 5657578. For N=3: 5765785 find the arrangement in linear time. ...

Balls and Baskets Problem Algorithm?

Hello all, Let's say there are N people and all these people have 1 basket and unlimited balls. They can throw a ball to others' baskets. We let them throw their balls to others' baskets and we come up with a scenario like that : 'A' person's basket Balls from E, F, G, I, K, L, M, P 'B' person's basket Balls from A, C, E, F, K, T, R,...

Balls and Baskets Problem Ver2

In addition to original balls and baskets problem I mentioned here : http://stackoverflow.com/questions/1948311/balls-and-baskets-problem-algorithm There is a slightly different problem. Still there are N people and they have unlimited balls but they dont have baskets this time. Problem is : There are N people with unlimited balls an...

How to know calculate the execution time of an algorithm in c++?

Hi, I want to test which data structure is the best by looking at the run-time performance of my algorithm, how do I do it? For example I already have a hashmap<string, int> hmp; assuming I have "apple" in my hashmap I want to know how long the following statement takes to execute: hmp["apple"]. How can I time it? Thanks! ...

Is there a good integer only line rasterization algorithm ?

Hello, I've been working on building a simple 3d graphic engine and I'm trying to find a good integer based line rasterization algorithm. ( I'm not trying to re-invent the wheel, I'm trying to get a deeper understanding of wheels). Are there any line rasterizing algorithms that don't rely on any floating point math? Thanks. ...

C# Given a desired order need a space efficient list reordering or sorting

My objective is: Given a list of entries, and a desired ordering, rearrange the list of entries according to this ordering. The list will be very large, so space efficiency is important. Ex: List<Entry> data = ReadDataFromSomeWhere(); // data => [a, b, c]; List<int> ordering = RandomPermutation(data.Count); // ordering => [2, 1, 3]; da...