[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

printing a file in reverse order is easy in recursion rather than in iteration

Posted on 2016-11-08
3
Medium Priority
?
104 Views
Last Modified: 2016-11-17
Hi,

I am reading as

printing a file in reverse order is easy in recursion rather than in iteration

I was not clear on what it means. please advise.
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
dpearson earned 2000 total points
ID: 41879482
It's not good advice.  If you want to print out a file in reverse order, iterative solutions are better.

The reason is say you have a 100MB file.

To read it into a buffer and then walk back up through the buffer printing it out (iterative solution), you will use 100MB on the heap.
To read it in a byte at a time in a recursive solution (and then print it out in reverse order) you will use more than 100MB on the stack (since recursive functions are stored on the stack).  That will crash your Java process.  Heap space is always a lot larger than stack space.

Doug
0
 
LVL 7

Author Comment

by:gudii9
ID: 41886765
 Heap space is always a lot larger than stack space.

how much is usual space of heap and stack? please advise
0
 
LVL 28

Expert Comment

by:dpearson
ID: 41887354
how much is usual space of heap and stack? please advise

You can configure these settings, but heap on a "normal" computer today might be perhaps 2GB while stack space might be 1MB.

So a difference of 2000 times.

Doug
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question