algorithm

Creating dynamic maps on the web

My company uses a sales model of dealers, territory managers and regional managers, each with a different level of area scope (IE manage based on zips codes, states, or regions.) I want to create a slimmed down map that is similar to this US state map that would allow our users to manipulate who manages what. What are some good resourc...

Which is faster, Hash lookup or Binary search?

When given a static set of objects (static in the sense that once loaded it seldom if ever changes) into which repeated concurrent lookups are needed with optimal performance, which is better, a HashMap or an array with a binary search using some custom comparator? Is the answer a function of object or struct type? Hash and/or Equal fu...

path-finding through smoke

I once found a paper on path finding through a simulation that involved smoke(fluids in general). Has anyone read anything like this ? I can't remember the name of the paper or the author. If you know a paper like this please tell me ...

ISO 9797-1 Algorithm 1 [CBC-MAC] in C#

It seems that there're 6 variations to CBC-MAC algorithm. I've been trying to match the MAC algorithm on the PINPad 1000SE [which per manual is ISO 9797-1 Algorithm 1]. I got an excellent start from here. And I coded the algorithm as below: public static byte[] CalculateMAC(this IPinPad pinpad, byte[] message, byte[] key) { //Div...

"Plumber" Programmers vs. Computer Scientists

I'm a self taught programmer pushing 40 years old, and a self admitted "plumber programmer" that relies pretty heavily on APIs. I slowly play catch up on my understanding of how to properly implement data structures and algorithms, Big(O), etc., but find that my lack of Math background ends up preventing me from understanding some of the...

Are nested intervals a viable solution to nested set (modified pre-order traversal) RDBMS performance degredation?

Among the known limitations of Joe Celko's nested sets (modified pre-order traversal) is marked degredation in performance as the tree grows to a large size. Vadim Tropashko proposed nested intervals, and provides examples and theory explanation in this paper: http://arxiv.org/html/cs.DB/0401014 Is this a viable solution, are there any...

Representing sparse integer sets?

What is a good way to represent sparse set of integers (really C memory addresses) in a compact and fast way. I already know about the obvious things like bit-vectors and run-length encoding. but I want something much more compact than one word per set element. I need to add and remove elements and test for membership. I do not need othe...

Algorithm for "nice" grid line intervals on a graph

I need a reasonably smart algorithm to come up with "nice" grid lines for a graph (chart). For example, assume a bar chart with values of 10, 30, 72 and 60. You know: Min value: 10 Max value: 72 Range: 62 The first question is: what do you start from? In this case, 0 would be the intuitive value but this won't hold up on other data ...

Python Canvas

I'm looking for a Python library for creating canvases for manipulating gemetric shapes. Specifically I need the ability to create arbitrary polygons and place them on the canvas, the polygons need to have the ability to be transparent/have an alpha channel, I need to be able to edit polygons that are currently on the canvas, and I need...

Hole in a Polygon

I need to create a 3D model of a cube with a circular hole punched at the center of one face passing completely through the cube to the opposite side. I am able to generate the vertices for the faces and for the holes. Four of the faces (untouched by the hole) can be modeled as a single triangle strip. The inside of the hole can also be...

Average time complexity of quicksort vs insertion sort

I'm lead to believe that quick sort should be faster than insertion sort on a medium size unorderd int array. I've implemented both algorithms in java and I notice quicksort is significantly slower then insertion sorrt. I have a theory: quiksort is being slower because it's recursive and the call it's making to it's own method signat...

Paths in undirected graphs

We are given an undirected graph G = (V, E) and two vertices s, t ∈ V . We consider simple paths between s and t. A path is simple if every vertex is visited at most once. Are the following in P or NP-complete? Does an efficient algorithm polynomial time exist for the following? "n" represents the number of vertices in the graph "V" ...

Are there algorithms for increasing resolution of an image?

Are there any algorithms or tools that can increase the resolution of an image - besides just a simple zoom that makes each individual pixel in the image a little larger? I realize that such an algorithm would have to invent pixels that don't really exist in the original image, but I figured there might be some algorithm that could inte...

Algorithm for finding the smallest power of two that's greater or equal to a given value

I need to find the smallest power of two that's greater or equal to a given value. So far, I have this: int value = 3221; // 3221 is just an example, could be any number int result = 1; while (result < value) result <<= 1; It works fine, but feels kind of naive. Is there a better algorithm for that problem? EDIT. There were some nic...

Map RSS entries to HTML body w. non-exact search

How would you solve this problem? You're scraping HTML of blogs. Some of the HTML of a blog is blog posts, some of it is formatting, sidebars, etc. You want to be able to tell what text in the HTML belongs to which post (i.e. a permalink) if any. I know what you're thinking: You could just look at the RSS and ignore the HTML altogether...

64 bit division

Hi, Can anyone send me a c code to divide 2 64bit numbers. My compiler only supports 32/32 division. Thanx & Regards Mani ...

Resources and tutorials to get started on algorithms

I'm interested in learning about algorithms, both conceptually and practically, as a beginner. I want to learn about binary search trees and similar. What tutorials and example programs, preferably in Python or Java, will help me? ...

Generating random fixed length permutations of a string

Lets say my alphabet contains X letters and my language supports only Y letter words (Y < X ofcourse). I need to generate all the words possible in random order. E.g. Alphabet=a,b,c,d,e,f,g Y=3 So the words would be: aaa aab aac aba .. bbb ccc .. (the above should be generated in random order) The trivial way to do it would be to gene...

Flood Fill Algorithms

Its the weekend again, and that means I get to play with my hobby project. I've gotten tired of creating test levels by hand, so I thought I'd take a break from engine development and work on a level editor: I'd like to implement a flood fill algorithm in the editor, which would work just like in a paint program. Does anyone have any...

Detecting infinite loop in brainfuck program

I have written a simple brainfuck interpreter in MATLAB script language. It is fed random bf programs to execute (as part of a genetic algorithm project). The problem I face is, the program turns out to have an infinite loop in a sizeable number of cases, and hence the GA gets stuck at the point. So, I need a mechanism to detect infinite...