Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Tom Cameron

Ranch Hand
+ Follow
since Apr 30, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tom Cameron

interesting... so I guess it would depend on the problem. I'm not really sure what you mean by asymptotic analysis though. Thanks for a speedy reply.
12 years ago
Hi it's me again. I was thinking about recursion again, (new to it) and I was thinking about the Big O notations for recursive methods. So, my big question, are recursive methods generally a lot slower than regular methods? Sometimes it seems to be easy to implement but it is making the computer repeat itself several times.

Let's take an easy example to clear my mind up: if I were to reverse some string, I would normally write a for loop and a charAt method to reverse the whole thing, thus it is O(n) but if I were to use recursion such that I am always printing out the character at one end and then cut off that same ending character of the string recursively, wouldn't it also be O(n) ? Sometimes I think recursion would have more "complexity" than that. Or if I'm wrong, please correct me since I'm just thinking.
12 years ago
I found out my problems and properly fixed my base case (correctly this time).

Thanks anyways
12 years ago
Thanks Jeanne for a fast reply. I think I fixed my base case now with this new code:



My main problem is that I can't get my program to draw the next "set of triangles" on the next "level", i.e. 2 smaller triangles on the bigger triangle and 1 triangle on each end of the line ( a total of 5 triangles). instead, I'm stuck with 1 triangle the whole time, so I figure I'm doing my recursion wrong somehow.
12 years ago
Not sure if I should post this in the beginner's section but here it goes. I thought this "Koch Curve" would be fun because it looks cool. The problem I'm having is that it is stuck on the first iteration and it won't draw more of those triangles. This is the code I have so far that runs:



I'm having a feeling that I'm missing a parameter for the recursion part of it since it is basically redrawing the same starting triangle over again.
Thanks
12 years ago
Hi. I'm back after a long break from programming and I need your ranch's help again.
I defined a static recursive method that works for reversing all the characters of a given string and then the next question was:


Trace the execution of the method for the String "Junk" using activation frames.



We started doing recursion in class. I'm still very unclear as to what an activation frame actually is and or how/what to do to trace an execution. Is it like "drawing a picture of a stack" at run-time and then just draw the next element on top of the stack, which would be the next recursive call?

Thanks for any help that I might get!
12 years ago
Conditions now work correctly, silly me, doh'. As always, you guys give a very speedy reply, thank you Michael Dunn and Stefan Wagner and everyone else here!
14 years ago
That second post of yours Stefan makes much much more sense. When you changed my condition ( 2 messages above this) didn't work. I understand it now. Thanks.
14 years ago
you made your solution somewhat strange and hard for me to change, I can't get a user input from the way you wrote your solution.
14 years ago
I just noticed, I also have to keep the input ability in the solution.
14 years ago
It works quite well, but it sorta destroyed the whole idea of a recursion. I tried to define the next number in terms of the previous two numbers that were being calculated. I never expected this to work your way like that.
14 years ago
The output stops when the output are the same two numbers from the beginning input.
14 years ago
I'm "trying" to set it up recursively by using the arrays (just seems easier). The problem seems to lie around the for loop condition.

Sorry if my problem doesn't seem to be clear.

Example Input:
1
8

Output
1 8 9 7 6 3 9 2 1 3 4 7 1 8

so it's like 1 + 8 = 9
9 + 8 = 7 (use only the ones place, the digit on the right)
7 + 9 = 6
... and so on
14 years ago
Good evening everyone!

I ran into a strange looking problem the other day. It involves the use of a special recursive function called the necklace problem. Heard it's supposed to be a famous math problem. Anyways. The thing is, I have to input two numbers, the first one to fill in the tens value place, and the second number to fill in the ones value place. To get the next number, I have to add the two previous numbers and only use the number in the ones place value, but it has to stop if you see the same two numbers in the beginning. So only the numbers of the ones place value are used. I am very close to getting it, but the condition to stop my loop doesn't seem right.



I seem to be very close to getting it right. What's the correct boolean condition to stop it? Suggestions/ideas/solutions all welcomed if possible
14 years ago
Your code can be sortened up quite a bit in two words: bubble sorting. Ever heard of it? It involves the use of nested for loops and an array. So, while you're counting the steps in order of your array , you are also keeping track of the numbers you're using (ascending or descending). Look up bubble sorting on google, it might clear some stuff up. I got two examples from class that might help ya.

14 years ago