algorithm

Simple Python Challenge: Fastest Bitwise XOR on Data Buffers

Challenge: Perform a bitwise XOR on two equal sized buffers. The buffers will be required to be the python str type since this is traditionally the type for data buffers in python. Return the resultant value as a str. Do this as fast as possible. The inputs are two 1 megabyte (2**20 byte) strings. The challenge is to substantially bea...

Where can I find review materials?

I've got interviews coming up for an internship this summer, and I'd like to review common algorithms and data structures so that I won't be caught off guard by any of the technical questions. Can anyone recommend a good resource, online or otherwise, for a refresher on common things like shuffling an array, tree traversal, linked list...

Approaches for using and analyzing set data in time.

I am designing an interactive installation for a gallery where I will receive input telling me which of 8 input transducers have been bridged. For example if someone touches strip number 1, I will be able to detect that. For convenience let's notate that as {1}. If they touch 1 and 2 simultaniously, I will be able to detect that connecti...

How do you determine the best, worse and average case complexity of a problem generated with random dice rolls?

There is a picture book with 100 pages. If dice are rolled randomly to select one of the pages and subsequently rerolled in order to search for a certain picture in the book -- how do I determine the best, worst and average case complexity of this problem? Proposed answer: best case: picture is found on the first dice roll worst case...

Algorithm question: print all the elements on a single given level of a binary tree

Hi, I am required to print out(visit) the nodes on a single level of a binary tree. I don't see how this can be done but then again I not very skilled with algorithms in general. I know that in Breadth-First traversal you use a queue and that you start by putting the root node in the queue then you dequeue it visit it and enqueue it's ch...

Are unescaped user names incompatible with BNF?

Hi all, I've got a (proprietary) output from a software that I need to parse. Sadly, there are unescaped user names and I'm scratching my hairs trying to know if I can, or not, describe the files I need to parse using a BNF (or EBNF or ABNF). The problem, oversimplified (it's really just an example), may look like this: (data) ::= <...

Generic Alpha Beta Search with C++

I'm trying to design a function template which searches for the best move for any game - of course the user of this function template has to implement some game specific functions. What i'm trying to do is to generalize the alpha beta search algorithm with a function template. The declaration of this function template looks like this: ...

how to merge two sorted integer array in place using O(n) time and O(1) space cost

For example, given an integer array and its two consecutive sequence 's beginning position which are 'b1' and 'b2', furthermore provided with the position 'last' which indicates the second sequence's ending position. From array[b1] to array [b2-1] and from array [b2] to array[last] are both in order separately, how to merge them in place...

How to separate object from background in an image?

I have a segmentated image, looks like this: // I am not allowed to post pictures since I am a new member, so only the link: // Turns out I cannot post two hyperlinks either, so I am only going to post the link of the map file. Edit: I believe now I can post images: I also have a map file that clearly shows the segments: Now, wh...

Smallest number that is evenly divisible by all of the numbers from 1 to 20?

I did this problem [Project Euler problem 5], but very bad manner of programming, see the code in c++, #include<iostream> using namespace std; // to find lowest divisble number till 20 int main() { int num = 20, flag = 0; while(flag == 0) { if ((num%2) == 0 && (num%3) == 0 && (num%4) == 0 && (num%5) == 0 && (num%6) == 0 &...

Can anyone explain this algorithm for calculating large factorials?

i came across the following program for calculating large factorials(numbers as big as 100).. can anyone explain me the basic idea used in this algorithm?? I need to know just the mathematics implemented in calculating the factorial. #include <cmath> #include <iostream> #include <cstdlib> using namespace std; int main() { unsig...

Need help with circle collision and rotation? - Game Physics

Ok so I have bunch of balls: What I'm trying to figure out is how to make these circles: Rotate based on the surfaces they are touching Fix collision penetration when dealing with multiple touching objects. EDIT: This is what I mean by rotation Ball 0 will rotate anti-clockwise as it's leaning on Ball 3 Ball 5 will rotate ...

Justifying UIVIews on the iPhone: Algorithm Help

I have been messing around with a way to justify align a collection of UIView subclasses within a containing view. I am having a little bit of trouble with the algorithm and was hoping someone could help spot my errors. Here is pseudocode of where I am now: // 1 see how many items there are int count = [items count]; // 2 figure out ...

Efficient search in a corpus

I am having a few million words which I want to search in a billion words corpus. What will be the efficient way to do this. I am thinking of a trie, but is there an open source implementation of trie available? Thank you -- Updated -- Let me add few more details about what exactly is required. We have a system where we crawled news...

Algorithm to merge two lists lacking comparison between them

I am looking for an algorithm to merge two sorted lists, but they lack a comparison operator between elements of one list and elements of the other. The resulting merged list may not be unique, but any result which satisfies the relative sort order of each list will do. More precisely: Given: Lists A = {a_1, ..., a_m}, and B = {b_1, ....

min-conflicts Algorithm to Solve N-Queen Proplem

using nQueens problem how to translate this algorithm to java code function MIN-CONFLICTS(csp,max_steps) returns a solution or failure inputs: csp, a constraint satisfaction problem max_steps,the number of steps allowed before giving up current<-- an initial assignment for csp for i=1 to max_steps do if cur...

Algorithm to determine possible groups of items.

I am scratching my head trying to do this and it's eating me up. I know it is not THAT complex. I have a number of items, this number can be equal or greater than three. Then I need to determine the possible combination of group of items that will complete the total. The only restriction it's that the groups should have three or more ite...

Minimize RMSD between two sets of points

I need to plot the transformation of a 3d object against time. I have the 3d shapes for each moment in time, but they are not guaranteed to be geometrically well placed, so I cannot just render them and slap the pictures together into a movie. I therefore need to align them so that they are pleasantly and consistently oriented with respe...

Cardinal direction algorithm in Java

This weekend I spend a few minutes thrashing together an algorithm that would take in a heading (in degrees) and return a String for the cardinal direction (I'm using it in an android compass application I'm using). What I ended up with was this: private String headingToString(Float heading) { String strHeading = "?"; Hashtable<...

Update position of a point

Hi all. My problem is this: I have a set of points in 3D space, and their positions are updated from time to time with a certain velocity. But i need to keep a minimal distance between them. Can you help me with this? EDIT: I am using C for the implementation of the algorithm. Thanks in advance. ...