Recursive method to print all permutations of a string, JAVA Programming

Assignment Help:

Objectives

_ Creating and compiling a simple program

_ Designing classes

_ Use of recursive algorithms

_ Learn basic combinatorics  

Task: string permutation

Write a recursive method to print all permutations of a string. For example, for a string "abc", the output would be:

abc

acb

bac

bca

cab

cba

Write a program to test your method.

The program should prompt the user to enter a string. Then the program should display all the possible permutations. You can assume that all characters in the input string are different.

Hint:

Declare the following two helping methods:

void displayPermutations(String text)

and

void displayPermutations(String done, String todo)

The first method invokes displayPermutations( "", text ). The second method uses a loop to move a character from todo to done and recursively invokes it with a new todo and done. The base case is when todo string is empty. In this case the method prints done

Example

Note:

user entered values are shown in bold.  

Example 1

This program prints out all permutations of a string.

Enter a string? dome

There are the following permutations:

dome

doem

dmoe

dmeo

deom

demo

odme

odem

omde

omed

oedm

oemd

mdoe

mdeo

mode

moed

medo

meod

edom

edmo

eodm

eomd

emdo

emod

Example 2

This program prints out all permutations of a string.

Enter a string? one

There are the following permutations:

one

oen

noe

neo

eon

eno  

Important Notes

1. For the purposes of this assignment, you can assume that the user will only enter  valid values.

2. In your program you must define and make use of at least the two methods:

a. displayPermutations(String text) and

b. displayPermutations(String done, String todo) as described above.

3. Test your program. In particular, be sure to test it on turing before you submit it.


Related Discussions:- Recursive method to print all permutations of a string

Thread, create thread without extending anything

create thread without extending anything

Design and implement online food delivery system, You are required to desig...

You are required to design & implement online food delivery system using Java RMI technology. This involves writing both the server and the client program(s). Client programs can u

Nested if.., WAP to input a 4 digit no and find greatest using nested if

WAP to input a 4 digit no and find greatest using nested if

Complete back end and front end development, Complete Back end and Front En...

Complete Back end and Front End Development Project Description: This work is a part of ongoing project. The need is to prepare and integrate the web part of this project.

Caesar Cipher, How can I create a simple Caesar cipher using if-else statem...

How can I create a simple Caesar cipher using if-else statements?

INHERITANCE, Did Java support hybrid inheritance?

Did Java support hybrid inheritance?

Describe unbalanced arrays, Describe Unbalanced Arrays ? Such as C Java...

Describe Unbalanced Arrays ? Such as C Java does not have true multidimensional arrays. Java fakes multidimensional arrays by using arrays of arrays. This means that it is prob

Alreadyboundexception thrown and by which method, When is AlreadyBoundExcep...

When is AlreadyBoundException thrown and by which method? Ans) AlreadyBoundException is thrown by bind(String name) method when a remote object is already registered with the re

Write a program that will analyze stocks, Write a program in java that will...

Write a program in java that will analyze stock data and purchase stock with the user''s specific risk and investment. User will select risk from a GUI, high, medium or low and inp

File and random access file classes, Difference between the File and Random...

Difference between the File and Random Access File classes? Ans) The File class encapsulates the files and directories of the local file system. The Random Access File class giv

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd