algorithm

How does pagination on Reddit's home page work?

Reddit uses a time decay algorithm. That would mean the sort order is subject to change. When a user goes to page 2, is there a mechanism to prevent them from seeing a post that was on page 1 but was bumped down to page 2 before they paged over? Is it just an acceptable flaw of the sort method? Or are the first couple of pages cached for...

How do I check if a program terminates?

Is there a general rule that can be used to determine this? E.g: int i = 10; while (i > 1 ) { if (i%2 == 0) i = i/2; else i = 3*i - 1; } ...

Do both these factorial functions run in O(n)?

The recursive function defined as so: function factrec($x) { if($x <= 1) { return $x; } else { return $x * factrec($x - 1); } } And iterative here: function factiter($x) { $y = $x; while($y > 1) { $x *= ($y - 1); $y--; } return $x; } I had read that on the recursive functi...

Do programmers should train in ACM-contests?

A lot of those coders, who are succeed contests like TopCoder SRMs, or Google Codejam, etc., get good jobs and salary. But is it really neccesary? I mean, do all code developers should know different algorithms, structures, or all this contests are just wasting of time? The problem is those contests take much time - to train, to study, t...

Algorithm to make a face on a photo look fatter ?

What is the most general and simple approach to make look fatter a face on an image ?I am working with java but programming details are not important i am looking for the algorithm . ...

Implementing a sparse array in C# / fastest way to map integer to a specific bucket/range number.

My initial problem is that I need to implement a very fast, sparse array in C#. Original idea was to use a normal Dictionary<uint, TValue> and wrap it in my own class to only expose the TValue type parameter. Turns out this is pretty slow. So my next idea was to map each integer in the needed range (UInt32.MinValue to UInt32.MaxValue) t...

How to determine the number of similar bits?

I need to compare two numbers and look for similarities in more significant bits. I'm trying to determine the number of least significant bits that differ. 10111000 10111011 184 and 187 require an offset of two, because only two least significant bits differ. 10111011 11111011 187 and 251 require an offset of seven, because the sev...

Function which is Big O(1) but not Ω(1)

Can some help me with a function which is Big O(1) but not Ω(1) and the other way around? Some explanation would greatly help. ...

data structure programming algorithm

how to draw binary trees whose preorder listing is abcdefgh and whose postorder listing is dcbgfhea.also,list the nodes of binary trees in inorder and level order ? ...

Iteration to Recursion

Possible Duplicate: Can all iterative algorithms be expressed recursively? Is it always possible to convert a iterative function in a recursive function? ...

Generating 2D regions

Are there any good approaches to generating regions for a 2D map? Suppose you have a world map and would like to create country or province borders with a somewhat realistic look. ...

combination of combination java

I need to find combination of combination in JAVA. I have for instance 6 students in class. Out of them, I need to create combination of 4 people in group, and for each group I can choose an intimate group of 2. I have to make sure that there are no doubles (order does not matter).! and need to print the 4 people group. However, this...

Best way to select the ith smallest number of a delimited sequence of numbers

Hi everyone. If I am given a certain set of numbers (which I store in a balanced binary search tree for easiness), then I want to answer a query that requires me to inform what is the ith smallest number between [A,B], what would be a fast algorithm to perform that task? Technically I could traverse the tree from the root searching for...

Detecting random keyboard hits considering QWERTY keyboard layout

The winner of a recent Wikipedia vandalism detection competition suggests that detection could be improved by "detecting random keyboard hits considering QWERTY keyboard layout". Example: woijf qoeoifwjf oiiwjf oiwj pfowjfoiwjfo oiwjfoewoh Is there any software that does this already (preferably free and open source) ? If not, is ther...

Hashing sets of integers

I'm looking for a hash function over sets H(.) and a relation R(.,.) such that if A is included in B then R(H(A), H(B)). Of course, R(.,.) must be easy to verify (constant time), and H(A) should be computed in linear time. One example of H and R is: H(A) = OR over 1 << (h(x) % k), for x in A, k a fixed integer and h(x) a hash function...

Convert ascii encoding to int and back again in python (quickly)

I have a file format (fastq format) that encodes a string of integers as a string where each integer is represented by an ascii code with an offset. Unfortunately, there are two encodings in common use, one with an offset of 33 and the other with an offset of 64. I typically have several 100 million strings of length 80-150 to convert ...

Algorithms needed on filtering the noise caused by the vibration

For example you measure the data coming from some device, it can be a mass of the object moving on the bridge. Because it is moving the mass will give data which will vibrate in some amplitude depending on the mass of the object. Bigger the mass - bigger the vibrations. Are there any methods for filtering such kind of noise from that dat...

finding maximum size sub-matrix of all 1's in a matrix having 1's and 0's

Hi, the problem is - Suppose you are given an mXn bitmap, represented by an array M[1..m,1.. n] whose entries are all 0 or 1. A all-one block is a subarray of the form M[i .. i0, j .. j0] in which every bit is equal to 1. Describe and analyze an efficient algorithm to find an all-one block in M with maximum area I am trying to make a d...

Java: Simple recursion function returns only 1

This is oddly my first Java application, I was wanting to implement an arbitrary precision factorial function, I did the recursive one fine but my iterative one simply outputs "1" and nothing else.. It is so late for me I can not spot why, I am not sure where I went wrong, is there something obvious here? public static BigInteger ifact(...

Bi quinary coded examples

i have following problem To decode the Biquinary code use the number 5043210. At each digit multiply the biquinary number by the number 5043210. This will give you one decimal digit. For example take the number 0110000. To change this into decimal: (5 × 0) + (0 × 1) + (4 × 1) + (3 × 0) + (2 × 0) + (1 × 0) + (0 × 0) = 4 i have tried this ...