PDA

View Full Version : Algorithm of the week/month?



snoop
16th November 2006, 12:11 PM
I was thinking about what would make this forum more active... and I thought of perhaps doing an algorithm of the month or week; I know there are a number of professional programmers and computer science students here that could write worthwhile well documented algorithms every once in a while. And I think it would answer a lot of questions for people that are in CPS classes.

Carnage
20th November 2006, 10:16 AM
sounds like an interesting idea... are we talking new algorithms here or old ones that we discuss?

Earendil
20th November 2006, 06:34 PM
If you make it algorithm of the week, you could get a blend of the two. Have a few weeks focused on discussing known algorithms, and have a few for members to post ones they've written, and have people review them, suggest improvements, and the like?

I'd think it's too much to ask that people generate new algorithms that often, so review of older ones is probably needed.

snoop
24th November 2006, 03:57 PM
There aren't a lot of great new algorithms coming out that many people here would understand. I mean some of the classics, dijkstra, bin sort etc.

Earendil
25th November 2006, 05:37 PM
Well, you could have ones that aren't necessarily new, but just not famous. Like, for my project now I'm going to be writing an algorithm that takes a 2d array of any size and rotates it 90 degrees. That's not really a classic, but it's something that can be put up and discussed.

snoop
25th November 2006, 08:04 PM
well I mean more difficult algorithms...and the classics are kinda important... That one isn't all that hard to do, and is pretty much guaranteed O(N) efficiency. I mean the ones that have a right and wrong ways to do..
here's the solution to that algorithm btw ;P


void invert(char &array, int x_dim, int y_dim) {
int j = 0;
char temparray[y_dim][x_dim];
for (int i = 0; i < x_dim; i++) {
for (j = 0; j < y_dim; j++) {
temparray[j][i] = array[i][j];
}
}
array = temparray;
free(temparray);
}

Earendil
25th November 2006, 08:28 PM
Actually, that didn't work. It rotated it 270 degrees, then flipped it vertically. Close though. And much simpler than... my original way. Which will now be burned.

Anyways, if you're looking to increase activity, it might be better to include easier algorithms for people who are trying to learn, rather than who already know?

snoop
26th November 2006, 09:46 AM
my bad in the assignment make it [i][j] ;p I didn't test the algorithm

Earendil
1st December 2006, 07:41 PM
static boolean[][] rotate(boolean[][] a) {

int size = a[0].length;

boolean[][] temparray = new boolean[size][size];

// Stores rotated values in temparray
for (int i = 0; i < size; i++) {

for (int j = 0; j < size; j++) {
temparray[i][j] = a[j][size - 1 - i];
} // end inner for

} // end outer for

return temparray;
} // end rotate method

Turns out that was the trick.

Anyways... on topic... Someone set this up? I suppose you could just make the thread, and wait for someone else to sticky it.

snoop
3rd December 2006, 12:55 PM
that sounds like it'd probably be the best plan would be to just write one and wait for a sticky.