algorithm

C (beginner) : Why won't my qsort work? EDIT: From one error to another

I'm doing K&R exercise 6-4, which is: 6-4. Write a program that prints the distinct words in its input sorted into decreasing order of frequency of occurrence. Precede each word by its count. What I decided to do is create a struct called dstncFreqNode6_4: struct dstncFreqNode6_4 { char *word; int count; struct dstncFreqN...

Social Search Algorithms

The question is oriented towards a research that I have been conducting since 3 months. What are the social search engines available currently (if any)? What is the future of semantic + social(collective) intelligence collection/distribution engines? ...

Reordering python list based on an algorithm or pattern

Here is a stumper for you math geeks out there. I have a python list that is just a sequence that looks like this: myList=[1,2,3,4,5,6,7,8,9,10,11,12,13,(...etc...),43] Unfortunately, the data from which the list was generated was not zero-padded, and it should have been. So in reality: 1==1 2==10 3==11 4==12 5==13 6==14 7==15 8=...

Calculate average without being thrown by strays

I am trying to calculate an average without being thrown off by a small set of far off numbers (ie, 1,2,1,2,3,4,50) the single 50 will throw off the entire average. If I have a list of numbers like so: 19,20,21,21,22,30,60,60 The average is 31 The median is 30 The mode is 21 & 60 (averaged to 40.5) But anyone can see that the ...

All possible paths from one node to another in a directed tree (igraph)

I use python binding to igraph to represent a directed tree. I would like to find all possible paths from one node in that graph to another one. Unfortunately, I couldn't find a ready to use function in igraph that performs this task? EDIT The concerns on infinite number of paths the graph I'm talking about is actually a directed ac...

Why doesn't this implementation of Jarvis' March ("Gift wrapping algorithm") work?

I'm trying to implement Jarvis' algorithm for finding the convex hull of a set of points, but for some reason it doesn't work. This is my implementation: procedure TPointList.ConvexHull(aHull : TPointList); //Return the convex hull of a set of 2D points var vPointOnHull : TPoint2D; vEndpoint : TPoint2D; I : intege...

Quicksort decision tree

I have just spent a couple of hours trying to represent the decision tree for the quicksort algorithm on a set of elements (and I also searched the web). I would like to know what each node actually represents. Is it the comparison between two sets (resulting from the call to Partition)? or just the comparison between two elements of the...

Throwing cats out of windows

Imagine you're in a tall building with a cat. The cat can survive a fall out of a low story window, but will die if thrown from a high floor. How can you figure out the longest drop that the cat can survive, using the least number of attempts? Obviously, if you only have one cat, then you can only search linearly. First throw the cat fr...

Eye tracking: finding the pupil (x,y)

Hello, I am looking for some suggestions on how to approach the following computer vision problem. Below are 4 samples of an eye tracking dataset that I am working with. I would like to write code takes one such image and calculates the (x,y) position of the center of the pupil. I am currently using MATLAB, but I am open to using other ...

Algorithm to transform a workflow DAG into parallel resource allocation?

Say I have a graph where nodes are workloads of various kinds and edges are dependencies between the workloads. (This is a DAG since cyclical dependencies must not exist.) I also have a set of multiple agents who can perform the work. Some workload varieties may be given to any agent, others must be given to a specific agent, and other...

minimum connected subgraph containing a given set of nodes

I have an unweighted, connected graph. I want to find a connected subgraph that definitely includes a certain set of nodes, and as few extras as possible. How could this be accomplished? Just in case, I'll restate the question using more precise language. Let G(V,E) be an unweighted, undirected, connected graph. Let N be some subset...

Finding a median using SSE2 instruction set

Hello, My input data is 16-bit data, and I need to find a median of 3 values using SSE2 instruction set. If I have 3 16-bits input values A, B and C, I thought to do it like this: D = max( max( A, B ), C ) E = min( min( A, B ), C ) median = A + B + C - D - E C functions I am planing to use are : max - _mm_max_epi16 min - _mm_min_e...

pythagorean triples exercise

Hi everyone i need a quick hint regarding the following exercise question: Write a program that generates all Pythagorean triples whose small sides are no larger than n. Try it with n <= 200. what is "no longer than n" all about ?? exercise source: Java by Dissection (Ira Pohl and Charlie McDowell) note: i found what looks to b...

Efficiency of Algorithm

This is a direct quote from the textbook, Invitation to Computer Science by G.Michael Scneider and Judith L.Gersting. At the end of Section 3.4.2, we talked about the tradeoff between using sequential search on an unsorted list as opposed to sorting the list and then using binary search. If the list size is n=100,000 about how many ...

Recurrence Relation for a loop

The question is to set up a recurrence relation to find the value given by the algorithm. The answer should be in teta() terms. foo = 0; for int i=1 to n do for j=ceiling(sqrt(i)) to n do for k=1 to ceiling(log(i+j)) do foo++ ...

Sort first n integers in linear time and constant space

I'm looking for a non-comparison or comparison based algorithm that can sort an array containing any permutation of the first n positive integers, which should be O(n) time complexity and O(1) space complexity. Is there an existing algorithm that fits these specifications? ...

Why the space complexity of this algorithm is O(1)

Hi all: i read the algorithm below to find the lowest common ancestor of two nodes in a binary search tree. /* A binary tree node has data, pointer to left child and a pointer to right child */ struct node { int data; struct node* left; struct node* right; }; struct node* newNode(int ); /* Function to find least co...

Whats the best approach (Algorithim) to continually calculate cascading relationships between objects?

For instance A+B=C C+D=E E+F=G as changes are made to each node the associated nodes are recalculated. The image below is a simplistic example of what I am trying to do. Further clarification The structure for each object is identical. the inputs would be prices as each price changes it would have a cascading effect on the prices do...

travelling salesman

Where can I find source code for travelling salasman problem? ...

Is this regression algorithm original and effective?

I've had an idea for a non-linear regression algorithm that I haven't seen before: We fit a simple parametric function, such as a radial basis function, to the data using gradient descent. We find the residual from this and then fit a function to this, repeating this process to reduce the error and build up a collection of superimposed ...