algorithm

Performing an edge contraction on a graph.

I am trying to do edge contraction on a graph. n is the number of vertices in the graph. The vector f containing pairs of vertices representing an edge contains the edges which are to be contracted. The graph does not contain any self loops. Please point out any logical mistakes if any in the code. If the method is entirely wrong then...

Find the rightmost occurrence of a string t, in a string s.

Corrected code: int strrindex(char *s, char *t) { int i, j, k, p; i = -1; for (k = 0; s[k] != '\0'; k++) { if (strlen(s) < strlen(t)) break; if (s[k] == t[0]) { for (p = k; s[p] != '\0'; p++) { j = p; while (s[j] != '\0' && s[j] == t[j-k] && t[j-k] != '\0') { j++; } if (t[j-k] != '\0') { break; ...

Finding the square root of a given number using bitwise operations

Is there an algorithm to find the square root of a given number using bitwise operations? ...

question about euler project's problem

here is problem about sum of factorial of digit http://projecteuler.net/index.php?section=problems&amp;id=254 also here is Define sf(n) as the sum of the digits of f(n). So sf(342) = 3 + 2 = 5. here is code which prints 32 as sum of digit's factorials but it does not show me second result import java.util.*; public class fact_of_d...

Question regarding the Smith-Waterman algorithm

Hi all, I am running some string matching tests using the Smith-Waterman algorithm. I am currently using SimMetrics (the Java open source project) to run the tests. Can anyone explain why when I compare 'Bloggs J.' to 'Bloggs' I get a similarity value of 1.0? There obviously is a gap (e.g. 'o' and '.'), but it does not appear to be ...

Algorithm for generating a size k error-correcting code on n bits

I want to generate a code on n bits for k different inputs that I want to classify. The main requirement of this code is the error-correcting criteria: that the minimum pairwise distance between any two encodings of different inputs is maximized. I don't need it to be exact - approximate will do, and ease of use and speed of computationa...

Perceptual similarity between two audio sequences

Hi, I would like to get some sort of distance measure between two pieces of audio. For example, I want to compare the sound of an animal to the sound of a human mimicking that animal, and then return a score of how similar the sounds were. It seems like a difficult problem. What would be the best way to approach it? I was thinking to e...

Is quick sort followed by binary search faster than linear search?

Is it better to sort then binary search or simply linear search? Thanks ...

BST preorder traversal and writting tree content to temporary array

I'm trying to write binary search tree's content to temporary array in order to use in main. However I'm not sure how to do it... I have tried something like this: void Book::preorder(TreeNode *ptr, Person &temp[], int x) { if(ptr!=NULL) { temp[x].name=ptr->item.name; x++; preorder(ptr->left, temp, x); preorder(ptr->right, te...

Concatenating red-black trees

The OCaml standard library has a wonderful Set implementation that uses a very efficient divide-and-conquer algorithm to compute the union of two sets. I believe it takes whole subtrees (not just single elements) from one set and inserts them into the other set, rebalancing when necessary. I'm wondering if this requires the height infor...

i want to learn web spider and extraction of data algorithms

I'm building at list trying to build simple web crawler that extract data by pre definitions. After reading posts here I based my spider on libxml2 and curl and C++. Now I would like to learn web spider and data extraction algorithms if there are any. What should I learn ? ...

How do I paint clouds?

I need an algorithm to paint clouds, or cloud like shapes. Obviously, I wouldn't want them all to be similar. What should I use to generate the relevant series of X,Y coordinates to paint the clouds? I am going to implement this either in SVG or Canvas ...

Any good method to work with large amount of data?

I have almost 100.000 records in the database and I need to compare them to each-other with the Longest Common Subsequence algorithm, and I need to do that with 1000 new records every day. My application is written in c# .Net, and the problem is that this comparing is working slow on the application level, for comparing of 1000 records a...

How to find function range?

I have an arbitrary function or inequality (consisting of a number of trigonometrical, logarithmical, exponential, and arithmetic terms) that takes several arguments and I want to get its range knowing the domains of all the arguments. Are there any Java libraries that can help to solve a problem? What are the best practices to do that? ...

HCF of given numbers

whats the logic for calculating HCF of given numbers? ...

Find set of numbers in one collection that adds up to a number in another.

For a game I'm making I have a situation where I have a list of numbers say [7, 4, 9, 1, 15, 2] (named A for this) and another list of numbers say [11, 18, 14, 8, 3] (named B) provided to me. The goal is to find all combinations of numbers in A that add up to a number in B. For example: 1 + 2 = 3 1 + 7 = 8 2 + 9 = 11 4 + 7 = 11 1...

Formula Parser with Brackets

Hi folks, I need to implement a simple formula parser. What I am doing is first create a postfix notation and then evaluating the postfix string. Unfortunately, this algorithm doesn't allow brackets i.e. (2+3)*a. Anyone knows how to extend the algorithm to allow brackets? Thanks in advance, Frank ...

Acos & Asin substitute in Access

How can I calculate track & distance & wind vectors in Access. Many thanks ...

Find a number which occurs an odd number of times in a SORTED array

Hi, I have a question and I tried to think over it again and again... but got nothing so posting the question here. Maybe I could get some view-point of others, to try and make it work... The question is: we are given a SORTED array, which consists of nos. which occur EVEN no. of times, except one, which occurs ODD no. of times. We nee...

Computing the colors of the Olympic flag

Let's say you are helping setting up the Olympics on an alien planet. You are in charge of making the Olympic flag. The Olympic flag would have 6 colors. The flags of every country on the planet must have one of the six colors on the Olympic flag. You already know the colors on a flag. How would you compute the colors on the Olympic flag...