algorithm

What algorithm should I use to zoom a graph or map smoothly?

I have a graph, generated by a function, and it zooms itself in and out automatically, depending on the value of the function. I already have the graphing tools and I can display any x,y,width,height at high resolution. I tried just snapping to the right spot: x = target_x y = target_y width = target_width height = target_height But...

Roman representation of integers

Possible Duplicate: How do you find a roman numeral equivalent of an integer I am looking for a simple algorithm (preferably in Python). How to translate a given integer number to a Roman number? string Roman(int Num){...} For example, Roman(1981) must produce "MCMLXXXI". ...

what is the resulting value of this variable?

This is javascript var result = "2" + 5 + 5; what would the value of result be? im guessing the 2 isnt taken into consideration? would it be 210? Thanks ...

Algorithm for RC car...

I'm looking for an algorithm, and I have no idea where to start! I'm trying to get from point A to point B in a cartesian graph. Movement is restricted to that of a RC car: backward, forward, forward-left, and forward-right (constant turning radius; car is either turning completely, or it is not turning at all). How would I construct ...

How can I efficiently calculate the negative binomial cumulative distribution function?

This post is really helpful: http://stackoverflow.com/questions/1095650/how-can-i-efficiently-calculate-the-binomial-cumulative-distribution-function (Title = How can I efficiently calculate the binomial cumulative distribution function?) However, I need the negative binomial cumulative distribution function. Is there a way to tweek ...

How to design a string matching algorithm where the input is the exact string and the lookup values are regex-ish?

This is a design question. Background: We get a web request into our system from many different websites (for a widget that we give out), from which we grab the referrer string (if it exists). We use the referrer to decide on some things within the application. The problem arises in that I need to look at a list of "sites" (urls, partia...

Find a[j]=j in O(log n) time

How can I find if a sorted array has an element a[j]=j in O(log n) time?(no duplicates) ...

Implementing the Hungarian Method as described by Papadimitriou & Steiglitz

If you've implemented the Hungarian Method exactly as given in Figure 11-2 of Combinatorial Optimization: Algorithms and Complexity, did you succeed without altering the pseudo-code in any [significant] way? To be specific, I'm referring to the corrected 1998 Dover edition, which is up-to-date with respect to the errata file dated Octobe...

Fastest way to fit a parabola to set of points?

Hi, Given a set of points, what's the fastest way to fit a parabola to them? Is it doing the least squares calculation or is there an iterative way? Thanks Edit: I think gradient descent is the way to go. The least squares calculation would have been a little bit more taxing (having to do qr decomposition or something to keep things ...

Stack using a queue

I was browsing through some interview questions and stumbled upon this. It got me tearing my hair apart. Does anyone know how to implement a stack using queue?. ...

Deleting a line from a file, reading and rewriting is very inefficient ... can someone come up with a better algorithm?

Hi, Deleting a particular line/certain bytes from a file is very inefficient as there is a lot of reading and writing(re-writing) to be done. Is there anyway we can minimize work in such a process? Imagine if an entire file is a set of linked lists and as a user we know the structure of these linked lists then wouldn't it be wonderful a...

Brute force sudoku solver algorithm in Java problem

Everything seems to work fine in the algorithm besides the solve method. When it executes the program using a solvable Sudoku board, it says that it cannot be solved. I've tried everything I can think of in the solve method. I've tried debugging and it fails after the first row is tested. Any suggestions? Here is the full code so far: ...

Algorithm for finding a set of regions containing a cell

I am working with some spreadsheet data and I have a set of cell regions that are of arbitrary bounds. Given any cell, what is the fastest way to determine the subset of regions which contain the cell? Currently, the best I have is to sort the regions with the primary sort field being the region's starting row index, followed by its en...

Algorithms for testing a poker hand for a straight draw (4 to a straight)?

Hi Folks, I'm in the throes of writing a poker evaluation library for fun and am looking to add the ability to test for draws (open ended, gutshot) for a given set of cards. Just wondering what the "state of the art" is for this? I'm trying to keep my memory footprint reasonable, so the idea of using a look up table doesn't sit well b...

Pseudocode/Java Mystery Algorithm

I have an algorithm, and I want to figure it what it does. I'm sure some of you can just look at this and tell me what it does, but I've been looking at it for half an hour and I'm still not sure. It just gets messy when I try to play with it. What are your techniques for breaking down an algoritm like this? How do I analyze stuff like t...

Tricky algorithm question

Possible Duplicate: Quickest way to find missing number in an array of numbers Input: unsorted array A[1,..,n] which contains all but one of the integers in the range 0,..,n The problem is to determine the missing integer in O(n) time. Each element of A is represented in binary, and the only operation available is the functio...

how to write a simple regular expression pattern matching function in c/c++?

This is a question in my paper test today, the function signature is int is_match(char* pattern,char* string) The pattern is limited to only ASCII chars and the quantification * and ?, so it is relatively simple. is_match should return 1 if matched, otherwise 0. so, how to do, i am really dizzy on this? thanks in advance! ...

Algorithm to find solution to puzzle.

Hello! I am trying to make a game where a player have to find his way from Start to End on the Game Board. As you see this Game Board contains a bunch of red circular obstacles. To win the game the player has to remove a minimum amount of obstacles. So my question is, how do I programatically find out the minimum amount of obstacles t...

Spatial organisation of a group of blocks on a grid

I have a grid of cells (empty at beginning), and a collection of blocks which are rectangles or squares whose size are a multiple of a cell (for example, a block might be 2 cells by 3 cells). I won't know all the blocks in advance, but will have to place them as they arrive. In case anyone's wondering, this has to do with placing a bunch...

Finding Paths in Directed Graph with Greedy Approach With At Least K Nodes and a Given Starting Node

I have a non-weighted DAG graph. What I want to do is to find all the paths in a greedy way and the path should contain at least K nodes, and a given starting node. Is there any existing algorithm/implmentation that does that? For example I have the following graph: my %graph =(36=>[31],31=>[30,22],30=>[20],22=>[20,8],20=>[1],8=>[5],...