Question: [Ocaml Language] Please solve this question by completing (*TODO*) in this code: (* problem 1*) let fastexpt : int -> int -> int = fun

[Ocaml Language]

Please solve this question by completing (*TODO*) in this code:

(* problem 1*)

let fastexpt : int -> int -> int

= fun b n -> (*TODO*)

[Ocaml Language] Please solve this question by completing (*TODO*) in this code:

(* problem 1*) let fastexpt : int -> int -> int =

Problem 1 (10pts) Consider the task of computing the exponential of a given number. We would like to write a function that takes as arguments a base b and a positive integer exponent n to compute b". Read the remaining prob- lem description carefully and devise an algorithm that has time complexity of (log n) One simple way to implement the function is via the following recursive definition: 0 m- which translates into the OCaml code: let rec expt b n = if n = 0 then 1 else b * (expt b (n-1)) However, this algorithm is slow: it takes (n) steps

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!