Solved

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

Posted on 2016-11-08
3
73 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 27

Accepted Solution

by:
dpearson earned 500 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 27

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java example issue 5 62
Eclipse for Java EE development 2 66
glassfish admin console 1 44
Code Coverage and Coding Standards 2 75
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

740 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