Question

In: Computer Science

Task 1 1.1 - Mergesort has two major advantages over Quicksort. What are these advantages? Write...

Task 1

1.1 - Mergesort has two major advantages over Quicksort. What are these advantages? Write at most 5-6 sentences.

1.2 - Mergesort complexity analysis, explain it via recurrence relation and its main strategy. Write at most 7-8 sentences.

1.3 - Why a recursive algorithm always needs a base case? 2-3 sentences at most.

1.4 - Write Fibonacci Sequence formula F(N) with its base cases. Just write the formula with base-cases.

1.5 - Show how F(N=4) is computed for Fibonacci Sequences recursively starting from its base cases. Write your base case and how each value is computed.

1.6 - What is the time complexity of computing recursive Fibonacci Sequence F(N). Give Big-O notation and explain your answer. 5-6 sentences at most.

Solutions

Expert Solution

1.1 The advantage of merge sort over quick sort ,

a. merge sort worst case time complexity is O(nlog(n)) where as quick sort worst case time complexity is O(n2 ).

b. merge sort is stable where as quick sort is not stable, so it is very helpful in sorting for those arrays/list which maintain ordering througout of their computing.

1.2 the time complexity of merge sort is O(nlog(n)).it uses divide and conqure algorithm to perform sorting. its recurrence relation is T(n) = 2T(n/2) + O(n) , here 2T(n/2) is because at every time it divide the array into two half. and O(n) is because it always merge two half.

1.3 reccursive relation algorithm need a base case because recursive method call it self hence it may go in a infinite loop , so to break this infinite loop base case is needed, base case is a condition inside recursive method which causes recursive method to come out of infinite loop.

1.4 fibonacci sequence with a base case is T(n) = T(n-1) +O(1). , here base case is if(n<=1) return n.

so time complexity here is O(n).

1.5 fibonacci (n==4),

fib(n)

{

if(n<=1)

return n;

return fib(n-1)+fib(n-2)

}

1.6. the time complexity of fiboancci is O(n) it is because its recurrance relation is T(n) =T(n-1) +O(1) ,

thus upon calculating this recurrance relation its output is O(n).


Related Solutions

Task 1. to be completed. 1.1 - Write a small Python snippet code that can revert...
Task 1. to be completed. 1.1 - Write a small Python snippet code that can revert an array of N element (Please do not use the default function “reverse()). 1.2 - There is a famous programming (algorithm) concept that can vastly reduce the complexity of Recursive Fibonacci Algorithm. 2 .a) What is the name of this concept 2.b) Write the execution time and memory complexity of Fibonacci sequences, once this concept is applied 2.c) Explain the main idea behind this...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
What are two main advantages that the corporate form has over partnerships?
What are two main advantages that the corporate form has over partnerships?
1. In your opinion, what are two major advantages, and two drawbacks, of having Millenials in...
1. In your opinion, what are two major advantages, and two drawbacks, of having Millenials in the workplace? Explain.
1-Explain serialization and traceability. What are the two major advantages of serialization and traceability? What is...
1-Explain serialization and traceability. What are the two major advantages of serialization and traceability? What is a disadvantage of serialization?
What are some of the major advantages and disadvantages of being a first mover? Identify two...
What are some of the major advantages and disadvantages of being a first mover? Identify two e-commerce companies that prove your point.
Discuss the major advantages and disadvantages of survey research methods over qualitative methods.
Discuss the major advantages and disadvantages of survey research methods over qualitative methods.
What type of algorithm is the Quicksort algorithm if it has random pivots?
What type of algorithm is the Quicksort algorithm if it has random pivots?
Identify what you consider to be the major advantages of for profit facilities and the major...
Identify what you consider to be the major advantages of for profit facilities and the major advantages of not for profit facilities. Do you think that hospice care will change based on the type of ownership (profit vs. not for profit) it is under? If so, how and why?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT