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 34 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
YES! Correct, THANKS for helping me on my review


gcook

  • Member
  • Posts: 343
Reply 3 on: Yesterday
:D TYSM

 

Did you know?

Many supplement containers do not even contain what their labels say. There are many documented reports of products containing much less, or more, that what is listed on their labels. They may also contain undisclosed prescription drugs and even contaminants.

Did you know?

In the United States, there is a birth every 8 seconds, according to the U.S. Census Bureau's Population Clock.

Did you know?

Human neurons are so small that they require a microscope in order to be seen. However, some neurons can be up to 3 feet long, such as those that extend from the spinal cord to the toes.

Did you know?

Patients who have been on total parenteral nutrition for more than a few days may need to have foods gradually reintroduced to give the digestive tract time to start working again.

Did you know?

In women, pharmacodynamic differences include increased sensitivity to (and increased effectiveness of) beta-blockers, opioids, selective serotonin reuptake inhibitors, and typical antipsychotics.

For a complete list of videos, visit our video library