Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a recursive function that will test to see if the input String parameter belongs to the following format: L = {S : S is

Write a recursive function that will test to see if the input String parameter belongs to the following format:

L = {S : S is in the form of AnB3n, for some n >= 0} where n and 3n are powers.

Test your function in main function.

----------------------------------------------------------------

The class should have two methods:

public static boolean IsIn(String w){ //body}; public static void main(String[] args)

----------------------------------------------------------------

Coding requirement:

public static void main(String[] args)

{

String str ="AABBBBBB";

if(IsIn(str))

System.out.println("The string " + str + " is in the language.");

else

System.out.println("The string " + str + " is in NOT the language.");

}

-----------------------------------------------------------------------------------------------------

A recursive method calls itself.

IsIn(String w)

Each recursive call, solves an identical, but smaller problem.

AABBBBBB

ABBB

A test for the base case enables the recursive calls to stop

One of the smaller case?

w.length()==0

---------------------------------------------------------------------------------------------

Pseudocode

If base case == 0

return true

Else if check the characters

return IsIn(diminished string)

Else

return false

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

Explain the cost of capital.

Answered: 1 week ago

Question

Define capital structure.

Answered: 1 week ago

Question

List out some inventory management techniques.

Answered: 1 week ago