The Artima Developer Community
Sponsored Link

Java Answers Forum
Recursion versus iteration

1 reply on 1 page. Most recent reply: Jan 27, 2003 11:14 PM by Tj

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Rachel Brunner

Posts: 1
Nickname: rachelbrun
Registered: Jan, 2003

Recursion versus iteration Posted: Jan 16, 2003 3:11 AM
Reply to this message Reply
Advertisement
I am developing a web spider, using a tree structure and a hashmap. I am not sure whether to use recursion or iteration. If I use a hashmap and synchronization with recursion,will that cost a lot of time in which case it is better to do iteration?

Thank you

Rachel


Tj

Posts: 7
Nickname: tj
Registered: Jan, 2003

Re: Recursion versus iteration Posted: Jan 27, 2003 11:14 PM
Reply to this message Reply
Java runtimes don't currently optimize recursive structures, I believe. Iteration will pretty much always be a win, if you care for performance and stability (since Java has limits to recursion). But you could prototype using recursion, since it's generally a clearer way of writing things. Then convert to iteration.

I've used recursion when I knew for a fact that I wouldn't be dealing with deep trees. Then all I cared was writing a bug-free, clear version. If profiling later told me there was a problem, then I would have converted to iteration. Fortunately, there was absolutely no problem.

Flat View: This topic has 1 reply on 1 page
Topic: help with testing a hashtable Previous Topic   Next Topic Topic: Automatic Web Site Montoring Software(Java Ver), free trial, contact

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use