a. Let T(n) be the number of minutes needed to fry n pancakes on
both sides by the
algorithm given. Then we have the following recurrence for
T(n):
T(n) = T(n − 2) + 2 for n > 2, T(1) = 2, T(2) = 2.
T(n) = T(n-2) + 2
= T(n-4) + 4
= T(n-6) + 6
.....
T(n) = T(n-(n-2))+2n = T(2) + 2n = 2 + 2n
T(n) = O(n).
solution is T(n) = n for every even n > 0 and
T(n) = n + 1 for every odd n > 0
and can be obtained either by backward substitutions or by applying the formula for the generic term of an arithmetical progression.
b)
The algorithm fails to execute the task of frying pancakes in the minimum amount of time when n is odd for all n>1.
For example:
T(3) = 4 minutes to fry 3 pancakes but there is a much quicker process for that
First, fry pancakes 1 and 2 on one side. -> Takes 1 minute
Then fry pancake 1 on the second side together with pancake 3 on its first side. -> Takes 1 minute
Finally, fry both pancakes 2 and 3 on the second side. -> takes 1 minute
Total time taken is 3 minutes but as per algorithm, it will take much more long-time i.e, 4 minutes.
c)
If n ≤ 2, fry the pancake (or the two hamburgers together if n =
2) on each side.
If n = 3, fry the pancakes in 3 minutes as indicated in the
previous answer.
If n > 3, fry two pancakes together on each side and then fry
the remaining n − 2 pancakes by the same
algorithm. The recurrence for the number of minutes needed to fry n
pancakes looks now as follows:
T(n) = T(n − 2) + 2 for n > 3, T(1) = 2, T(2) = 2, T(3) =
3.
can you plzzz explain in detial There are n pancakes to be fried on a small...
Problem 5: Recurrence relations and detailed analysis of recursive algorithm efficiency g(n: non-negative integer) 1. if n ≤ 1 then return n 2. else return (5 * g(n─1) ─ 6 * g(n─2)) MergeSort divides the array to be sorted into two equal halves, calls itself recursively on each half to sort that subarray, and then calls the Merge algorithm to merge the two sorted halves in linear time. This leads to its two recurrence relations T(n)=2T(n/2)+cn, n>1;...
(a) Your company participates in a competition and the fastest algorithm wins. You know of two different algorithms that can solve the problem in the competition. • Algorithm I solves problems by dividing them into five subproblems of half the size, recursively solving each subproblem, and then combining the solutions in linear time. • Algorithm 2 solves problems of size n by dividing them into 16 subproblems of size n/4, recursively solving each subproblem, and then combining the solutions in...
I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is not limited to finding only the median, but can generally find the ith element with 0≤i <n. Implement this generic version of the median algorithm by creating a class selector in the ads.set2.select package and implementing the following method: /** * Returns the...
You work for a factory making bricks. A coworker accidentally contaminated one of the bricks with lightweight material and it must be removed. Given a pile of 50 bricks and a balance scale, how can you find the one that weighs less? The scale can hold any number of bricks on each side of the scale at one time, and it will tell you if the two sides weigh the same, or which side is lighter if they do not...
An m×n
array A
of real numbers is a Monge array if for all i,j,k,
and l
such that 1≤i<k≤m
and 1≤j<l≤n
, we have
>A[i,j]+a[k,l]≤A[i,l]+A[k,j]>
In other words, whenever we pick two rows and two columns of a
Monge array and consider the four elements at the intersections of
the rows and columns, the sum of the upper-left and lower-right
elements is less than or equal to the sum of the lower-left and
upper-right elements. For example, the following...
If someone can help with 3
3) To multiply 2 n bit binary numbers the straightforward way takes (r) time because each digit of each number multiplies each digit of the other number. (The aditions from carying are lower order terms.) Consider the following divide- and-conquer algorithm, which assumes, for simplicity, that n is a power of 2: Split each number into 2 collections of bits, the high order bits and the low order bits. For convenience, call the two...
1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2) is 2, Fibonnaci(3) is 3, Fibonnaci(4) is 5, and so on. Your function may only use a constant amount of memory (i.e. no auxiliary array). Argue that the running time of the function is Θ(n), i.e. the function is linear in n. 2. (10 points) Order the following functions by growth rate: N, \N,...
An SDLC approach that completes portions of the system in small increments across iterations and integrates it into the whole is called Choose Choose walking skeleton Scrum team A(m) is a is a set of functionally related activities that combine to enable the develop process in a UP project In Scrum, a(n) s the client stakeholder for whom a system is being built. Refactoring scrum meeting The basic idea behind the development methodology is to respond to a current situation...
1)
can any one please givem the code for this
a) If n is a power of 2, as it is in Figure 9-3, you would merge
pairs of individual entries, starting at the
beginning of the array. Then you would return to the beginning of
the array and merge pairs of twoentry
subarrays. Finally, you would merge one pair of four-entry
subarrays. Notice that the subarrays
in each pair of subarrays contain the same number of entries.
In general,...
LANGUAGE IS C++ Lab Ch14 Recursion In this lab, you are provided with startup code which has six working functions that use looping (for, while, or do loops) to repeat the same set of statements multiple times. You will create six equivalent functions that use recursion instead of looping. Although looping and recursion can be interchanged, for many problems, recursion is easier and more elegant. Like loops, recursion must ALWAYS contain a condition; otherwise, you have an infinite recursion (or...