Solved

recursive function Simple and URGENT !!

Posted on 2006-10-22
9
194 Views
Last Modified: 2013-11-20
im trying to print all possible sequences of any given 2 strings RECURSIVELY. For example, if i=2 and j=3, i want
the strings

aabbb
ababb
abbab
abbba
baabb
babab
babba
bbaab
bbaba
bbbaa

Can someone help with idea or code ?

0
Comment
Question by:beginer92
[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
  • 3
  • 2
9 Comments
 

Author Comment

by:beginer92
ID: 17786258
look, It's a part of the homework and not the complete hw.
I really need help. Pls
0
 

Author Comment

by:beginer92
ID: 17786305
can I get a hint of how to think of it recursively. U said an idea is okay
0
 

Author Comment

by:beginer92
ID: 17786355
damnn!

i think writting a one line hint should have been a better option than that unfriendly "sorry!"
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 17786783
Write 'aabbb'
Find first instance of not 'a' - this is starting point.
Now swap the character at that position with the position before until that not 'a' reaches the start of the string.
Increment initial start point and repeat until start point is at end of string.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 17786858
For an absolutely clear recursive function it might be better to start with 'aabbb' for example and pass that to a function which moves the first non 'a' with an 'a' to the left of it one position left then calls the function again.  It will stop when it can't swap any more characters

eg.

aabbb
ababb
baabb
....
bbbaa
and now it leaves the recursive function


(What I wrote at first can use recursion but it is really more like a loop)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 171
ORA-01403: no data found 43 116
mapAB Challlenge 35 180
Path of Workbook 3 87
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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