algorithm

Algorithm to determine most popular article last week, month and year?

I'm working on a project where I need to sort a list of user-submitted articles by their popularity (last week, last month and last year). I've been mulling on this for a while, but I'm not a great statitician so I figured I could maybe get some input here. Here are the variables available: Time [date] the article was originally publ...

Smallest integer larger than lg N

I was reading somewhere that: The smallest integer larger than lg N is the number of bits required to represent N in binary, in the same way that the smallest integer larger than log10 N is the number of digits required to represent N in decimal. The Java statement for (lgN = 0; N > 0; lgN++, N /= 2) ; is a si...

How to write a Linear Congruential Generator (LCG) in C#? Or are there any well known implementations?

I am wanting to generate a random array of sequences that repeat and only use each number once. For example, given a range of 0-9 with 2 different seeds you might get Seed 1: 7 3 5 9 0 8 1 2 6 4 | 7 3 5 9 0 8 1 2 6 4 | 7 3 5 9 0 8 1 2 6 4 Seed 2: 2 5 7 1 4 9 6 8 3 0 | 2 5 7 1 4 9 6 8 3 0 | 2 5 7 1 4 9 6 8 3 0 From what I understand, a...

Comparison Based Ranking Algorithm

I would like to rank or sort a collection of items (with size potentially greater than 100,000) where each item in the collection does not have an intrinsic (comparable) value, instead all I have is the comparisons between any two items which have been provided by users in a 'subjective' manner. Example: Consider a collection with el...

How to construct a repeating equation?

Suppose two integers x and N. I'm trying to determine how to construct an algorithm that would return an integer of the value x repeated N times. So if x was 9 and N was 4, the equation would return 9999. And if x was 9 and N was 5, the equation would return 99999. (ad nauseam) I hope this isn't completely absurd or out of place on SO...

2d point clustering

Given: Given a set of N points in the 2D plane (x and y coordinates), and a set of N radii corresponding to each point. We will refer to a point's disc as the disc centered at the point with its radius. Problem: Cluster the points. A cluster of points is such that each point EITHER falls within the disc of at least one other point in th...

Scheduling Algorithm for Maintining Two Dimensional Constraint

I have been tasked to do a scheduling program in my company. Basically given N employee you should schedule them shift for the month. I tried to do this via brute force and ordered priority of constraint. However, I am having problem when trying to maintain vertical and horizontal constraints. Vertical constraints, all person should hav...

Algorithm for schematizing (metro) maps

This is a long shot, but I thought I might try before starting the dirty work. I've got a project to build an application which will, for a defined input stations (vertices) and lines (edges), that is, a real map of some public transportation, schematize a given map into a metro map. I've done some research on the problem and it's an NP...

Determine points within a given radius algorithm.

I'm not sure what mathematical concept this is to support my question. ^^ Let's say we have PointA as the reference. The problem is to find the points around PointA within a given radius (Using coordinates). My approach would be to compute the distance of every point (Pythagorean) and then compare with the given radius. I'm sure that th...

How can this Java code be improved to find sub-string in a string?

Hi, I was recently asked to submit a solution to a problem for a job. Problem: Find a sub-string in a string. Input: "Little star's deep dish pizza sure is fantastic." Search: "deep dish pizza" Output: "Little star's [[HIGHLIGHT]]deep dish pizza[[ENDHIGHLIGHT]] sure is fantastic." Note that the highlighter doesn't have to have...

Optimum algorithm to calculate pythagorean triplet

I have a question for everyone. I have this problem statement where in given, x^2 + y^2 = c is the equation, you have to optimally find the tuples (x,y) such that the equation holds true. Given a variable c, whose value is known, you have to find the values (x,y). So suppose if you have c=0, then x=0 and y=0. Suppose you have c=2, then...

graph algorithm question

How can I find all available path for each Vertices which won't cause a cycle? What algorithm to use? Please be brief and provide links if possible, and ask questions if something is not clear from the wonderful diagram below :) I am not looking for a shortest path or anything like that. Instead I just want to know which paths I can st...

term highlight algorithm (HTML)

Hi, I know there are quite some term highlighting questions asked but as far as I know none answers mine. The search terms are put into an array $keyarray = array("DE", "ABCD"); $string = "ABCDEF"; foreach ($keyarray as $value) { $string = str_ireplace($value, "<b>{$value}</b>", $string); } The results will obviously be ABCDEF rath...

Minimum area triangle from a given set of points

Given a set of n points, can we find three points that describe a triangle with minimum area in O(n^2)? If yes, how, and if not, can we do better than O(n^3)? I have found some papers that state that this problem is at least as hard as the problem that asks to find three collinear points (a triangle with area 0). These papers describe a...

Line clipping to arbitary 2D polygon

Hi, guys, If I get a line segment which was long enough to cross a given polygon, which could be concave or convex polygon. How did I find the all the intersected light segments which was contained in the polygon? If the target region is not polygon, but a implicit curve function or spline curve, how to do it? Thanks! ...

Good algorithms book with proofs of the algorithms?

Possible Duplicate: What book to use to learn Algorithms and Data Structures ? I need a good book on algorithms with mathematical proofs of the complexity and the algorithm itself. Can you recommend me one? ...

Algorithm to find common subsets

I have N number of sets Si of Numbers, each of a different size. Let m1, m2, ... mn be the sizes of respective sets (mi = | Si |), and M be the size of the largest set. I have to find common subsets that have at least two numbers in them. Example: Set Items 1 10,80,22 2 72, 10, 80, 26,50 3 80, 4 10, 22 5 22, 72, 10, 80, ...

Remove Duplicate ID's?

I have a list of 50,000 ID's in a flat file and need to remove any duplicate ID's. Is there any efficient/recommended algorithm for my problem? Thanks. ...

Algorithm: Determining type of homepage?

I've been thinking about this for a while now, so I thought I would ask for suggestions: I have some crawler which enters the root of some site (could be anything from www.StackOverFlow.com, www.SomeDudesPersonalSite.se or even www.Facebook.com). Then I need to determin what "kind of homepage" I'm visiting.. Different types could for in...

What, if anything, is wrong with this shuffling algorithm and how can I know?

Just as background, I'm aware of the Fisher-Yates perfect shuffle. It is a great shuffle with its O(n) complexity and its guaranteed uniformity and I'd be a fool not to use it ... in an environment that permits in-place updates of arrays (so in most, if not all, imperative programming environments). Sadly the functional programming wor...