Henry Wong wrote:
When it comes to recursion, I am definitely *not* a fan of learning by example.
If you look at a solution, in my opinion, at best, you just learn how that solution works. And if you are unlucky, you only think you know how it works.
Recursion requires a way of thinking out the problem. And if you never try to figure it out, with the easy examples, how can you do the hard ones? You need to mentally exercise your recursion muscles, on the easy problems, to be strong enough for the hard ones.
Henry
Rene Rad wrote:
Fred Hamilton wrote:
Rene Rad wrote:I think I get it.
Does x.length ALWAYS start at 1? If so I guess I should never use '(or)equals to' but rather always less than.
Is this correct?
the issue is that array indexes start at 0. if the array has length 10, then we have elements numbered 0,1,2,3,4,5,6,7,8,9.
Count em. There's 10 numbers there.
I understand that, 0 is still a number. does .length always start at 1?
Rene Rad wrote:I think I get it.
Does x.length ALWAYS start at 1? If so I guess I should never use '(or)equals to' but rather always less than.
Is this correct?
Matt Cartwright wrote:just wondering ..
java.awt.geom.Point2D distanceSq(Point2D point)
Distance Formula
M
Alec Lee wrote:Thanks. I am working hard to recall my math knowledge. I show what I've done and see if it is correct or not:
Assuming the point is (xp,yp), then
From 2 point form I get the equation of the line as: (yp-y1)^2 * (x1-x2)^2 = (xp-x1)^2 * (y1-y2)^2 ......(1)
(I took square of the equation for easy substitiion with my 2nd equation)
From distance between 2 point formula: d^2 = (yp-y1)^2 + (xp - x1)^2 .......(2)
And, now it is 2 equations with 2 unknown. It could be solved by eliminiation. Since, I got (yp-y1)^2 in both equations, I can take the one in (2) and substitute it into (1) to get xp. And with xp known I just find yp from (1).
Is that correct?