?
Solved

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

Posted on 2016-11-08
3
Medium Priority
?
90 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

752 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