Tuesday, March 22, 2011

recursion

just trying to blog

Well today was an interesting day because with that snowy rain and thats it 4 the day. this is my 1st time doin this so excuse me 4 messing up with anything.

What we learned in class today was about recursion, but it was at the last 10 minutes of class because all of us were doing the jumper project. From Mr. Jacoby recursion is a strategy for solving problems by
repeatedly reducing them to simpler problems.

For example: factorials
5! = 5 x 4!
4! = 4 x 3!
3! = 3 x 2!
2! = 2 x 1!
So from what i got the lower u go the more u can understand what is the answer.
Also that the repitition of it would eventually end it up being easier to do by that every time it recur it would repeat and then the simplest form and then from there go forwards then u should be able to get your answer.

Recursive problems are broken down into two cases

line 1. The base case: the simplest case where no computation is necessary.
line 2. The recursive case: everything else - brings us to closer to the base case. It simplifies or reduces the problem.

                        public int factorial(int n) {
line 1:                           if (n == 0) return 1;
line 2:                           return n * factorial(n ‐ 1);
                        }


All loops can be written recursively though its not a good idea! 

No comments:

Post a Comment