Question

The Fibonacci numbers are defined by recurrence (3.22). Give an O.n-time dynamic-programming algorithm to compute the...

The Fibonacci numbers are defined by recurrence (3.22). Give an O.n-time dynamic-programming algorithm to compute the nth Fibonacci number.

Draw the subproblem graph. How many vertices and edges are in the graph?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1 answer)

def fibonacci(n):
a,b=0,1
while n>0:
a,b=b,a+b
n-=1
return a
ans = fibonacci(8)
print("Fibonacci=",ans)

----> Since it's directly applying the basic fibonacci sequence we can easily say that time complexity is O(n).

2 answer)

Graph:

Subproblem graph will have (n+1) vertices.

Let's say v0 to vn...

for i=2 to n

vertex vi will have two leaving edges,....... one edge to the vertex vi-1 and one edge to the vertex vi-2

There'll be no edges leaving the vertiices v0 or  vv1.

Therefore, subproblem graph will have 2n-2 edges totally...

Please comment if you've any doubt...

I'm ready to help you.

Add a comment
Know the answer?
Add Answer to:
The Fibonacci numbers are defined by recurrence (3.22). Give an O.n-time dynamic-programming algorithm to compute the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Give a dynamic programming algorithm that runs within the time complexity. Also give the space complexity of the algorit...

    Give a dynamic programming algorithm that runs within the time complexity. Also give the space complexity of the algorithm. Please Given a directed graph with non-negative integer edge weights, a pair of vertices s and t, and integers K and W, describe a dynamic-programming algorithm for deciding whether there exists a path from s to t that has total weight W and uses exactly K edges. Your algorithm should run in time O(nm)WK). Analyze the time- and space-complexity of your...

  • Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the...

    Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the linear recurrence equation Fn F-1 F-2 where F F2 1 and by convention Fo 0. For example, the first 8 Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21. (a) For a given n, compute the nth Fibonnaci number using a for loop (b) For a given n, compute the nth Fibonnaci number using a while loop Print the 15th Fibonacci number...

  • Viterbi algorithm We can use dynamic programming on a directed graph G = (V, E) for...

    Viterbi algorithm We can use dynamic programming on a directed graph G = (V, E) for speech recognition. Each edge (u, v) in E is labeled with a sound s(u, v) from a finite set S of sounds. The labeled graph is a formal model of a person speaking a restricted language. Each path in the graph starting from a distinguished vertex v0 in V corresponds to a possible sequence of sounds produced by the model. The label of a...

  • Give pseudocode that performs the traceback to construct an LCS from a filled dynamic programming table...

    Give pseudocode that performs the traceback to construct an LCS from a filled dynamic programming table without using the “arrows”, in O(n + m) time. 2. Suppose we are given a “chain” of n nodes as shown below. Each node i is “neighbors” with the node to its left and the node to its right (if they exist). An independent set of these nodes is a subset of the nodes such that no two of the chosen nodes are neighbors....

  • Problem 1: Dynamic Programming in DAG Let G(V,E), |V| = n, be a directed acyclic graph...

    Problem 1: Dynamic Programming in DAG Let G(V,E), |V| = n, be a directed acyclic graph presented in adjacency list representation, where the vertices are labelled with numbers in the set {1, . . . , n}, and where (i, j) is and edge inplies i < j. Suppose also that each vertex has a positive value vi, 1 ≤ i ≤ n. Define the value of a path as the sum of the values of the vertices belonging to...

  • Could the running time of algorithm max_ind_set_improved() be improved by using dynamic programming or memoization? And...

    Could the running time of algorithm max_ind_set_improved() be improved by using dynamic programming or memoization? And if so, which of the two approaches would be preferable? Justify your answer. def max_ind_set(nodes, edges): if len(nodes) <= 1: return len(nodes) node = nodes[0] # pick a node # case 1: node lies in independent set => remove neighbours as well nodes1 = [ n for n in nodes if n != node and (node, n) not in edges ] size1 = 1...

  • Give the specifications of a pseudo-polynomial time algorithm for Galactic Shortest Path. Hint: G...

    Hi, I'm confused about how to do this, any help is appreciated thanks! Give the specifications of a pseudo-polynomial time algorithm for Galactic Shortest Path. Hint: Given an instance of GSP such that G has n vertices and m edges, you may want to use a 5 dimensional m by n by n by L by R array. Give the specifications of a pseudo-polynomial time algorithm for Galactic Shortest Path. Hint: Given an instance of GSP such that G has...

  • 1 (15 pts) Implement recursive, memoized, and dynamic programming Fibonacci and study their performances using different...

    1 (15 pts) Implement recursive, memoized, and dynamic programming Fibonacci and study their performances using different problem instans You can choose to look at the perfor- mance by either timing the functions or counting the basic operations (in code) Provide your results below, and submit your code. Also, describe the pros and cons of your choice of performance metric Note: If you decide to use timing, the standard way to time an algorithm is to run the same problem 100...

  • My homework task is: Let a linear, binary, array A and two positives real numbers a and b, with a < b. Give a dynamic...

    My homework task is: Let a linear, binary, array A and two positives real numbers a and b, with a < b. Give a dynamic programming algorithm using bottom-up approach, that splits table A to the minimum numbers of continuous sub-arrays, so that the percentage of units (1s) <= a, OR percentage of units (1s) >= b.. Analyze the run time of the algorithm. For example, with input A = [1; 0; 1; 1; 1; 0; 0; 1; 0; 0;...

  • Could the running time of algorithm max_ind_set_improved() be improved by using dynamic programmi...

    Could the running time of algorithm max_ind_set_improved() be improved by using dynamic programming or memoization? And if so, which of the two approaches would be preferable? Justify your answer. def max_ind_set(nodes, edges): if len(nodes) <= 1: return len(nodes) node = nodes[0] # pick a node # case 1: node lies in independent set => remove neighbours as well nodes1 = [ n for n in nodes if n != node and (node, n) not in edges ] size1 = 1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT