you are given as input an array a containing n integers. describe a divide and conquer algorithmwhich outputs two indices i < j such that a[j] − a[i] is maximized. your algorithm should run inθ(n lg n). you should provide a recurrence for the runtime of your algorithm and solve it.
Added by Agust-N D.
Step 1
.n] into two halves: left = a[1..m] and right = a[m+1..n], where m = ⌊n/2⌋. For each subarray, recursively compute: - best pair (i, j) within that subarray that maximizes a[j] − a[i] with i < j. - the minimum value in the subarray and its index: minVal and Show more…
Show all steps
Close
Your feedback will help us improve your experience
Akash M and 58 other Calculus 3 educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Given a one-dimensional array A[1..n] (n ≥ 2), we consider the problem of finding the number of pairs (i, j) such that: 1 ≤ i < j ≤ n, and A[i] > 3 * A[j]. Use the following array as an example, the respective solution for this problem should be 7 and the corresponding pairs are: (1, 6), (2, 6), (3, 5), (3, 6), (4, 5), (4, 6), (4, 8) Question #1 [4 pts]: Let us use Pairs(A, 1, n) to represent the solution. Apply the divide-and-conquer technique to design an algorithm that solves the problem. Clearly write your algorithm in pseudo-code similar to those in your textbook and feel free to add additional return values if needed. Question #2 [2 pts]: Let T(n) be the running time of Pairs(A, 1, n) in question #1. Write the recurrence expressing T(n) in terms of T(k) for some k < n. Solve it to determine the upper bound of T(n).
Akash M.
Problem 3: (7 points) Design and analyze a divide and conquer algorithm that determines the minimum and maximum value in an unsorted list (array). a) Verbally describe and write pseudo-code for the min_and_max algorithm. b) Give the recurrence. c) Solve the recurrence to determine the asymptotic running time of the algorithm. How does the theoretical running time of the recursive min_and_max algorithm compare to that of an iterative algorithm for finding the minimum and maximum values of an array.
Madhur L.
Give an algorithm for the following problem and determine its time complexity. Given a list of n distinct positive integers, partition the list in to two sublist, each of size n/2, such that the difference between the sums of the integers in the two sublists is maximized. You may assume that n is a multiple of 2.
K S.
Recommended Textbooks
Calculus: Early Transcendentals
Thomas Calculus
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD