Quantcast

Maximum PC

It is currently Fri Oct 24, 2014 4:06 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 20 posts ] 

Do you use recursive functions?
Yes. All the time. 10%  10%  [ 2 ]
Yes. Occasionally 67%  67%  [ 14 ]
Yes. I think? 5%  5%  [ 1 ]
No. But I keep thinking about it. 5%  5%  [ 1 ]
No. What's recursion? 5%  5%  [ 1 ]
No. 5%  5%  [ 1 ]
No. 5%  5%  [ 1 ]
Total votes : 21
Author Message
 Post subject: Recursion anyone?
PostPosted: Wed Aug 11, 2004 5:30 am 
Smithfield
Smithfield
User avatar

Joined: Sat Jun 26, 2004 2:47 am
Posts: 10158
Location: Between 32nd Notes
When I took programming one of the more cool things that I took was recursive functions. But I really didn't see the need for them to often.

How many of you guys/girls use recursive functions?


Top
  Profile  
 
 Post subject: Re: Recursion anyone?
PostPosted: Wed Aug 11, 2004 6:32 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
Satchboy wrote:
When I took programming one of the more cool things that I took was recursive functions. But I really didn't see the need for them to often.

How many of you guys/girls use recursive functions?


Recursive functions are awesome! BST's can be traversed much faster through the use of recursion. I odn't use recursion for everything, but I don't like to avoid it.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 7:54 am 
8086
8086
User avatar

Joined: Wed Jul 14, 2004 9:08 pm
Posts: 80
Lalalalalalalala laaaaa

longjump. 8)


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 8:55 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24226
Location: Granite Heaven
Recursion is a great tool to use ... but only when it is necessary. 8)


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 10:01 am 
I judge you GUILTY!
I judge you GUILTY!
User avatar

Joined: Tue May 25, 2004 4:38 pm
Posts: 162
Location: New York City
Karl the Pagan wrote:
longjump. 8)


Masochist.

Hehehe.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 2:08 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
Jipstyle wrote:
Recursion is a great tool to use ... but only when it is necessary. 8)


Amen! I can't code BST's without recursion, I don't even know how to iterate through a BST using standard loops! Recursion is my and your bestfriend. :D


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 5:25 pm 
Smithfield
Smithfield
User avatar

Joined: Sat Jun 26, 2004 2:47 am
Posts: 10158
Location: Between 32nd Notes
Karl the Pagan wrote:
Lalalalalalalala laaaaa

longjump. 8)


I'm sorry but I don't know the reference to "longjump". :oops:


Top
  Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 7:40 pm 
8086
8086
User avatar

Joined: Wed Jul 14, 2004 9:08 pm
Posts: 80
It's something used to make unrolling recursive functions more efficient when you eventually return.

Google recursion+longjump


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 5:13 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
DJSPIN80 wrote:
Jipstyle wrote:
Recursion is a great tool to use ... but only when it is necessary. 8)


Amen! I can't code BST's without recursion, I don't even know how to iterate through a BST using standard loops! Recursion is my and your bestfriend. :D

Well, that you should be able to do w/o recursion - an easy version is a bst implementation using an array then just use a stack to simulate the recursion... ;)

I once tried to write an iterative version of the towers of hanoi problem. OMG, Huge PITA! I had done the recursive version pretty easily and spent a good hour and a half on the iterative verson before calling it quits.

Recursion and Dynamic Programming - two fo the best friends a programmer can ever have.... :)


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 5:26 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
Gadget wrote:
DJSPIN80 wrote:
Jipstyle wrote:
Recursion is a great tool to use ... but only when it is necessary. 8)


Amen! I can't code BST's without recursion, I don't even know how to iterate through a BST using standard loops! Recursion is my and your bestfriend. :D

Well, that you should be able to do w/o recursion - an easy version is a bst implementation using an array then just use a stack to simulate the recursion... ;)

I once tried to write an iterative version of the towers of hanoi problem. OMG, Huge PITA! I had done the recursive version pretty easily and spent a good hour and a half on the iterative verson before calling it quits.

Recursion and Dynamic Programming - two fo the best friends a programmer can ever have.... :)


While I could, using recursion is both fun and easier to visualize. Besides, do YOU want to visualize a BST in your head as a flat array? I know I wouldn't want that! ;)

That said, I thought about coding ToH using standard iterative commands, but I gave up 5 minutes into it. :D

And yes, Recursion + Dynamic Programming = Programmer's Best Friends.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 11:53 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
DJSPIN80 wrote:
Gadget wrote:
DJSPIN80 wrote:
Jipstyle wrote:
Recursion is a great tool to use ... but only when it is necessary. 8)


Amen! I can't code BST's without recursion, I don't even know how to iterate through a BST using standard loops! Recursion is my and your bestfriend. :D

Well, that you should be able to do w/o recursion - an easy version is a bst implementation using an array then just use a stack to simulate the recursion... ;)

I once tried to write an iterative version of the towers of hanoi problem. OMG, Huge PITA! I had done the recursive version pretty easily and spent a good hour and a half on the iterative verson before calling it quits.

Recursion and Dynamic Programming - two fo the best friends a programmer can ever have.... :)


While I could, using recursion is both fun and easier to visualize. Besides, do YOU want to visualize a BST in your head as a flat array? I know I wouldn't want that! ;)

You guys keep forgeting how basic a bST array is..... you probably learned it early on in your first data structures class and then fogot all about. :)

Say our tree can have up to 100 positive intergers, right. Inititalize an integer array of 101 in size with everything filled to -1 (in a zero based language like java, c#, etc). Skip the index 0. The 'root node' is at index 1. A left child is 2*parent and a right child is 2*parent + 1. A child's parent is always child / 2.

Not so hard to visualize... :)


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 1:30 pm 
Thunderbird
Thunderbird
User avatar

Joined: Wed Jul 07, 2004 1:13 pm
Posts: 817
Location: Missouri
Gadget wrote:
DJSPIN80 wrote:
Gadget wrote:
DJSPIN80 wrote:
Jipstyle wrote:
Recursion is a great tool to use ... but only when it is necessary. 8)


Amen! I can't code BST's without recursion, I don't even know how to iterate through a BST using standard loops! Recursion is my and your bestfriend. :D

Well, that you should be able to do w/o recursion - an easy version is a bst implementation using an array then just use a stack to simulate the recursion... ;)

I once tried to write an iterative version of the towers of hanoi problem. OMG, Huge PITA! I had done the recursive version pretty easily and spent a good hour and a half on the iterative verson before calling it quits.

Recursion and Dynamic Programming - two fo the best friends a programmer can ever have.... :)


While I could, using recursion is both fun and easier to visualize. Besides, do YOU want to visualize a BST in your head as a flat array? I know I wouldn't want that! ;)

You guys keep forgeting how basic a bST array is..... you probably learned it early on in your first data structures class and then fogot all about. :)

Say our tree can have up to 100 positive intergers, right. Inititalize an integer array of 101 in size with everything filled to -1 (in a zero based language like java, c#, etc). Skip the index 0. The 'root node' is at index 1. A left child is 2*parent and a right child is 2*parent + 1. A child's parent is always child / 2.

Not so hard to visualize... :)


I have worked with Arrays in VB 5/6, Java, and C++. Now I have never been enrolled in a CS degree. My associates is in Microcomputers and Networking and am going for a Bachelors in CIS. But I have never heard BST once in any of my classes. So I did some research and it seems very interesting.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 1:37 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Mon Jun 14, 2004 4:04 pm
Posts: 985
Location: Earth
baldeagle wrote:
I have worked with Arrays in VB 5/6, Java, and C++. Now I have never been enrolled in a CS degree. My associates is in Microcomputers and Networking and am going for a Bachelors in CIS. But I have never heard BST once in any of my classes. So I did some research and it seems very interesting.


BST's are fun to code, I just didn't like using arrays for BST's, mainly because I never cared to visualize it, so I never got the hang of it, either that or I cut class or something.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 3:44 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
DJSPIN80 wrote:
baldeagle wrote:
I have worked with Arrays in VB 5/6, Java, and C++. Now I have never been enrolled in a CS degree. My associates is in Microcomputers and Networking and am going for a Bachelors in CIS. But I have never heard BST once in any of my classes. So I did some research and it seems very interesting.


BST's are fun to code, I just didn't like using arrays for BST's, mainly because I never cared to visualize it, so I never got the hang of it, either that or I cut class or something.

That and the code is still much shorter and cleaner using a linked node implementation and recursion.


Top
  Profile  
 
 Post subject:
PostPosted: Sat Aug 14, 2004 8:00 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Sat Jun 26, 2004 3:44 pm
Posts: 513
Location: Vancouver Island
I tried to use recursion, but I kept repeating myself... ;-)


Top
  Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 3:59 pm 
8086
8086

Joined: Mon Aug 02, 2004 10:59 am
Posts: 50
I use recursion all the time, but I thought that recursion was not actually more effecient than another type of loop, just easier to read. Is this true (I mean the 'fastest' implementations of each)?


Top
  Profile  
 
 Post subject:
PostPosted: Fri Sep 10, 2004 7:19 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24226
Location: Granite Heaven
It can be more efficient, and it can be drastically less efficient ... it really depends on how it is used.

For example, if a recursive method calls itself using a pass-by-copy (ie., it creates new instances of its members with each call), it can quickly eat up memory ... if it uses pass-by-reference, then this is not a problem.

As with all tools, it is important to use them wisely. :D


Top
  Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 2:59 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Cplusplus wrote:
I use recursion all the time, but I thought that recursion was not actually more effecient than another type of loop, just easier to read. Is this true (I mean the 'fastest' implementations of each)?


In general, recursion is going to be slower.

A few forms of recursion, such as tail recursion, are paticularly slow in comparison. Every recursive call results in all the local variables being pushed onto the stack and the creation of a new stack frame, which is very expensive if you were doing something simple.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 3:01 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Jipstyle wrote:
For example, if a recursive method calls itself using a pass-by-copy (ie., it creates new instances of its members with each call), it can quickly eat up memory ... if it uses pass-by-reference, then this is not a problem.

As with all tools, it is important to use them wisely. :D


Recursively (and quickly).....

True.

If the number of calls is large, it is slow in comparison.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Sep 14, 2004 7:59 pm 
I judge you GUILTY!
I judge you GUILTY!
User avatar

Joined: Tue May 25, 2004 4:38 pm
Posts: 162
Location: New York City
What languages support tail recursion?
I know C++ doesn't.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.