Home / Expert Answers / Computer Science / which-of-the-following-recursive-methods-is-equivalent-to-this-iterative-method-string-bar-string-s-pa287

(Solved): Which of the following recursive methods is equivalent to this iterative method?String bar(String s) ...



Which of the following recursive methods is equivalent to this iterative method?

String bar(String s) {
String x = "";
for (int i = 0; i < s.length(); i++)
x =s.charAt(i) + x;
return x;
}

A) String bar(String s) { if (s.length() == 0) return s; return s.charAt(s.length() - 1) + bar(s.substring(0, s.length() - 1)); }

B) String bar(String s) { if (s.length() == 0) return s; return bar(s.substring(0, s.length() - 1)) + s.charAt(s.length() - 1); }

C) String bar(String s) { if (s.length() < 1) return s; return s.charAt(0) + bar(s.substring(1)); }

D) none of these

E) String bar(String s) { if (s.length() < 0) return s; return bar(s.substring(1)) + s.charAt(0); }



We have an Answer from Expert

View Expert Answer

Expert Answer




The equivalent recursive method to the given iterative method is:

We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe