algorithm

Open-source implementations of a photoshop-like quick select algorithm?

Are there any open-source implementations of an graph-cut algorithm similar to that used for Photoshop's quick select tool? I'm researching for a personal project of making a GIMP tool\plugin similar to PS's tool, but I'm wondering if it's been done before. ...

STL Sort vs median of medians

std::sort() uses the Introsort algorithm that switches between quick & heap sort depending upon the current partitioning ratio. Is there a practical disadvantage to implementing Median-of-Medians Quicksort in place of Introsort? After all, it's harder to model a mixture of sorting algorithms theoretically & compute their worst case com...

Finding the max repeated element in an array

Given an array with N elements. We know that one of those elements repeats itself atleast N/2 times . We dont know anything about the other elements . They may repeat or may be unique . Is there a way to find out the element that repeats atleast N/2 times in a single pass or may be O(N) ... ??? P.S : No extra space is to be used . ...

Linked list problem

Hiii ... If we are given two linked lists (may be of different length) such that a few nodes from the end are common ... How do we find the first common node in least time as possible ... ? The lists are singly linked . Some nodes are common from the end and we need to find the first common one for both among them FROM THE END. ...

What is the algorithm for counting the number of 1's and 0's in a 16 bit number in lc3 machine language?

Provided adresses: x4000 - address of the input number x4001 - address to store count for 0's x4002 - address to store count for 1's ...

What's a good algorithm for nearest neighbour problem in two dimensions ?

I would like to build an app that's going to give you the closest restaurant depending on your location. We'll have a database with all the POI corresponding to the restaurant and we'll get your location with the GPS of your phone... What algorithm would be appropriate ? Where can I find good doc about it ? Thanks ...

Using Latex algorithmic package for switch statement?

My googling didn't come up with how to do a switch statement in an algorithm using the algorithm and algorithmic packages, but I'm assuming you can. Most guides just didn't mention it either way. \begin{algorithm} \caption{send(...) method} \begin{algorithmic} \IF{dest equals..} %\SWITCH{nature} \STATE cast data... \STATE extract data.....

Regular Expressions Algorithm

Given a sub-string, is there a way to generate all the possible regular expressions (most restrictive to least restrictive) that would match that sub-string for a given string? For example, say you have a sub-string "orange" and a string "apple banana orange grape". How would I get a list of regexes that match "orange" (I know there wil...

Rectangular region in an array

Given an N*N matrix having 1's an 0's in them and given an integer k,what is the best method to find a rectangular region such that it has k 1's in it ??? ...

High-level vs. low-level algorithm implementation

What is exactly meant by high-level and low-level implementation of an algorithm? ...

How to get homography matrix in such case? (from one still image)

In my case as input I have such data structures: original image (RGB pixels), objects (squares) with lines crossing points in pixels (x,y) on Image Plane. I have image like this In my particular case the Image Plane has 3 quadrilaterals - projections of real world squares, which, as we know, have same size, lying on the same plane, w...

Does dijkstras algorithm relax the edges of the shortest path in order?

In "Introduction to algorithms, 3rd edition" exercise 24.3-5 wants an example that this is wrong (not always true). Is that possible? In my mind this is impossible because every edge is relaxed at a time when the path to the current vertice is already decided. Word for word: Professor N. claims to have a proof of correctness of Dijk...

selecting hash values by value property in ruby

In Ruby, I have a hash of objects. Each object has a type and a value. I am trying to design an efficient function that can get the average of the values of all of objects of a certain type within the hash. Here is an example of how this is currently implemented: #the hash is composed of a number of objects of class Robot (example name...

Time and space complexity of vector dot-product computation

Help me! What is the time and space complexity of an algorithm, which calculates the dotproduct between to vectors with the length n. ? ...

Find common sequence that is out of order

What algorithm finds a common sequence that is out of order between two strings? I need to implement or use one in C++. ...

Find the smallest window of input array that contains all the elements of query array

Problem: Given an input array of integers of size n, and a query array of integers of size k, find the smallest window of input array that contains all the elements of query array and also in the same order. I have tried below approach. int[] inputArray = new int[] { 2, 5, 2, 8, 0, 1, 4, 7 }; int[] queryArray = new int...

How can I improve this PHP pagination algorithm?

I'm working on a pagination algorithm in PHP. I can guess that it needs room for improvement, so I'd like some thoughts on how to improve it, be it cleaning up the code itself, from a UI/UX standpoint, or anything else you can think of. The algorithm should output pagination that looks like this: 1 2 3 ... 6 7 8 ... 97 98 99 or this:...

What is the best way to analyse a large dataset with similar records?

Hi, Currently I am loooking for a way to develop an algorithm which is supposed to analyse a large dataset (about 600M records). The records have parameters "calling party", "called party", "call duration" and I would like to create a graph of weighted connections among phone users. The whole dataset consists of similar records - peopl...

Algorithm for smoothing wifi signal strength

When measuring the strength of a Wifi signal between two static points, the measurement constantly fluctuates due to environmental factors. What is a good algorithm to use smooth out small fluctuations and detect significant changes? Exponential moving average? ...

Finding a lower bound for an algorithm using the guess/verify method

Hi everyone, I am trying to work out a few guesses on algorithm complexity, but every time I attempt to guess using an exponential time, my guess/verify method seems to fail. I am sure I am doing something absurdly wrong, I just can't find it myself. For Example, if I have the recurrence T(n) = 2T(n-1) + T(n-2) + 1 , where T(1) = 0 and ...