# Anagram without recursion

Page 1 of 1

## 4 Replies - 1768 Views - Last Post: 05 July 2011 - 04:13 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=238084&amp;s=ad9b2e0b8ed2e420717af343916ee76a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ritvijpathak

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 04-July 11

# Anagram without recursion

Posted 04 July 2011 - 08:38 AM

I wrote a program using recursion for generating anagrams.
But now we have to write another without using recursion.
Can anyone explain me the logic used so that I can write it?
Is This A Good Question/Topic? 0

## Replies To: Anagram without recursion

### #2 maniacalsounds

• D.I.C Regular

Reputation: 112
• Posts: 454
• Joined: 27-June 10

## Re: Anagram without recursion

Posted 04 July 2011 - 09:23 AM

First, please don't post two topics about the exact same thing.

Second, what do you mean? Recursion is basically where you make a call to that same method within the method if necessary. Simply take out calls to the method, and find another workaround for it.

Sorry, we can't help you much without you showing code.
Was This Post Helpful? 1

### #3 macosxnerd101

• Self-Trained Economist

Reputation: 9042
• Posts: 33,542
• Joined: 27-December 08

## Re: Anagram without recursion

Posted 04 July 2011 - 09:28 AM

The big deal with recursion is that it is state-driven. Since it stores states (meaning the recursive calls) on the Java call stack, it is very easy to backtrack and go to the previous state. The way I would suggest is using your own Stack to store the states and backtrack using that.

My tutorial on Trees, Stacks, and the Iterator Pattern is a good place to start.
Was This Post Helpful? 1

### #4 ritvijpathak

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 04-July 11

## Re: Anagram without recursion

Posted 05 July 2011 - 03:03 AM

maniacalsounds, on 04 July 2011 - 09:23 AM, said:

First, please don't post two topics about the exact same thing.

Second, what do you mean? Recursion is basically where you make a call to that same method within the method if necessary. Simply take out calls to the method, and find another workaround for it.

Sorry, we can't help you much without you showing code.

Sorry! my mistake.

I mean that i need to write a program for printing anagrams of a given string without using recursion.
I have no idea what logic i should use. Can anyone help me with the logic only not the code..?
Was This Post Helpful? 0

### #5 macosxnerd101

• Self-Trained Economist

Reputation: 9042
• Posts: 33,542
• Joined: 27-December 08

## Re: Anagram without recursion

Posted 05 July 2011 - 04:13 AM

Did you see my previous post?
Was This Post Helpful? 0

Page 1 of 1

 Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).