algorithm

Is the time complexity of the empty algorithm O(0)?

So given the following program: Is the time complexity of this program O(0)? In other words, is 0 O(0)? I thought answering this in a separate question would shed some light on this question. EDIT: Lots of good answers here! We all agree that 0 is O(1). The question is, is 0 O(0) as well? ...

Is there such a thing as "negative" big-O complexity?

Possible Duplicate: Are there any O(1/n) algorithms? This just popped in my head for no particular reason, and I suppose it's a strange question. Are there any known algorithms or problems which actually get easier or faster to solve with larger input? I'm guessing that if there are, it wouldn't be for things like mutations or...

Efficient algorithm to find String overlaps.

I won't go into the details of the problem I'm trying to solve, but it deals with a large string and involves finding overlapping intervals that exist in the string. I can only use one of the intervals that overlap, so I wanted to separate these intervals out and analyze them individually. I was wondering what algorithm to use to do this...

Determine compass direction from one lat/lon to the other

Does anyone have an algorithm to determine the direction from one lat/lon to another (pseudo-code): CalculateHeading( lat1, lon1, lat2, long2 ) returns string heading Where heading is e.g. NW, SW, E, etc. Basically, I have two points on a map and I want to get a general idea of the direction taking into account that 50 miles East an...

exact graph algorithms

in data structures and algorithms, what is meant by "Exact Graph Algorithms" ? can you give me some examples? ...

question about compression of data

I want to learn methods for data compression, also how to convert video from MP3 to MP4. Does it depend on bit manipulations? If yes, how? ...

An efficient way to find matching items in N lists?

Given a number of lists of items, find the lists with matching items. The brute force pseudo-code for this problem looks like: foreach list L foreach item I in list L foreach list L2 such that L2 != L for each item I2 in L2 if I == I2 return new 3-tuple(L, L2, I) //not impor...

Need help on designing an algorithm that outputs a time period that can be used for sampling signals within a given range

I need to count frequencies in the 0.1Hz to 1.99GHz range. At my disposal is a 16bit counter with an additional overflow bit, a timer accurate to 1uS, frequency dividers and a microcontroller to glue all these together. The logic I have decided to use is so: Condition the input signal to give a 50% duty cycle 5Vpp square wave Feed th...

How do you print the EXACT value of a floating point number?

First of all, this is not a floating point newbie question. I know results of floating point arithmetic (not to mention transcendental functions) usually cannot be represented exactly, and that most terminating decimals cannot be represented exactly as binary floating point numbers. That said, each possible floating point value correspo...

Perceptual Hash Algorithms in Python or PHP?

I've been exposed via StackOverflow to pHash, a C++ perceptual hash library for audio, video, images, and text fingerprinting - recently with preliminary bindings for PHP, C# and Java. I'm interested in studying these algorithms and I'm wondering if there are any open-source pure Python or PHP implementations of the same / similar algor...

Folder permissions based on users and groups

Hey Im working on a folder tree and need to be able to limit the visibility of certain folder based on the user and the group they belong to. I already have a database representation of all the folders in the tree and the hierarchy of the folders. My question now is how to best represent the permissions. If I have to possibly look up p...

Min Max-Matching Problem

I have a matching problem and I don't know how to solve it: Given a complete bipartite graph (A, B). Each node a_i in A, has two states: s(a_i)=0 or s(a_i)=1 Weighted edges are declared as: w(a_i, b_j, s(a_i)) Fixing a configuration for the states, the problem becomes a max-matching. The goal is to find the configuration with minimum...

Get X unique numbers from a set

What is the most elegant way to grab unique random numbers I ponder? At the moment I need random unique numbers, I check to see if it's not unique by using a while loop to see if I've used the random number before. So It looks like: int n = getRandomNumber % [Array Size]; for each ( Previously used n in list) Check if I've used n...

Is there a Dynamic Programming way to compute the k minimum spanning trees?

My teacher asked us to implement a Dynamic Programming solution to that problem, but I'm thinking one doesn't exist since I couldn't find it using Google. Anyway, given a graph and a k, say 3, you have to find the 3 best MSTs from it. If the graph is such that it doesn't have k subtrees, you can return either the same tree multiple time...

Question on lexical analysis

I am reading the dragon book. Quoting the text from the book (3.1.4 Lexical errors, Pno 114) It is hard for a lexical analyzer to tell, without the aid of other components, that there is a source-code error. For instance, if the string fi is encountered for the first time in a C program in the context: fi ( a == f(x) ) ....

Efficient algorithm to get primes in large numbers.

Hi all , I'm a beginner in C#, I'm trying to write an application to get Primes between two numbers entered by the user .. The Problem is at larg no. like 1 to 10000000 getting the primes takes long time and according to the problem i'm solving, the whole operation must be carried out in a small time interval , this is the problem link f...

Help with algorithm problem from SPOJ

I thought it would be a fun problem: Prime Path But...It is hard for me. My only idea is "To do something with knapsack problem".. and no other ideas. Could You track me for good way? It's not for any challenge or University homework. I just want to learn something. _ Ok, but firstly, how to find this prime numbers? Do i need to find ...

General Programming Logic: Defining Hourly Wage Ranges

Note: This is a general programming question, not specific to any language, but feel free to use the language of your choice in your answer to explain the logic. I would like a method to take a string of text, say "Default(0-100)=20" and then extract out of that the default hourly wage would be 20 for hours 0 through 100. This could be ...

How can I get a least recently used algorithm to work with multiple threads?

I'm using a memory pool to store image data in a ray tracer and I'm using a least-recently-used algorithm to deal with freeing blocks of memory. This works fine when there is only one thread. When I add more threads, the LRU code breaks. I'm using a linked list to store the history of which blocks have been accessed and this is the part ...

what is a loop invariant ?

I'm reading "Introduction to Algorithm" CLRS. and the authors are talking about loop invariants, in chapter 2 (Insertion Sort). I don't have any idea of what it means. ...