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 31 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


alvinum

  • Member
  • Posts: 317
Reply 3 on: Yesterday
Wow, this really help

 

Did you know?

All patients with hyperparathyroidism will develop osteoporosis. The parathyroid glands maintain blood calcium within the normal range. All patients with this disease will continue to lose calcium from their bones every day, and there is no way to prevent the development of osteoporosis as a result.

Did you know?

There used to be a metric calendar, as well as metric clocks. The metric calendar, or "French Republican Calendar" divided the year into 12 months, but each month was divided into three 10-day weeks. Each day had 10 decimal hours. Each hour had 100 decimal minutes. Due to lack of popularity, the metric clocks and calendars were ended in 1795, three years after they had been first marketed.

Did you know?

The effects of organophosphate poisoning are referred to by using the abbreviations “SLUD” or “SLUDGE,” It stands for: salivation, lacrimation, urination, defecation, GI upset, and emesis.

Did you know?

About 3% of all pregnant women will give birth to twins, which is an increase in rate of nearly 60% since the early 1980s.

Did you know?

Hypertension is a silent killer because it is deadly and has no significant early symptoms. The danger from hypertension is the extra load on the heart, which can lead to hypertensive heart disease and kidney damage. This occurs without any major symptoms until the high blood pressure becomes extreme. Regular blood pressure checks are an important method of catching hypertension before it can kill you.

For a complete list of videos, visit our video library