algorithm

Graph drawing algorithms - I'm trying to render finite state automata

I want to write something that will draw finite state automata. Does anyone know any algorithms that are related to this? EDIT: I should mention that I know about graphviz. I want to build my own draw program/function, so what I'm looking for is some more theoretical stuff/pseudo-code for algorithms. ...

If Desktop Computers were 1024 times faster what kind of software would we be writing?

Continuing along current trends we can expect our algorithms to run many times faster on Desktop Computers in 10 years (let's pick a number) 1024x faster. Do you know of any algorithms that are within 1024 times of running on average Desktop Systems and that would dramatically change the kinds of software we can write there? I have my ...

Pixel Drawing Algorithm

I need an example algorithm that will draw pixels one at a time on a grid based (x,y) system, and also color them based on an rbg value based on binary data that is provided in some form. I am looking for anything written in php or a php like language such as C, but that does not use any sort of library or graphics card api, as i am codi...

What should I use as a check digit algorithm for a base 31 value?

I'm using the following set of values to create a 9 character long base 31 value: 0123456789ABCDEFGHJKLMNPQRTUWXY I was looking at modifying the Luhn algorithm to work with my base. My question is: In base 10, the Luhn algorithm doubles each value in an even position and then if the result is >10 the individual digits of the result ar...

Removing duplicates from 2d array in Javascript

What would be a nice algorithm to remove dupes on an array like below... var allwords = [ ['3-hidroxitiramina', '3-hidroxitiramina'], ['3-hidroxitiramina', '3-hidroxitiramina'], ['3-in-1 block', 'bloqueo 3 en 1'], ['abacterial', 'abacteriano'], ['abacteriano', 'abacteriano'], ['abciximab', 'abciximab'],...

Identify this Algorithm: Slots and Pegs

I have a number of slots and pegs arranged in a straight line. The pegs can be moved and need to be moved to a slot each. A slot can be left empty only if all pegs are taken. When a peg is moved, it is not allowed to go past another peg. In other words the order of the pegs must be maintained. Preferably, the total distance moved by all ...

Efficient solution for a special assignment problem

Given: -A set of items that each have costs for being placed into a given container type. -A set of container types that each have a number of available containers. Example: Amount*Container-Type : 5 * A, 3 * B, 2 * C Items(Costs) : 3 * X (A=2, B=3, C=1) 2 * Y (A=5, B=2, C=2) 1 * Z (A=3, B=3, C=1) Problem: Find the best placem...

Find subset totals for huge data set

Hi all, 1st of all: I'm not a programmer, never learnt programming/algorithms. Actually I have to program, mostly in awk, or ruby, some bash. In today's task, I have a huge data set (float numbers) in a plain text file, one record/line, and a sum of all numbers of the set, but the sum is wrong, because some of the numbers (can be only...

Calculate final scores in a game relative to previous scores and other players.

Supposing a multi-player game, what you be the fairest way give final scores based on the previous scores of all players. For example, in a two player match, player A having two times the score of player B. "A" finishing first would not give him a lot of points; finishing last, he would lose quite a lot of points. ...

Creating a linear gradient in 2D array

I have a 2D bitmap-like array of let's say 500*500 values. I'm trying to create a linear gradient on the array, so the resulting bitmap would look something like this (in grayscale): The input would be the array to fill, two points (like the starting and ending point for the Gradient tool in Photoshop/GIMP) and the range of values whic...

How do I generate non overlapping circles in a fixed region?

What's the best way to generate a known number of non overlapping fixed radius circles in a limited space? ...

What is the state of the art in computer chess tree searching?

I'm not interested in tiny optimizations giving few percents of the speed. I'm interested in the most important heuristics for alpha-beta search. And most important components for evaluation function. I'm particularly interested in algorithms that have greatest (improvement/code_size) ratio. (NOT (improvement/complexity)). Thanks. PS ...

Permutation of a vector

Hello, suppose I have a vector: 0 1 2 3 4 5 [45,89,22,31,23,76] And a permutation of its indices: [5,3,2,1,0,4] Is there an efficient way to resort it according to the permutation thus obtaining: [76,31,22,89,45,23] Using at most O(1) additional space? ...

Replace 2 strings at the same time?

hello how can I replace 2 strings in the same time? for example let's say I have string like this: str1 = "AAAA BBBB CCCC DDDD" i want to replace every "AAAA" with "CCCC" and every "CCCC" with "AAAA" but if i did: str1.gsub("AAAA","CCCC") # CCCC BBBB CCCC DDDD str1.gsub("CCCC","AAAA") # AAAA BBBB AAAA DDDD what I want str1 to be "C...

How to store a hash table in a file?

How can I store a hash table with separate chaining in a file on disk? Generating the data stored in the hash table at runtime is expensive, it would be faster to just load the HT from disk...if only I can figure out how to do it. Edit: The lookups are done with the HT loaded in memory. I need to find a way to store the hashtable (in m...

Fast min on span

Given a list of arrays and lots of setup time I need to quickly find the smallest value in some sub-span of each array. In concept: class SpanThing { int Data; SpanThing(int[][] data) /// must be rectangulare { Data = data; //// process, can take a while } int[] MinsBruteForce(int from, int to...

Equal sum subsets hybrid

The problem is the following: You are given a set of positive integers { a1 , a2 , a3 , ... , an } in which there are no same numbers ( a1 exists only once ,a2 exists only once,...) eg A = {12 , 5 ,7 ,91 }. Question: Are there two disjoint subsets of A , A1 = { b1,b2,...,bm } and A2 = { c1,c2,...,ck} so that b1+b2+...+bm = c1+c2+.....

Probability distribution in Python

I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module that I could use, else I...

Cycles in an Undirected Graph

Given an undirected graph G=(V,E) with n vertices ( |V| = n ), how do you find if it contains a cycle in O(n) ? ...

How to calculate the number of operations that occur during the execution of a for loop?

I had an exam a couple of days ago and today the Instructor gave us the key answer of the exam. One of the questions was for ( j = 9; j >= 1; j-- ) Count the Number of operations The result was 20. Can anyone explain how he gets 20 operations from that? ...