Tail recursion and exception handling

Assignment Help Basic Computer Science
Reference no: EM13963483

Tail Recursion and Exception Handling

Can we use tail recursion elimination to optimize the following program?

exception OddNum;

let fun f(0,count) = count

| f(1, count) = raise OddNum

| f(x, count) = f(x-2, count+1) handle OddNum => -1

Why or why not? Explain. This is a tricky situation - try to explain succinctly what the issues are and how they might be resolved.

Reference no: EM13963483

Questions Cloud

Discuss the innovation involved in product development : Choose a product that they are interested in or provides the required information to discuss the innovation involved in its development - What aspect of the technology influenced the development and the products
Ealuation order and exceptions : Suppose we add an exception mechanism similar to the one used in ML to pure Lisp. Pure Lisp has the property that if every evaluation order for expression e terminates, then e has the same value under every evaluation order. Does pure Lisp with ex..
What is the identity of this gas : A sample of 4.00 g of gas occupies a volume of 1.47 L at 20.0 psi and - 40.0 °F. What is the identity of this gas?
Implications of false beliefs about homosexuality : Reflect on the following statement made by Stanton L. Jones in the assigned article, "Sexual Orientation and Reason: On the Implications of False Beliefs About Homosexuality"
Tail recursion and exception handling : Can we use tail recursion elimination to optimize the following program?
What is the mass of the ice cubes dropped : Two ice cubes at 0.0 oC are dropped in an insulated container containing 93.8 g of water at 27.0°C. After all the ice is melted, the final temperature of the system is 17.0 °C. What is the mass of the ice cubes dropped? Assume that the container has ..
What is the momentum amplitude for this wavefunction : What is the probability of finding the particle in the interval 0 less than or equal to x less than or equal to pi/2b? What is the momentum amplitude for this wavefunction?
Problem regarding the exceptions and recursion : Assume that if f calls g and g raises an exception that f does not handle, then the activation record of f is popped off the stack without returning control to the function f.
Trying to figure out ionic bonds and figuring out formula : Trying to figure out ionic bonds and figuring out formulas.  For example...K+1 and CO3-2 combines to form what.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Ease of access or speed of processing

Security of your data is of utmost importance to Jamie, even more so than ease of access or speed of processing. Which type of application category would you recommend Jamie use?

  Calculate the total wages for an employee

Design and create a program to calculate the total wages for an employee. An employee is paid $10 per hour for the first 40 hours. The employee is paid $15 per hour for every hour greater than 40 hours and up to 50 hours.

  Economists find the prisoner''s dilemma

Economists find the Prisoner's Dilemma game interesting because in it, players who act in their own self-interest, don't end up better off--they end up worse off instead. Explain why it is both a good thing and bad thing that when a person acts in th..

  Database application development

Database Application Development - Scripting languages are used to develop dynamic Web sites, offering tight integration with databases and the ability to offer portability and stability through a variety of environments. There are a variety of scrip..

  Evaluation process to seven-step acquisition model

Discuss in scholarly detail the acquisition evaluation process to the Seven-Step Acquisition Model.

  Display the total sales with ah dollar sign

Display the total sales with ah dollar sign and two decimal places. I have no idea how to code this add button.The code has to work for Visual Basic. Thank you.

  Translate the instruction into machine code

Translate the following instruction into machine code, replacing pseudo-code where necessary. Show all your work in binary, but report the machine code for each instruction in hexadecimal.

  Create a monospaced font of point size

How would you create a Monospaced font of point size 20 that is bold? Give the Java statement needed.

  Draw a magenta circle

Given a graphics object g, write a few lines of code to have that graphics object draw a magenta circle (not filled in) that has a diameter of 200 pixels.

  A transformer has 20 primary windings 100

A transformer has 20 primary windings 100 secondary windings. If the secondary volatage is 25 V, find the primary voltage

  Writejava class take a seven-letter return the phone numbers

this week you are required to use concepts learned in this week: strings and the Java library method contains. Write a Java class PhoneNumber that will take in a seven-letter word and return the phone number that corresponds to it.

  The use of borrowed material and utilize original ideas

The paper should be in the range of 1200 - 1500 words with double spacing. It is very important to include proper APA citation (in-text citations with quotation marks and source information, plus a reference list). Please minimize the use of bo..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd