algorithm

How to get camera position from such data generated by LSD lines detector?

So for example I have such lines with coordinates. how (using what algorithm) is it possible to generate some kind of simple 3d scene meaning get relative distance from camera to the wall that is facing us? ...

What is a fast algorithm for finding critical nodes?

I'm looking for a quick method/algorithm for finding which nodes in a graph is critical. For example, in this graph: Node number 2 and 5 are critical. My current method is to try removing one non-endpoint node from the graph at a time and then check if the entire network can be reached from all other nodes. This method is obvious not...

Help on using boost relaxed heap

Hello all, I'm implementing a few graph algorithms at the moment and am wanting a container with the complexity of a fibonacci heap or a relaxed heap (specifically I want at least O(logN) for push and pop and O(1) for reduce_key). I'm not keen on implementing this myself if at all possible (development and testing overhead and time) an...

How to recognize what is, and what is not tail recursion?

Sometimes it's simple enough (if the self call is the last statement, it's tail recursion), but there are still cases that confuse me. A professor told me that "if there's no instruction to execute after the self-call, it's tail recursion". How about these examples (disregard the fact that they don't make much sense) : a) This one sho...

What is the logic for solving this sequence?

The sequence goes like this.. 7,8,77,78,87,88,777,778,787,788 and so on.. What can be the logic for finding the nth number of the sequence? I tried that by dividing it by 2 and then by 4 and hence, but it doesn't seem to work. ...

Lowest common multiple for all pairs in a list

I have some code that calculates the lowest common multiple for a list of numbers. I would like to modify this code to return a list of values that represents the lowest common multiple for each pair in my number list. def lcm(numbers): return reduce(__lcm, numbers) def __lcm(a, b): return ( a * b ) / __gcd(a, b) def __gcd(a,...

How to optimize my current getMax method to retrieve the highest number in an array?

What would be the best way to optimize this code below to make it more efficient while applying the 'best practices'. This is just a simple school project and it works, I've tested it. But I just feel like there's a better and more efficient way to write this method. What do you think? I have an array that is pre-populated with a bunch...

PCA: What's wrong with this algorithm?

Can someone please either confirm or correct this Wikipedia algorithm for computing the first principal component? I want a simple implementation of PCA in D, which doesn't have any existing libraries for PCA AFAIK. I've tried implementing this, and it doesn't seem like my results on simple examples match stuff I get from R or Octave. ...

Efficient search for shortest and longest strings from an array of long strings in C

Given an array of pointers to ordinary C NUL-terminated (and typically very long) strings, how can we best find the smallest and the largest strings? ...

Writing algorithm functions for STL

I have a std::set which is of type point struct point { int x; int y; int z; }; Suppose I want to perform three different operation on each variable in set i.e Find the smallest number from x variables. Get missing elements from y variables using set difference. Get product of all z variables. At this point, should i use thr...

OCR error correction: How to combine three erroneous results to reduce errors.

The problem I am trying to improve the result of an OCR process by combining the output from three different OCR systems (tesseract, cuneinform, ocrad). I already do image preprocessing (deskewing, despeckling, threholding and some more). I don't think that this part can be improved much more. Usually the text to recognize is between on...

Insert multiple items into List or Array (no Linq and not quite CodeGolf)

No matter how I try, I can't seem to create a nice and clean algorithm for doing the following: System.Array (or generic List) data of System.Object System.Array (or generic List) xval of System.Object System.Array (or generic List) idxs of System.Int32 xval and idxs contain the same number of elements and idxs contains no values les...

Picking five numbers that sum to S

Given an array A of N nonnegative numbers, I'm interested in finding the number of ways you can pick 5 numbers (from distinct positions in the array) such that their sum is S. There is an easy solution in O(N^3): Let H be a hash table of (sum, position of leftmost element of sum) for i = 0, N for j = i + 1, N H.add(A[i] + A...

desktop search algorithm

Anybody has idea on how desktop search algorithm is implemented. Any starting point would be helpful. ...

C# radix sort for strings of arbitrary lengths

I need to sort a huge list of text strings of arbitrary length. I suppose radix sort is the best option here. List is really huge, so padding strings to the same length is completely impossible. Is there any ready-made implementation for this task, preferably in C#? ...

3D Connected Points Labeling based on Euclidean distances

Hi guys, Currently, I am working on a project that is trying to group 3d points from a dataset by specifying connectivity as a minimum euclidean distance. My algorithm right now is simply a 3d adaptation of the naive flood fill. size_t PointSegmenter::growRegion(size_t & seed, size_t segNumber) { size_t numPointsLabeled = 0; /...

What is the most efficient pattern/algorithm to compare two lists and find the delta between those two lists?

We have two lists, let's say students and their scores. I want to compare these two lists and find the delta between the new list and the old list, then find the least intrusive way to Insert or Update into the new list any changes. What is the best algorithm to approach this? Want to focus on minimal amount of changes to new list and...

Identifying graphs in heap of connected nodes -- how is this called?

I have a SQL table with three columns X, Y, Z. I need to split it in groups in such a way that all records with same value of X or Y or Z are assigned to the same group. I need to make sure that the records with same value X or Y or Z are never split across multiple groups. If you think of records as nodes and values of X, Y, Z as edges...

An algorithm thats gives all possible distinct arrays whose positive integer elements sum to a given number.

Possible Duplicate: An algorithm to decompose a whole number into all possible sets of whole numbers that sum to it. An algorithm which for any input positive integer, gives all possible distinct arrays of positive non-zero integers that can sum to it. e.g Inputting 4 returns (1,1,1,1), (1,1,2), (1,2,1), (2,1,1), (1,3), (3,1)...

Is there any way to improve this function which replaces occurrences of substrings with another string in an malloc allocated string?

Hello. I'm very new to C and I decided to make a function called str_replace which replaces strings inside strings which have been made using malloc. It appears to work but can anyone find any room for improvements. Any advice will be appreciated. I'd like to know if people think finding the number of occurrences to calculate the new s...