Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write the following functions using recursion: // Print out 'n' *'s on the same line printStars(int n); // Return the minimum of the array min(int[]

write the following functions using recursion:

// Print out 'n' *'s on the same line

printStars(int n);

// Return the minimum of the array

min(int[] numbers));

// Return Yes if pattern is found in target, No otherwise

isIn(String pattern, String target);

// Print all the permutations of word

permutations(String word);

// Return the number of permutations of word

countNumberOfPerms(word);

The above methods must be recursive or they may do some non-recursive stuff and make a call to a recursive function that actually performs the computation.

..

the main is (don't change the mian):

public class A8

{

public static void main(String[] args)

{

A8Utils utils = new A8Utils();

utils.printStars(0);

utils.printStars(5);

int[] numbers = { 41, 0, 74, -1, 8, 37, 79, 5, 22, -17 };

System.out.println("Minumum is " + utils.min(numbers));

String[] patterns = { "al ", "Sta", "eat", "eac" };

for(int ii = 0; ii < patterns.length; ++ii)

{

System.out.println("Is pattern '" + patterns[ii] + "' in 'Cal State Long Beach'? " + utils.isIn(patterns[ii], "Cal State Long Beach"));

}

utils.permutations("1234");

utils.permutations("ios");

utils.countNumberOfPerms("LongBeach");

}

}

the output :

0 stars: 5 stars: ***** Minumum is -17 Is pattern 'al ' in 'Cal State Long Beach'? Yes Is pattern 'Sta' in 'Cal State Long Beach'? Yes Is pattern 'eat' in 'Cal State Long Beach'? No Is pattern 'eac' in 'Cal State Long Beach'? Yes The 24 permutations of 1234 sorted are: 1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321 The 6 permutations of ios sorted are: ios iso ois osi sio soi The number of permutations of LongBeach is 362880

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

Step: 3

blur-text-image

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

ISBN: B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions