This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes Why non-recursive sorting algorithms are not popular? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Why non-recursive sorting algorithms are not popular?" Watch "Why non-recursive sorting algorithms are not popular?" New topic
Author

Why non-recursive sorting algorithms are not popular?

Hareendra Reddy
Ranch Hand

Joined: Jan 09, 2011
Posts: 173

I have been revising algorithms for some days. Actually , i am not aware that iterative versions of the algorithms do exist but why they are not popular as their recursive counterparts.

Even the Arrays.sort method in java implements recursive quick sort.I heard that recursion causes overhead in maintaining the stack frames for each method call.

for e.g: Iterative version for merge sort is even simple. It first sort the adjacent elements and then the sorted pairs , so on.

I posted this question on StackOverflow too: but dint get a convincing answer.What are your views about this??

Thanks,
S.Hareendra
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2409
Quick sort (one of the fastest sorting algorithm) is recursive; trying to implement it in iterative fashion will lead to hard-to-understand code.

I heard that recursion causes overhead in maintaining the stack frames for each method call.

Yes, there is an overhead, but there is an overhead in implementing an iterative version, too. Recursion by itself is not something to be afraid of.
Hareendra Reddy
Ranch Hand

Joined: Jan 09, 2011
Posts: 173

Thank you Tim..
This, This andthis are useful too.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11861
    
  18

memory is pretty cheap these days. My father used to tell me about when they paid basically $1 PER BYTE of memory. Today, I can run into just about any store and buy a 4GB thumb drive for under $15 bucks. It's usually not something to worry about. even my cell phone has a 4GB chip in it.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why non-recursive sorting algorithms are not popular?
 
It's not a secret anymore!