CSC 3102 Chapter : Csc3102DPj

17 views2 pages
15 Mar 2019
School
Course
Professor

Document Summary

* this program compares the performance of the recursive. * and memoized (dp) versions of implementations of the fibonacci algorithm. * by measuring runtimes in microseconds in a sample run. * @author duncan public class fibonacci public static void main(string[] args) System. out. print("enter the value of n for the f(n) you wish to compute: "); int n = input. nextint(); System. out. println("computing, using the naive version"); long beg = system. nanotime()/1000; int fibn = naivefib(n); long elapsed = system. nanotime()/1000 - beg; System. out. println("computing, using the memoized version"); beg = system. nanotime()/1000; fibn = memoizedfib(n,memo); elapsed = system. nanotime()/1000 - beg; System. out. println("computing, a second time using the naive version"); beg = system. nanotime()/1000; 1 fibn = naivefib(n); elapsed = system. nanotime()/1000 - beg; System. out. println("computing a second time using the memoized version"); beg = system. nanotime()/1000; fibn = memoizedfib(n,memo); elapsed = system. nanotime()/1000 - beg; System. out. println("fib("+n+") = "+fibn+" took "+elapsed+" microseconds to compute. * computes the nth fibonacci number in a naive way using recursion.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers