algorithm

lalr(1) action table algorithm

Hi Could someone describe the algorithm to generate the needed tables (action, goto) from a given grammar for LALR(1)? I have already read http://en.wikipedia.org/wiki/LALR%5Fparser http://en.wikipedia.org/wiki/LR%5Fparser Edit Finally I found out some interesting related pages in the dragon book, but whoever wants, can answer the...

String Find/Replace Algorithm

I would like to be able to search a string for various words, when I find one, i want to split the string at that point into 3 parts (left, match, right), the matched text would be excluded, and the process would continue with the new string left+right. Now, once i have all my matches done, i need to reverse the process by reinserting t...

What is the best way to go about writing a simple x86 assembler?

I'm interested in writing an x86 assembler for a hobby project. At first it seemed fairly straight forward to me but the more I read into it, the more unanswered questions I find myself having. I'm not totally inexperienced: I've used MIPs assembly a fair amount and I've written a toy compiler for a subset of C in school. My goal is...

How can I optimize a multiple (matrix) switch / case algorithm?

Is it possible to optimize this kind of (matrix) algorithm: // | case 1 | case 2 | case 3 | // ------|--------|--------|--------| // | | | | // case a| a1 | a2 | a3 | // | | | | // case b| b1 | b2 | b3 | // | | | | // c...

Are there resources about logistics?

I couldn't find any complex resources in Google. Maybe the key words that I used were wrong. I am interested in web-sites, book titles, book authors etc.. I'm looking general theory. UPD: Previous title of the question was: "Are there resources about transport scheduling?". ...

Solving a game using two 3x3 matrices

Hi I have two 3x3 matrices. One representing the actual state and the other in a "current" state. Actual state -> 1,2,3 5,7,6, 9,8,x Current state1 -> 3,1,2 x,6,7 8,9,4 I need to bring the current state matrix to the original state by doing only swaps of element x a...

How do I convince a peer that algorithms are important?

A peer of mine is working on a report that displays the weekly (Sunday to Saturday) advance of every employee in our small consultancy firm. There's a piece of code he wrote that shows the columns corresponding to the days in the target week. His algorithm is the following: Get which day of the week the first day of the month is. If it...

What's a good multi-core 64-bit "Hello World" program?

I recently got my home PC upgraded to a quad-core CPU and 64-bit OS. I have some former experience with C/C++ and I'm really "itching" to try exercising some 64-bit CPU capabilities. What's a good "Hello World" type program that demonstrates 64-bit multi-core capabilities by doing some simple things that don't work well at all in 32-bit ...

List implemented using an inorder binary tree

For the new computer science assignment we are to implement a list/array using an inorder binary tree. I would just like a suggestion rather than a solution. The idea is having a binary tree that has its nodes accessible via indexes, e.g. t = ListTree() t.insert(2,0) # 1st argument is the value, 2nd the index to insert at t.get(0) # ...

How do I partition a bipartite graph by color?

For instance, suppose I have a graph G = (V, E) where V = {A, B, C, D} E = {(A, B), (A,D), (C, D)} This graph is bipartite, and thus can be split into two disjoint sets {A, C} and {B, D}. My first guess is that I can simply walk the graph and assign alternating colors to each vertex. Is this the case, or is it more complicated/simple...

How CSS and DOM is implemented in the browser?

This is a pretty academic question. I'm wondering how the browser is implemented as in what data structure or algorithm is used to map a CSS selector to a particular DOM element. Is it accomplished through a hash table? How does DOM child node knows that the style applied to parent also applies to itself etc. I've been looking at Moz...

Transforming multiple iterator elements

My problem is more complex than this, so I've narrowed it down to a very simple example that would show me enough to know how to handle the rest. Say I have an input iterator. I want make a new input iterator derived from it, where each element is the combination of multiple sequential elements of the original input with the following p...

Algorithm for generating huge wordlist

Alright, I know this is going to sound bad, like I'm going to use this for un-ethical things, but you have my word that I am not. I am writing a paper for my Computer and Information Security course and the topic I chose was hashing methods. One of the points that I go over in my paper is MD5 being only one-way and the only way to crack...

Where to learn about enemy game algorithms (like Starcraft/Warcraft)?

I would like to learn about games (strategy) algorithms especially about how do enemies algorithms works ? Is there any good place for beginners? ...

How to get the greatest difference among a list of ordered numbers in PHP?

For example, 1,3,6,8,11,45,99 The interval between numbers is: 2,3,2,3,34,54 So the greatest difference is 54. How to implement this function? function get_greatest_diff($arr_of_numbers) {} ...

How can I turn a floating point number into the closest fraction represented by a byte numerator and denominator?

How can I write an algorithm that given a floating point number, and attempts to represent is as accurately as possible using a numerator and a denominator, both restricted to the range of a Java byte? The reason for this is that an I2C device wants a numerator and denominator, while it would make sense to give it a float. For example,...

What is breadth-first search useful for?

Usually when I've had to walk a graph, I've always used depth-first search because of the lower space complexity. I've honestly never seen a situation that calls for a breadth-first search, although my experience is pretty limited. When does it make sense to use a breadth-first search? UPDATE: I suppose my answer here shows a situati...

Quickest way to determine if a 2D array contains an element?

Let's assume that I've got 2d array like : int[,] my_array = new int[100, 100]; The array is filled with ints. What would be the quickest way to check if a target-value element is contained within the array ? (* this is not homework, I'm trying to come up with most efficient solution for this case) ...

algorithms to evaluate user responses

I'm working on a web application which will be used for classifying photos of automobiles. The users will be presented with photos of various vehicles, and will be asked to answer a series of questions about what they see. The results will be recorded to a database, averaged, and displayed. I'm looking for algorithms to help me identify...

Designing a grid overlay based on longitudes and latitudes

I'm trying to figure out the best way to approach the following: Say I have a flat representation of the earth. I would like to create a grid that overlays this with each square on the grid corresponding to about 3 square kilometers. Each square would have a unique region id. This grid would just be stored in a database table that would...