Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.The code below is for a recursive solution to computing the n th Fibonacci number. public long fibRecursive(int n) { if (n 60 30 60

1.The code below is for a recursive solution to computing the nth Fibonacci number. public long fibRecursive(int n) { if (n <= 1) { return n; } else { return fibRecursive(n - 1) + fibRecursive(n - 2); } } Why is the running time for the above algorithm extremely inefficient?

-The recursive call, fibRecursive(n - 1) causes the algorithm to perform redundant calculations.

-The recursive call, fibRecursive(n - 2) causes the algorithm to perform redundant calculations.

-Both recursive calls cause the algorithm to perform redundant calculations.

-The algorithm is recursive, and is thus inherently inefficient.

2. Suppose that the median of the first, middle, and last item is used as a pivot in quicksort. What would be the result, after the first partitioning of the following array in quicksort:

a=[7 9 5 8 15 10 11]

[7 5 8 9 15 10 11]

[5 7 8 9 10 11 15]

[7 5 8 15 10 11 9]

[5 7 8 10 9 11 15]

3.Assume you have two algorithms, A and B, both of which perform the same function, although their implementations differ. Algorithm A has a running time of O(N2+10 N + 1800) while algorithm B has a running time of O(100N). Also assume that the value of N is restricted to the set of Natural numbers, i.e.,{1, 2, 3, ...}. For what values of N algorithm A performs faster than algorithm B?

N>60

30

N<30

N<30 or n>60

4. Which of the following data structure does not allow duplicate values and uses an array to store the data?

HashSets

Stacks

ArrayLists

HashMaps

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago