algorithm

Order sets of numbers for maximum distance

You have (up to 100) distinct sets of (2-4) numbers. The order of the sets or numbers in the sets does not matter. The highest number relates to the number of sets and goes up to 30. Like: {1 2 3 4} {1 2 3 5} {1 2 3} {1 2 4 5} {6 2 4} {6 7 8 9} {6 7 9} {7 8 9} {2 4 8 9} The goal is, to arrange these sets in a particular order, where tw...

Is it possible in MySQL to order something by popularity with a timestamp and the number of hits?

I only have two variables to work with here, age (unix timestamp) and hits. I'm wondering if there is a solution in MySQL to calculate and order by the popularity of something. The algorithm would have to acknowledge that new items would not necessarily have as many hits as older ones but are more popular. Is this possible the way I'm i...

How to round decimal value up to nearest 0.05 value??

Is there any way to round up decimal value to its nearest 0.05 value in .Net? Ex: 7.125 -> 7.15 6.66 -> 6.7 If its now available can anyone provide me the algo? ...

Why there is no std::copy_if algorithm?

Is there any specific reason for not having std::copy_if algorithm in C++ ? I know I can use std::remove_copy_if to achieve the required behavior. I think it is coming in C++0x, but a simple copy_if which takes a range, a output iterator and a functor would have been nice. Was it just simply missed out or is there some other reason behin...

bitwise operations without bitwise operators

Here's an example I ran across: private function bitwiseAnd(a:int, b:int):int { var result:int = 0; var n:int = 1; while ((a > 0) && (b > 0)) { if (((a % 2) == 1) && ((b % 2) == 1)) { result += n; } a = a / 2; b = b / 2; n = n * 2; } return result; } So basica...

Algorithmically get Amplitude and Phase of Sine wave?

I'm trying to figure out a way to algorithmically get the amplitude and phase of a function that has sinusoidal terms in the Maxima computer algebra system. This only applies to steady state (as t -> infinity and the transients decay). For example, a trivial case would be: f(t) = 1 / w * sin(w * t + theta) + exp(-a * t) + 8 In this ...

is there any sync algorithm/reference available for syncing a directory?

I'm planning to write a program to sync a folder in real time across multiple computers over the internet. I'm wondering if there is any sync algorithm to handle file sync conflicts, ie, computer A tries to save a file, while computer B has removed the file. ...

What is the best way to implement a rate-limiting algorithm for web requests?

Possible/partial duplicates: What’s a good rate limiting algorithm? Throttling method calls to M requests in N seconds Best way to implement request throttling in ASP.NET MVC? I am looking for the best way to implement a moving time window rate limiting algorithm for a web application to reduce spam or brute force attacks. Examples ...

How to predict the behavior of a system based on previous behavior

I am looking for an algorithm that, based on the previous behavior of a system, predicts the future behavior. I'm building a parallel memory allocator that has a public list of empty blocks. Each thread, when it needs, can take blocks from this list and allocate from them. The blocks are grouped in bins, depending on the allocation si...

Pagerank and its mathematics: Explanation needed

I am a student interested in developing a search engine that indexes pages from my country. I have been researching algorithms to use for sometime now and I have identified HITS and PageRank as the best out there. I have decided to go with PageRank since it is more stable than the HITS algorithm (or so I have read). I have found countle...

Math logic (basic trig) in a game, what is this code doing?

I'm trying to better understand what exactly this code is doing. It's written in Objective-C, but should be familiar to anyone with a C background. What exactly are sin/cos mathematics doing here? Also, does anyone have a good recommendation for learning trig for gaming concepts such as these? for (int i = 0; i < GAME_CIRCLES; i++) { p...

Algorithm for reading the actual content of news articles and ignoring "noise" on the page?

I'm looking for an algorithm (or some other technique) to read the actual content of news articles on websites and ignore anything else on the page. In a nutshell, I'm reading an RSS feed programatically from Google News. I'm interested in scraping the actual content of the underlying articles. On my first attempt I have the URLs from th...

Algorithm for solving set problem

If I have a set of values (which I'll call x), and a number of subsets of x: What is the best way to work out all possible combinations of subsets whose union is equal to x, but none of whom intersect with each other. An example might be: if x is the set of the numbers 1 to 100, and I have four subsets: a = 0-49 b = 50-100 c = 50-75...

What is the most efficient way to retrieve the column index for rows affected by "rowspan"?

Consider the following table: <table> <thead> <tr> <th scope="col" /> <th scope="col">A</th> <th scope="col">B</th> <th scope="col">C</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Apples</td> <td>Oranges<...

How to generate the effective order number? (nice pattern with unpredicatable gap)

Hi all just wondering does anyone in here have good idea about generating nice order id? for example 832-28-394, which show a quite nice and formal order id (rather than just use an database auto increment number like ID=35). the order id need to look random so it can not be able to guess by user. e.g. 832-28-395 (shoudnt exist) ...

Transpose a 2D array

How do you efficiently transpose a matrix? Are there libraries for this, or what algorithm would you use? E.g.: short src[W*H] = { {1,2,3}, {4,5,6} }; short dest[W*H]; rotate_90_clockwise(dest,src,W,H); //<-- magic in here, no need for in-place //dest is now: { {4, 1}, {5, 2}, {6, 3} }; (In my specific case its src arr...

How to combine and optimize a predicate, generally?

I'm doing some work on a Complex Event Processing system. It supports filtering of sets of records based on members of those records, using a query language. The language supports logical, arithmetic and user-defined operators over arbitrary members. Here's an example of a supported query: ( MemberA > MemberB ) && ( @in MemberC { "str...

Find a similarity of two vector shapes

Looking for any information/algorithms relating to comparing vector graphics. E.g. say there two point collections or vector files with two almost identical figures. I want to determine that a first figure is about 90% similar to the second one. ...

Algorithm for moving a point around an arbitrary non self-crossing closed polygon in N time

I'm looking for an algorithm that would move a point around an arbitrary closed polygon that is not self-crossing in N time. For example, move a point smoothly around a circle in 3 seconds. ...

data structures - asymptotic analysis (C++)

Does anyone know where I can find nicely organized in one placed (maybe a table, but doesn't have to) an asymptotic analysis of basic data structures. I'd like to refresh my understanding of data structures and also search and sorting algorithms. So I'm looking for best, avg. and worst case scenarios. It wouldn't hurt if it included STL...