Question

In: Computer Science

Please answer this two part question. Thank you! For this assignment you must write the following...

Please answer this two part question. Thank you!

For this assignment you must write the following functions in Scheme:

2.1 Write a recursive function called eval-poly that takes a list of numbers representing the coefficients of a polynomial and a value for ? and evaluates the polynomial for the given value of ?. The list of coefficients should start with the term of lowest degree and end with the term of highest degree. If any term of intermediate degree is missing from the polynomial it should have a coefficient of zero. For example, the polynomial ?3+4?2+2 would be represented by the list '(2 0 4 1). Hint: the polynomial above can be rewritten as 2+?⋅(0+?⋅(4+?⋅1))
> (eval-poly '() 0)

0

> (eval-poly '(5) 0)

5

> (eval-poly '(4 3) 2)

10

> (eval-poly '(2 7 1) 3)

32

2.2 Write a tail-recursive version of the previous problem called eval-poly-tail. It should call a helper function called eval-poly-tail-helper that uses tail recursion to keep a running sum of the terms evaluated so far. You might want to use the expt function to take a number to a power.
> (eval-poly-tail '() 0)

0

> (eval-poly-tail '(5) 0)

5

> (eval-poly-tail '(4 3) 2)

10

> (eval-poly-tail '(2 7 1) 3)

32

Solutions

Expert Solution

I have implemented the above problem using python.

1) Code

Output

​​​​​​

2) Using Tail Recurssion

Code

Output


Related Solutions

Please answer this multi-part question. Thank you! For this assignment you must write the following function...
Please answer this multi-part question. Thank you! For this assignment you must write the following function in Scheme: 4 Write a recursive function called mergesort that sorts a list by doing the following: (a) Use split to split the list into two roughly equal-sized partitions. (b) Recursively sort both partitions. (c) Use merge to merge the sorted partitions together. Once again you will need two base cases, one for the empty list and the other for a single-element list. >...
Please answer this multi-part question. Thank you! For this assignment you must write the following functions...
Please answer this multi-part question. Thank you! For this assignment you must write the following functions in Scheme: 4 Write a recursive function called mergesort that sorts a list by doing the following: (a) Use split to split the list into two roughly equal-sized partitions. (b) Recursively sort both partitions. (c) Use merge to merge the sorted partitions together. Once again you will need two base cases, one for the empty list and the other for a single-element list. >...
Please answer part a) through part d) of the question below. Thank you. Question 3 A...
Please answer part a) through part d) of the question below. Thank you. Question 3 A tobacco refinery has four methods of measuring pH. To test the four methods, a supervisor randomly assigns each of 32 tobacco samples with known pH to one of the four methods, so that each method is applied to exactly eight samples. The difference between measured pH and the known pH is recorded, and the data is below. Method Sample Response A 1 -0.307 A...
This question has two parts. Please answer both, thank you! Part A.) On the first day...
This question has two parts. Please answer both, thank you! Part A.) On the first day of the fiscal year, a company issues a $8,200,000, 9%, 9-year bond that pays semiannual interest of $369,000 ($8,200,000 × 9% × ½), receiving cash of $6,868,206. Journalize the first interest payment and the amortization of the related bond discount. Round to the nearest dollar. If an amount box does not require an entry, leave it blank. Interest Expense Discount on Bonds Payable Cash...
This question has two parts answer both questions please thank you Part 1)When Maria Acosta bought...
This question has two parts answer both questions please thank you Part 1)When Maria Acosta bought a car 2 1/2 years ago, she borrowed $17,000 for 48 months at 7.8% compounded monthly. Her monthly payments are $413.43, but she'd like to pay off the loan early. How much will she owe just after her payment at the 2 1/2 year mark? (Round your answer to the nearest cent.) Part 2) A man buys a car for $39,000. If the interest...
please answer the following question on the bottom. thank you. 4. Why is the mix of...
please answer the following question on the bottom. thank you. 4. Why is the mix of output produced in competitive markets more desirable than that in monopolistically competitive markets? 5. Prior to 1982, AT&T kept local phone rates low by subsidizing them from long-distance profits. Was such cross-subsidization in the public interest? Explain. 6. Why is there resistance to (a) local phone companies providing video and data services and (b) mergers of local cable and telephone companies?
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
In Java please. Thank you! Recursion For this assignment you are going to write six different...
In Java please. Thank you! Recursion For this assignment you are going to write six different methods. Each method is to be written recursively. Any method that is written iteratively will not receive any credit, even if it is correct and produces the same results or output. You will be given a starter file. You are not allowed to change the signatures of any of the given methods. You are not allowed to add any methods to your solutions. Write...
Each question has 6-7 parts, depending on the work. Please answer every part. Thank you. -...
Each question has 6-7 parts, depending on the work. Please answer every part. Thank you. - What is the formula for the Average Propensity to Consume (APC)? Group of answer choices consumption divided by income the change in consumption divided by a change in income income divided by consumption the change in income to a change in consumption None of the above - How does the size of the Marginal Propensity to Consume (MPC) affect the size of the multiplier...
Each question has 8-9 parts, depending on the work. Please answer every part. Thank you. -...
Each question has 8-9 parts, depending on the work. Please answer every part. Thank you. - The government spending multiplier is Group of answer choices the ratio of the change in the equilibrium level of output to a change in government spending the difference between the new and old levels of government spending. the ratio of the change in government spending to the change in the equilibrium level of output the difference between the old level of equilibrium output and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT