Question

ALGORITHM PROBLEM: A) Significant Inversions: We are given a sequence of n arbitrary but distinct real...

ALGORITHM PROBLEM:

A) Significant Inversions: We are given a sequence of n arbitrary but distinct real numbers <a1 , a2 ,..., an>. We define a significant inversion to be a pair i < j such that ai > 2 aj . Design and analyze an O(n log n) time algorithm to count the number of significant inversions in the given sequence.

[Hint: Use divide-&-conquer. Do the “combine” step carefully]

B) The Maximum-Sum Monotone Sub-Array Problem: Input: An array A[1..n] of arbitrary positive integers. Output: The maximum-element-sum contiguous sub-array of A[1..n] whose entries form a monotone sequence (either ascending or descending)

[Hint: Use an incremental approach]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A.

We will divide the array into equal halves, we will count the number of significant inversions in each halves, and we will also count the number of significant inversion in which one of the element is in one half and another element is in another half. We will add these to get the result. So we will perform analogous operation to merge sort in which we will divide the array into halves, count the significant inversal in each half then combine the subarray to form sorted array but also note if at some index element in left half form significant inversal with element in right half, then all the elements in next index in left half will be significant inversal. We will use this property to count the number of significant inversal in O(n log n) time.

int Divide (A,begin,end) 1. count- keep count of significant inversal 2. If end-begin< 2: then if A[begin]>Alend] then if A[b

Now merge step is very important to observe.

Note in step 4 of merge where we are incrementing count very smartly.

Complexity = O(n log n) just like merge sort

B.

We will divide the array into equal halves, we will check the maximum sum of monotone array in each halves, and we will also check the maximum sum of monotone array which has some portion in left half and some portion in right half. We will return the result which is maximum of all three. Without loss of generality assume that array is of size which is some exponent of 2.

Below is the Merge procudure where we keep the name Merge just to say that we are searching for monotone sequence which passed through middle of the array.

Time complexity T(n) = 2T(n/2)+O(n) = O( n log n)

Please comment for any clarification

Add a comment
Know the answer?
Add Answer to:
ALGORITHM PROBLEM: A) Significant Inversions: We are given a sequence of n arbitrary but distinct real...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Algorithm Problem - Counting Number of Inversions

    We are given a sequence ofndistinct numbers a1,...,an. We define an inversion to be a pair i<j such that ai>aj. Give an O(nlogn) algorithm to count the number of inversions. (Hint: assume that your algorithmreturns a sorted array of input sequences, as well as the number of inversions. Divide the input sequencesinto two halves, then count inversions and sort each half by doing recursive calls, and find a way to mergethese two sorted halves and to count the number of...

  • ALgorithm problem

    Recall the problem of ¯nding the number of inversions. As in the text, we are given asequence of numbers a1; : : : ; an, which we assume are all distinct, and we de¯ne an inversionto be a pair i < j such that ai > aj .We motivated the problem of counting inversions as a good measure of how di®erent twoorderings are. However, one might feel that this measure is two sensitive. Let's call a pair asigni¯cant inversion if...

  • 1. Design and write a Divide& Conquer algorithm that, given an array A of n distinct...

    1. Design and write a Divide& Conquer algorithm that, given an array A of n distinct integers which is already sorted into ascending order, will find if there is some i such that Ali] in worst-case 0(log n) time.

  • the question from the course COMP 4040 that Analysis of Algorithms if you want to answer it by code please use C or C++...

    the question from the course COMP 4040 that Analysis of Algorithms if you want to answer it by code please use C or C++ 5. Algorithm Design (20 points) Input: array A contains n distinct numbers from 1 to n, in arbitrary order. Output: number of inversions (defined as the number of pair(i, j) of array indices with i < j and A[i] > Aj]) (a) (5 points) What array with elements from the set {1, 2, ..., n) has...

  • Suppose that we are given a sorted array of distinct integers A[1, ......,  n] and we want...

    Suppose that we are given a sorted array of distinct integers A[1, ......,  n] and we want to decide whether there is an index i for which A[i] = i. Describe an efficient divide-and-conquer algorithm that solves this problem and explain the time complexity. 1. Describe the steps of your algorithm in plain English. 2. Write a recurrence equation for the runtime complexity. 3. Solve the equation by the master theorem.

  • Design and analysis of algorithms Type in answer Problem 5. Given a sorted array of distinct...

    Design and analysis of algorithms Type in answer Problem 5. Given a sorted array of distinct integers A[1- -n], you want to find out whether there is an index I for which Ai-i. Give a divide-and-conquer algorithm that runs in time O(log n)

  • Given n distinct items: Assuming n is a power of 2, write down a recursive divide-and-conquer...

    Given n distinct items: Assuming n is a power of 2, write down a recursive divide-and-conquer algorithm for solving simultaneous minimum and maximum, using n = 2 as the bottom of the recursion. If we let T(n) denote the number of comparisons done by your algorithm, write down the recurrence relation satisfied by T(n). Solve exactly (without using the “big O” notation) the recurrence relation for T(n), showing all the details of your work.

  • 1. (16 pts.) Sorted Array Given a sorted array A of n (possibly negative) distinct integers,...

    1. (16 pts.) Sorted Array Given a sorted array A of n (possibly negative) distinct integers, you want to find out whether there is an index i for which Al = i. Give a divide-and-conquer algorithm that runs in time O(log n). Provide only the main idea and the runtime analysis.

  • Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a...

    Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into 5 sub-instances of size n/3, and the dividing and combining steps take a time in Θ(n n). Write a recurrence equation for the running time T (n) , and solve the equation for T (n) 2. Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into 5 sub-instances of size n/3, and the dividing...

  • Consider n indivisible objects with distinct types i = 1, 2, 3,…, n. We are given...

    Consider n indivisible objects with distinct types i = 1, 2, 3,…, n. We are given positive integer weights W = {w1,w2...wn} and positive integer prices V = {v1,v2...vn} for the objects and a knapsack of weight capacity (m). Our problem is to find the maximum profit possible by including a subset of the objects into the knapsack with total weight of at most m. This form of the 0/1 Knapsack Problem can be solved by a Decrease and Conquer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT