Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7) Here is a recursive method that returns the smallest character in a string: // return smallest character in s, e.g. getMinChar(difference) would return 'c'

7) Here is a recursive method that returns the smallest character in a string:

// return smallest character in s, e.g. getMinChar("difference") would return 'c'

static char getMinChar(String s) {

if (s.length() == 1) return s.charAt(0);

if (getMinChar(s.substring(1)) > s.charAt(0))

return s.charAt(0);

else

return getMinChar(s.substring(1));

}

The method returns the correct value but it can be extremely slow when s is a long string. Recode getMinChar so that its more efficient by reducing the number of recursive calls. Your code should still be recursive. There is no need to make major changes to the algorithm.

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

6. Conclude with the same strength as in the introduction

Answered: 1 week ago

Question

7. Prepare an effective outline

Answered: 1 week ago