# Maximum PC

 It is currently Sun May 26, 2013 12:56 am

 All times are UTC - 8 hours

 Page 1 of 1 [ 20 posts ]
 Print view Previous topic | Next topic

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

Joined: Sat Jun 26, 2004 2:47 am
Posts: 10123
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

 Post subject: Re: Recursion anyone?Posted: Wed Aug 11, 2004 6:32 am
 Bitchin' Fast 3D Z8000

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

 Post subject: Posted: Wed Aug 11, 2004 7:54 am
 8086

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

longjump.

Top

 Post subject: Posted: Wed Aug 11, 2004 8:55 am
 Java Junkie

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

Top

 Post subject: Posted: Wed Aug 11, 2004 10:01 am
 I judge you GUILTY!

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

Masochist.

Hehehe.

Top

 Post subject: Posted: Wed Aug 11, 2004 2:08 pm
 Bitchin' Fast 3D Z8000

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.

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.

Top

 Post subject: Posted: Wed Aug 11, 2004 5:25 pm
 Smithfield

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

longjump.

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

Top

 Post subject: Posted: Wed Aug 11, 2004 7:40 pm
 8086

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.

Top

 Post subject: Posted: Fri Aug 13, 2004 5:13 am
 Bitchin' Fast 3D Z8000*

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.

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.

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

 Post subject: Posted: Fri Aug 13, 2004 5:26 am
 Bitchin' Fast 3D Z8000

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

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.

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.

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

Top

 Post subject: Posted: Fri Aug 13, 2004 11:53 am
 Bitchin' Fast 3D Z8000*

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

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.

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

 Post subject: Posted: Fri Aug 13, 2004 1:30 pm
 Thunderbird

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

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.

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

 Post subject: Posted: Fri Aug 13, 2004 1:37 pm
 Bitchin' Fast 3D Z8000

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

 Post subject: Posted: Fri Aug 13, 2004 3:44 pm
 Bitchin' Fast 3D Z8000*

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

 Post subject: Posted: Sat Aug 14, 2004 8:00 pm
 Bitchin' Fast 3D Z8000

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

Top

 Post subject: Posted: Fri Sep 10, 2004 3:59 pm
 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

 Post subject: Posted: Fri Sep 10, 2004 7:19 pm
 Java Junkie

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24153
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.

Top

 Post subject: Posted: Mon Sep 13, 2004 2:59 am
 Bitchin' Fast 3D Z8000*

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

 Post subject: Posted: Mon Sep 13, 2004 3:01 am
 Bitchin' Fast 3D Z8000*

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.

Recursively (and quickly).....

True.

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

Top

 Post subject: Posted: Tue Sep 14, 2004 7:59 pm
 I judge you GUILTY!

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 20 posts ]

 All times are UTC - 8 hours

#### Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ Maximum FAQs    Forum Rules, Posting Guidelines & Announcements    The Good, The Bad & The Banned    FAQs Help/Do It Yourself    PC Building Lab    The Help Desk    PC Modding    Education & Certification Hardware    Nuts & Bolts    Portable Talk    Appraisals, Deals & Bargains (oh my!) OS/Software/Programming    Windows Parlor    Alt.OS.Abode    Games Arena    Programmers' Paradise Networking/Internet    Internet Truckstop    Network Nook In/Out    Magazine and Book Feedback    Forum & Website Feedback    Dog Pound Team Maximum PC Folding at Home    Team Maximum PC - Folding at Home - FIND CURES TO DISEASES    Team MPC - Folding Gauntlets