algorithm

Creating a fast hash function for fixed-length input

Hi, Currently I working on a project where some information have to be hashed. As the dataset is huge (millions of records created every day) the algorithm for data transformation has to be fast. The pieces of data that have to be hashed are fixed length (11 decimal numbers - example: 05018144298). So what I would like to know is wheth...

How to find average of top half of N numbers?

Given N arbitrary integers, how to find average of top half of these numbers? Is there an O(n) solution? If not is it possible to prove that it's not possible? ...

Elegant way to bias random boolean

I'd like to create a random boolean in JavaScript, but I want to take the previous value into account. If the previous value was true, I want it to be more likely for the next value to be true. At the moment I've got this (this is in the context of a closure - goUp and lastGoUp are locals to the containing scope): function setGoUp() { ...

What's the fastest way to represent and multiply sparse boolean matrices?

So, I'm using boolean matrices whose dimension is usually a couple dozen to a couple hundred, they are usually quite sparse (just some 2-4 non-zeros in most rows and columns) and my runtime is heavily dominated by their multiplication. What datastructure suits best for speeding up multiplication under these circumstances? Currently I'm...

Web stats: Calculating/estimating unique visitors for arbitary time intervals.

Hi, I am writing an application which is recording some 'basic' stats -- page views, and unique visitors. I don't like the idea of storing every single view, so have thought about storing totals with a hour/day resolution. For example, like this: Tuesday 500 views 200 unique visitors Wednesday 400 views 210 unique visitors Thur...

any SHA-3 news?

The NIST 2nd SHA-3 Candidate Conference was held in late August. Has there been any news on the SHA-3 competition entrants that came to light at the conference? ...

Counting palindromic substrings in O(n)

Given a string (assume only English characters) S of length n, we can count the number of palindromic substrings with the following algorithm: for i = 0 to |S| do p1 = number of palindromes centered in i (odd length) p2 = number of palindromes centered in i and i+1 (even length) add p1 + p2 to total number of palindromic su...

Where can I find more resources on computing (or algorithms) with bounded error?

I've developed an algorithm for PSPACE computations, but it has an error associated with it that varies with parameters. I'd like to learn more about existing computational methods and algorithms that give results that are true within a bounded error. I guess this is something like probabilistic computation. Can someone help me identi...

Should developers know discrete math?

Is it important for developers to know discrete math? Most of the books about algorithms and analysis have at least some references to math. I can easily understand the algorithms in principle and can implement them without any problem, but when it comes to the math parts I get stuck. Is it generally assumed that developers will have dee...

Time Complexity between JFC's HashMap and TreeMap?

Hi everyone, From my understanding, TreeMap : 1. Insert O( logN ) 2. Delete O( logN ) 3. Retrieve O( logN ) HashMap : 1. Insert O( 1 ) -> O( N ) 2. Delete O( 1 ) -> O( N ) 3. Retrieve O( 1 ) -> O( N ) I know that TreeMap using Red-Black tree as internal data structure. However, I'm not so sure about HashMap's internal data structure....

Collision detection between two general hexahedrons

I have 2 six faced solids. The only guarantee is that they each have 8 vertex3f's (verticies with x,y and z components). Given this, how can I find out if these are colliding? ...

Writing a sequence generator algorithm in objective C in association with GPS coordinates

Hello all, I am developing a location based iPhone app wherein a random generator algorithm is needed. The app loads up with a number of images which the user has to reach. An algorithm has to be written where in the sequence of images has to be drawn upon three factors: total time entered by the user to play the game, total distance and...

Collision detection between 2 rotated cubes

Possible Duplicate: Collision detection between two general hexahedrons Right now I do collision detection by finding the min and max and doing bounding box check. Unfortunately, my player cube rotates with the camera and this makes for some annoying results when the player is at a 45 degree angle. The constraints are that eac...

Building a Regex Composer

I was reading the Java project idea described here: The user gives examples of what he wants and does not want to match. The program tries to deduce a regex that fits the examples. Then it generates examples that would fit and not fit. The user corrects the examples it got wrong, and it composes a new regex. Iteratively, you get a re...

Converting prime numbers

Possible Duplicate: Help with algorithm problem from SPOJ Came across this interview question. Given two n-digit prime numbers, convert the first prime number to the second changing one digit at a time. The intermediate numbers also need to be prime. This needs to be done in the minimum number of steps (checking for primality ...

Space complexity question

Possible Duplicate: Regarding in-place merge in an array I have an array, where the first and second half of the array is sorted, e.g. A[] = "2 4 7 1 5 20" No how do I sort the whole array in O(1) space complexity? Regards, Mithun ...

What algorithms are out there for detecting lights and shadows and their parameters?

So I have picture (not the best one) I want to detect where the lights come from and what types of lights are they. What algorithm\framework can do such things with static images? I mentioned shadows because in general if you can separate a shadow from a surface than you can probably determine light type and other its parameters. I me...

selection based on percentage weighting

I have a set of values, and an associated percentage for each: a: 70% chance b: 20% chance c: 10% chance I want to select a value (a, b, c) based on the percentage chance given. how do I approach this? my attempt so far looks like this: r = random.random() if r <= .7: return a elif r <= .9: return b else: return c I'...

Binary Search Trees

This is some code found on wikipedia regarding BST : # 'node' refers to the parent-node in this case def search_binary_tree(node, key): if node is None: return None # key not found if key < node.key: return search_binary_tree(node.leftChild, key) elif key > node.key: return search_binary_t...

Is it possible to output the permutations of 1,...,n using only iterators?

Here a couple of examples in a pseudocode to show what I mean. This produces the combinations (selections disregarding order without repetition) of 1,...,n taking 3 at a time. Do[Print[i,j,k], {i,1...n-2}, {j,i+1...n-1}, {k,j+1...n}] The loop works from left to right---for each i, the iterator j will go through its values and for ea...