algorithm

transforming a matrix into a vector along its diagonals

hi guys, im not not a programmer, i just need to solve something numerically in matlab. i need a function to make the following transformation for any square matrix: from row 1: 1 2 3 row 2: 4 5 6 row 3: 7 8 9 to 1 4 2 7 5 3 8 6 9 ie write the matrix in a vector along its diagonals from left to top right. any ideas please? i r...

Which of the following postfix notations correctly represents infix sum 1+2+3+4?

I am testing an infix-to-postfix-to-infix converter and found some kind of uncertainty. For example, a simple infix sum 1 + 2 + 3 + 4 can be converted to postfix one 1 2 + 3 + 4 + assuming that operators with equal precedence are not accumulated. If they are then I get 1 2 3 4 + + + On the other hand, all the following postfix e...

How does index rebuilding happen after a table is updated?

original simple table A ------------------------ rowid id name 123 1 A 124 4 G 125 2 R 126 3 P index on A.id ------------- id rowid 1 123 2 125 3 126 4 124 updated simple table A ---------------------- rowid id name 123 1 A 124 5 G 125 2 R 126 7 P Assumin...

Find the median from a stream of integers

Given an unsorted sequence of integers that flows into your program as a stream. The integers are too many to fit into memory. Imagine there is a function: int getNext() throws NoSuchElementException; It returns the next integer from the stream. Write a function to find the median. Solve the problem in O(n). Any ideas? Hint ...

How to calculate the angle of a vector from the vertical?

Hey, Im trying to find out the angle (in degrees) between two 2D vectors. I know I need to use trig but I'm not too good with it. This is what I'm trying to work out (the Y axis increases downward): I'm trying to use this code at the moment, but it's not working at all (calculates random angles for some reason): private float calcAng...

shortest paths not path in graph

Hi I was wondering if there is an algorithm which would find shortest paths in graph. Let's say that I have a graph where there are couples of path from one vertex to another. Two or more of these paths have the same cost. How can I mark,find etc all shortest paths between these vertices ? As far as I konw Djikstra or Bellman-Ford algori...

How is a table UPDATE handled by a RDBMS?

Suppose I have a table and an index on it original simple table A ------------------------ rowid | id name 123 | 1 A 124 | 4 G 125 | 2 R 126 | 3 P index on A.id ------------- id rowid 1 123 2 125 3 126 4 124 At this point, I execute this DML statement UPDATE A SET id = 5 WHERE id = 4 What e...

Hashing of pointer values

Sometimes you need to take a hash function of a pointer; not the object the pointer points to, but the pointer itself. Lots of the time, folks just punt and use the pointer value as an integer, chop off some high bits to make it fit, maybe shift out known-zero bits at the bottom. Thing is, pointer values aren't necessarily well-distrib...

Does an algorithm exist to convert any number in the Aleph-Null set into the smallest possible computable number?

Possible Duplicate: Programming Logic: Finding the smallest equation to a large number. I'm looking for an algorithm that will take an arbitrary number from the Aleph-Null set (all positive integers)(likely to be absolutely enormous) and attempt to simplify it into a computable number (if the computable number takes up less sp...

Counting placing items in bins according to boolean restrictions

We have a pool of items. Each item has a set of characteristics. Each characteristic is a string, integer, or floating-point number. Each item is also of a particular type. Types are hierarchical. We also have a set of bins. Each bin has a requirement, which is a boolean expression comprised of atomic expressions regarding item cha...

Could someone write a program that print the exactly code of the program

Possible Duplicate: Can a program output a copy of itself Could someone write a program that print the exactly code of the program ...

Help with this algorithm

I have an algorithm that can find if a point is inside a polygon. int CGlEngineFunctions::PointInPoly(int npts, float *xp, float *yp, float x, float y) { int i, j, c = 0; for (i = 0, j = npts-1; i < npts; j = i++) { if ((((yp[i] <= y) && (y < yp[j])) || ((yp[j] <= y) && (y < yp[i]))) && (x...

Library/data structure for handling huge data

I have some huge binary driver logs (around 2-5GB each, and probably around 10x as much after converting them to a readable form) and I need to write a tool that would allow me to sequentially browse, sort, search and filter them effectively (in order to find and resolve bugs). Each log entry has few attributes like: time-stamp, type, m...

Form and movement representation of a hexagonal plane.

The most basic way of representing a quadrile plane (a bunch of squares) is to use a two-dimensional array. In C# we declare this as int[,] and can make our plane as big as we want: string[3,3] => tic-tac-toe board (or similar) string[8,8] => chess or checkers board To "move" an item on the plane, we would just asign it toa new "posi...

how secure is a digital signature?

Digital signature, if I understood right, means sending the message in clear along with a hash of the message which is encrypted using a private key. The recipient of the message calculates the hash, decrypts the received hash using the public key, then compares the two hashes for a match. How safe is this? I mean, you can obtain the ...

Simplified concave-hulls

Problem: Given: n points that are strongly correlated to a 3d k-sided non-convex polygon, where n >> k Find: the best fit concave-hull that matches the original geometry of the points Attempted solutions: Warning: pseudocode segments = [] for each point in image: #segment points into planes via comparing approximate normals ...

Dynamic programming idiom for combinations

Consider the problem in which you have a value of N and you need to calculate how many ways you can sum up to N dollars using [1,2,5,10,20,50,100] Dollar bills. Consider the classic DP solution: C = [1,2,5,10,20,50,100] def comb(p): if p==0: return 1 c = 0 for x in C: if x <= p: c += comb(p-x) ...

QuickSort partition algorithm

Hi, I am trying to program the quicksort algorithm from Cormen Algorithm Textbook. Below is my code. class Quicksort { public void qSort(int[] a, int p, int r) { if(p<r) { int q = Partition(a, p,r); qSort(a, p, q-1); qSort(a, q+1, r); } } private int Partiti...

What's needed for NLP?

Hello, assuming that I know nothing about everything and that I'm starting in programming TODAY what do you say would be necessary for me to learn in order to start working with Natural Language Processing? I've been struggling with some string parsing methods but so far it is just annoying me and making me create ugly code. I'm lookin...

Generate a message out of cutout magazine characters (interview question)

This problem comes out of the dynamic programming chapter in The Algorithm Deisgn Manual by Skiena. Give an algorithm to determine whether you can generate a given string by pasting cutouts from a magazine. You are given a function that will identify the character and its position on the reverse side of the page for any given charac...