07 November 2004 - java_dev (original) (raw)

| | 05:37 pm - reuptake Hi everyone! In my Java class right now, we're doing iteration and recursion. One part of our assignment is to compute the Greatest Common Denominator in a small program -- both iteratively and recursively.These are the specifications of the assignment: public static long recursive (long a, long b). In this exercise, your task is to implement an algorithm recursively. The recursive definition is: If either a<0 or b<0, then their GCD is the same as the GCD of their absolute values. Otherwise, if b==0, then their GCD is a. Otherwise, their GCD is the GCD of b and the remainder of a after division by b, in that order. public static long iterative (long a, long b). Now, examine the recursive definition above and determine how to re-implement it as a loop. Then, write that implementation in this method. Now, I've written my code, and it compiles fine. However, I'm not quite sure if I'm coding it in the way the assignment wants, especially with this: "Otherwise, their GCD is the GCD of b and the remainder of a after division by b, in that order. " I'm also not quite sure if my program works well when tested with negative numbers. If you wouldn't mind, can you take a look at my code and tell me about any glitches in it? :) I would appreciate it so much! Thanks!**( Code behind the cutCollapse )**I'm having a pretty hard time in Java. Was anyone else completly confused when first learning Java? What helped you master it? | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| | 11:35 pm - battie42 - The math behind sort methods Hi again. I'm having a bit of trouble understanding my current programming project. I have to test out different sort methods by finding the times it takes to sort arrays ordered in different ways with varying number of integers. Then I make tables and graphs the results in a bajillion different ways.That's all fine, if not agonizingly tedious. But next I have to discuss something my professor calls the Big O of the sorts. This is where I'm getting hung up. I have three sorts on the order of N^2 : Bubble, Selection Exchange, and Insertion. I also have three on the order of N*Ln(N). Then there is the shell sort, which apparently is something else entirely.So far I learned that the the N^2 searches require a good long novel to sit through, while the NlnN sorts are nice and fast. What I don't understand is why. I tried going through the code for the sorts, but it's written in a different syntax so I can't really understand it. I also don't understand how to tell what the order is (and since I can't read the code, how can I)?If anything I just said made any sense, could someone give me a hint? I'd really appreciate it. | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |