This topic contains a solution. Click here to go to the answer

Author Question: Analyze the following functions:public class Test1 { public static void main(String[] args) ... (Read 33 times)

panfilo

  • Hero Member
  • *****
  • Posts: 572
Analyze the following functions:

public class Test1 {
public static void main(String[] args) {
System.out.println(f1(3));
System.out.println(f2(3, 0));
}
 
public static int f1(int n) {
if (n == 0)
return 0;
else {
return n + f1(n - 1);
}
}

public static int f2(int n, int result) {
if (n == 0)
return result;
else
return f2(n - 1, n + result);
}
}

◦ f2 is tail recursion, but f1 is not
◦ f1 is tail recursion, but f2 is not
◦ f1 and f2 are both tail recursive
◦ Neither f1 nor f2 is tail recursive


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by panfilo on May 6, 2020

Bigfoot1984

  • Sr. Member
  • ****
  • Posts: 321
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 25% of students answer this correctly




panfilo

  • Member
  • Posts: 572
Reply 2 on: May 6, 2020
Thanks for the timely response, appreciate it


AISCAMPING

  • Member
  • Posts: 347
Reply 3 on: Yesterday
Gracias!

 

Did you know?

The training of an anesthesiologist typically requires four years of college, 4 years of medical school, 1 year of internship, and 3 years of residency.

Did you know?

Addicts to opiates often avoid treatment because they are afraid of withdrawal. Though unpleasant, with proper management, withdrawal is rarely fatal and passes relatively quickly.

Did you know?

Throughout history, plants containing cardiac steroids have been used as heart drugs and as poisons (e.g., in arrows used in combat), emetics, and diuretics.

Did you know?

By definition, when a medication is administered intravenously, its bioavailability is 100%.

Did you know?

Medications that are definitely not safe to take when breastfeeding include radioactive drugs, antimetabolites, some cancer (chemotherapy) agents, bromocriptine, ergotamine, methotrexate, and cyclosporine.

For a complete list of videos, visit our video library