
Consider the following
sequence of n integers a_1, a_2,… , a_n and produces as output a matrix M = {m_(ij)} where m_(ij) is the minimum term
in the sequence of integers a_i
, a_(i+1),… , a_j for j ≥ i and
m_(ij) = 0 otherwise.
initialize M so that m_(ij) = a_i if j ≥ i and m_(ij) = 0
otherwise
for i := 1 to n
for j := i + 1 to n
for k := i + 1 to j
m_(ij) := min(m_(ij), a_k)
return M= {m_(ij)} {m_(ij) is the minimum term of
a_i
, a_(i+1),… , a_j
}
a) Show that this algorithm uses O(n^3) comparisons to
compute the matrix M.
b) Show that this algorithm uses Ω(n^3) comparisons to
compute the matrix M. Using this fact and part (a),
conclude that the algorithms uses Θ(n^3) comparisons.
[Hint: Only consider the cases where i ≤ n∕4 and
j ≥ 3n∕4 in the two outer loops in the algorithm.]

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- solvearrow_forwardGive a MPI program segment to convert a n-by-n matrix distributed on a n-by-n 2D mesh such that allits rows and columns get sorted in ascending order. Show only the iterative loop. Only communicationsallowed are to the four direct neighbors. (Hint: You may employ a variant of odd-even transpositionsort, but the whole matrix does not need to be sorted.)arrow_forwardWe want to determine whether an unsorted array A of n entries has duplicates. These integers are 1,..., 2n. Give this solution's worst-case running time asymptotic order T(n). Find an efficient algorithm.arrow_forward
- Algorithmarrow_forwardProblem 2. Suppose we have an array A[1 : n] which consists of numbers {1,...,n} written in some arbitrary order (this means that A is a permutation of the set {1,...,n}). Our goal in this problem is to design a very fast randomized algorithm that can find an index i in this array such that A[i] mod 8 € {1,2}, i.e., the reminder of dividing A[i] by 8 is either 1 or 2. For simplicity, in the following, we assume that n itself is a multiple of 8 and is at least 8 (so a correct answer always exist). For instance, if n = 8 and the array is A = [8,7, 2,5, 4, 6,3, 1], we want to output either of indices 3 or 8. (a) Suppose we sample an index i from {1,...,n} uniformly at random. What is the probability that i is a correct answer, i.e., A[i] mod 8 E {1,2}? (b) Suppose we sample m indices from {1,...,n} uniformly at random and with repetition. What is the probability that none of these indices is a correct answer? Now, consider the following simple algorithm for this problem: Find-Index-1(A[1:…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





