algorithm

Extension of Binary search algo to find the first and last index of the key value to be searched in an array.

The problem is to extend the binary search algorithm to find all occurrences of a target value in a sorted array in the most efficient way. Concretely speaking, the input of the algorithm are (1) a sorted array of integers, where some numbers may appear more than once, and (2) a target integer to be searched. The output of the algorithm...

Tetravex solving algorithm

Well, i was thinking of making a Tetravex solving program in order to practice my code writing skills (language will propably be Visual Basic) and I need help finding an algorithm for solving it. For those that don't know what tetravex is see this http://en.wikipedia.org/wiki/TetraVex . The only algorithm I can come up with is the brute ...

Duplicate image detection algorithms?

I am thinking about creating a database system for images where they are stored with compact signatures and then matched against a "query image" that could be a resized, cropped, brightened, rotated or a flipped version of the stored one. Note that I am not talking about image similarity algorithms but rather strictly about duplicate det...

AI: selecting immediate acceleration/rotation to get to a final point

I'm working on a game where on each update of the game loop, the AI is run. During this update, I have the chance to turn the AI-controlled entity and/or make it accelerate in the direction it is facing. I want it to reach a final location (within reasonable range) and at that location have a specific velocity and direction (again it doe...

Determining if a sphere intersects an object or not

Hello everyone, I have a closed object described by a surface representation of triangles (described by three vertices which forms a right hand rule with a normal pointing to the "outside" of the object). I place a sphere of some radius in 3D space somewhere close to the surface of the object. I want to determine if the sphere intersec...

How do you efficiently debug reference count problems in shared memory?

Assume you have a reference counted object in shared memory. The reference count represents the number of processes using the object, and processes are responsible for incrementing and decrementing the count via atomic instructions, so the reference count itself is in shared memory as well (it could be a field of the object, or the objec...

Longest path approximation algorithm from a given node

Hi guys! I'm looking for an approximation algorithm for the following problem - I have an unweighted, undirected graph, with cycles, and want to find the longest path starting from a given node. I do value speed over performance (so a O(n^5) algorithm would probably be an overkill). This is not homework (I swear!) or work related, but ...

The Genuine Sieve of Eratosthenes -- algorithm used to generate prime numbers.

Today I read a paper: O'Neill, Melissa E., "The Genuine Sieve of Eratosthenes", Journal of Functional Programming, Published online by Cambridge University Press 09 Oct 2008 doi:10.1017/S0956796808007004. It described an algorithm of generating prime number by using Priority Queue : sieve [] = [] sieve (x:xs) = x : sieve...

Algorithm(s) for spotting anomalies ("spikes") in traffic data

I find myself needing to process network traffic captured with tcpdump. Reading the traffic is not hard, but what gets a bit tricky is spotting where there are "spikes" in the traffic. I'm mostly concerned with TCP SYN packets and what I want to do is find days where there's a sudden rise in the traffic for a given destination port. Ther...

Python sort parallel arrays in place?

Is there an easy (meaning without rolling one's own sorting function) way to sort parallel lists without unnecessary copying in Python? For example: foo = range(5) bar = range(5, 0, -1) parallelSort(bar, foo) print foo # [4,3,2,1,0] print bar # [1,2,3,4,5] I've seen the examples using zip but it seems silly to copy all your data from...

mergesort beginner question

Dear all, I now have a question on Mergesort algorithm.Because in the original algorithm,the list to be sorted is diveded into two sublists and sort recursively. Now how about I want to divide the list of lengh n into 3 sub-lists of lengh n/3,and then sort these three sublists recursively and then combine? I just simply modify the origin...

Strategy to implement tree traversing algorithm in parallel?

I have implemented an iterative algorithm, where each iteration involves a pre-order tree traversal (sometimes called downwards accumulation) followed by a post-order tree traversal (upwards accumulation). Each visit to each node involves calculating and storing information to be used for the next visit (either in the subsequent post-or...

Trying to calculate Pi to N number of decimals with C#.

Note: I've already read this topic, but I don't understand it and it doesn't provide a solution I could use. I'm terrible with number problems. What's a simple way to generate Pi to what number of decimals a user wants? This isn't for homework, just trying to complete some of the projects listed here: Link ...

Speclialized hashtable algorithms for dynamic/static/incremental data

I have a number of data sets that have key-value pattern - i.e. a string key and a pointer to the data. Right now it is stored in hashtables, each table having array of slots corresponding to hash keys, and on collision forming a linked list under each slot that has collision (direct chaining). All implemented in C (and should stay in C)...

Algorithm for pattern matching

Background I am designing an application which will convert text from one language to other. For example, input text hello will be converted to specified language text. This is done by having a lookup table for each language. Conversion algorithm has the following steps. Looks for exact match. The whole word hello will be the pattern....

Algorithm for sorting a nested/adjecency model in Ruby

I've been trying to find a good way of doing this, either on the client side in Javascript or at the last minute within the server. This is a Rails application but it is a pretty generic question. I have a model that is hierarchical, and is currently stored in a nested set model. The model then has: parent_id, lft, and rgt I would lik...

What's the best way to dedupe a table?

I've seen a couple of solutions for this, but I'm wondering what the best and most efficient way is to de-dupe a table. You can use code (SQL, etc.) to illustrate your point, but I'm just looking for basic algorithms. I assumed there would already be a question about this on SO, but I wasn't able to find one, so if it already exists just...

Fractional Counting Via Integers

I receive an integer that represents a dollar amount in fractional denominations. I would like an algorithm that can add those numbers without parsing and converting them into doubles or decimals. For example, I receive the integer 50155, which means 50 and 15.5/32 dollars. I then receive 10210 which is 10 and 21/32 dollars. So 50 15...

How do I implement a sort of a head to tail list?

Given the following inputs: (note: this is not a linked list, it's all one string output from a web app that I don't have control over) DAVSCAF1WD6-11 ==> MOTENVF1WD6-11 MOTENVF1WD6-11 ==> WNDVUTF1WD4-11 TPKAKSF1WD6-11 ==> KSCYMOF1WD6-11 WNDVUTF1WD3-11 ==> WGTNUTF1WD2-11 DNVRCOF1WD7-11 ==> BELTKSF1WD3-11 SNFCCAF1WD6-16 ==> DAVSCAF1WD...

Production code for finding junction in a linked list

Hi all, I was asked this question in some interview. I was required to write code for finding junction in a linked list (which is in form of Y with both arms not necessarily equal) for production environment in O(1) space and linear time. I came up with this solution (which i had previously seen somewhere) : 1. Measure lengths of both l...