[algogeeks] Re: a tree problem

2006-02-24 Thread Gene
What are the rules for the rest of the steps/rounds? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this

[algogeeks] Re: A Definiton of an Algorithm

2006-02-21 Thread Gene
At best this is closed-minded. At worst it's ignorant. There are lots of cases where adding some formalism to intuitive notions has produced wonderful new insights. Take for example the denotational semantics of recursive definitions (or loops if you prefer). These were obvious just as you

[algogeeks] Re: Gerrymandering

2006-02-21 Thread Gene
I hope this isn't homework. This is can be solved with a DP roughly similar to the classic one for subset sum. Let X and Y be the districts. Use a 4d table of booleans G. G(i,x,y,p) is true iff there is an assignment of precincts P(1)...P(i), with p in X and i-p in Y, and with x and y gnu

[algogeeks] Re: A Definiton of an Algorithm

2006-02-20 Thread Gene
You must think about types in a more general sense that traditional programming language types: as values that satisfy a predicate. Then if the predicate is allowed to be a recursive function, you get your definition. --~--~-~--~~~---~--~~ You received this

[algogeeks] Re: strlen's algorithm

2006-02-20 Thread Gene
This is highly optimized code that in the normal case loads 4 bytes at a time, checks if any of the 4 is z a null (0) and handles accordingly. If the string doesn't start on a 4-byte boundary, the str_misaligned counts 1, 2, or 3 characters until a null or alignment boundary is found. The

[algogeeks] Re: Cormen Problem

2006-02-15 Thread Gene
This is the idea my code used, though I kept track of the start of the array with a pointer and the end with an integer length. You seem to imply that the median of an array is always a single element (at n1 or n2). Care is necessary when the lengths of the arrays are even. In this case the

[algogeeks] Re: dynamic programming in tree

2006-02-01 Thread Gene
I fear this problem is NP hard.

[algogeeks] Re: Recursion in blobs

2006-01-26 Thread Gene
You can think of the grid as a (possibly disconnected) undirected graphs where each filled grid square is a vertex connected by edges to its neighboring filled squares. Then the algorithm is a depth-first search. This is obviously O(n) where n is the number of _filled_ squares.

[algogeeks] Re: longest common subsequence problem

2006-01-24 Thread Gene
In perl (hopefully the homework has been due already)... use strict; our %memo; sub lcs { my ($x, $y) = @_; my $key = $x|$y; return $memo{$key} if defined $memo{$key}; my $s = ''; for (my $i = 0; $i length($x); $i++) { for (my $j = 0; $j length($y); $j++) { if

[algogeeks] Re: algorithm to identify number from 0-16384 having at most 4 1s in its binary number

2006-01-23 Thread Gene
Several. You can compute all possible ways to arrange four 1s in a field of 14 bits. for (i = 1; i (1 (14 - 3)); i = 1) for (j = i 1; j (1 (14 - 2)); j = 1) for (k = j 1; k (1 (14 - 1)); k = 1) for (m = k 1; m (1 (14 - 0)); m = 1) printf(%d , i | j | k | m);

[algogeeks] Re: Cashbox withdrawal

2006-01-06 Thread Gene
A friend of mine says that with the cash box given he can prove that the greedy approach always works EXCEPT that if the greedy algorithm would select an ODD number N of 500's, 50's 5's, or 0.25s, then the algorithm must also try N-1 of the same denomination. This is because they are congruent

[algogeeks] Re: Cashbox withdrawal

2006-01-04 Thread Gene
Your algorithm does not show how to select di. If you pick the smallest possible denomination first, then consider S=6 with a cash box of 2 x 1 1 x 5 The algorithm will pick both 1's and then fail because all that's left is the 5. If you pick the largest possble di then try S=60 with a cash box

[algogeeks] Re: Cashbox withdrawal

2006-01-04 Thread Gene
Indeed di-1 mod di = 0 is sufficient to make the greedy algorithm work, but 50 mod 20 = 10!

[algogeeks] Re: towers of hannoi

2005-11-24 Thread Gene
Turns out this is one of the programs where a great deal of simplification is possible. The first thing to note is that the second call in the original program is tail recursive; it is followed immediately by a return. For such calls, saving params on the stack is unnecessary because they are

[algogeeks] Re: Reverse Doubling List is there an alias?

2005-11-20 Thread Gene
It would make a nice homework question in an undergraduate data structures course, and there might be some applications where it performs marginally better than the standard approach, which is a single pointer to a single array. To grow the array, allocate new memory twice as large as the

<    1   2   3   4   5