Questions
Questions

FIT1008-FIT1054-FIT2085 Fundamentals of algorithms - S2 2025

Single choice

What is the best-case time complexity of the following recursive implementation of fibonacci(n)? (Complexity is based on the value of the variable n) def fibonacci(n): if n == 0: return 0 elif n == 1: return 1 else: return fibonacci(n-1) + fibonacci(n-2)

Options
A.a. O(n)
B.b. O(2n)
C.c. O(1)
D.d. O(n2)
Question Image
View Explanation

View Explanation

Verified Answer
Please login to view
Step-by-Step Analysis
To analyze the recurrence, observe the code path: for n > 1, the function calls itself twice, once with n-1 and once with n-2, and sums the results. Each call spawns two more calls (until reaching the base cases), creating a binary branching tree of recursive calls. Option a (O(n)): This would imply linear growth in the num......Login to view full explanation

Log in for full answers

We've collected over 50,000 authentic exam questions and detailed explanations from around the globe. Log in now and get instant access to the answers!

Similar Questions

Order (O) analysis characterizes computational complexity by

Transitive_Clo_Alg_4 You are working with a Graph class implemented using an adjacency map, where each vertex maps to a dictionary of its neighbors. The graph is directed, and the methods get_edge(u, v) and insert_edge(u, v) are used to check for and add edges. The function TRANSITIVE_CLOSURE(graph) shown below modifies a deep copy of the input graph by potentially adding new edges based on the structure of the graph:   function TRANSITIVE_CLOSURE(graph):    closure ← deep copy of input graph     vertices ← list of vertices in closure    n ← number of vertices     for k from 0 to n-1:        for i from 0 to n-1:            if i ≠ k and edge (i, k) exists in closure:                for j from 0 to n-1:                    if i ≠ j ≠ k and edge (k, j) exists in closure:                        if edge (i, j) does not exist in closure:                            insert edge (i, j) into closure     return closure What is the time complexity of this algorithm, assuming get_edge and insert_edge each take constant time?

What does the term "time complexity" refer to in the context of sorting algorithms?

Question at position 28 What is the main disadvantage of using algorithms?They only work for large problems.They only work for small problems.Correct solutions are not guaranteed.Solutions may take a long time.They are very similar to trial-and-error.

More Practical Tools for Students Powered by AI Study Helper

Join us and instantly unlock extensive past papers & exclusive solutions to get a head start on your studies!