Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 4 (Permutation Pattern Counting) Assume you are given an array A of unique numbers (i.e. no duplicates). We say that an arbitrary pair of

Problem 4 (Permutation Pattern Counting)

Assume you are given an array A of unique numbers (i.e. no duplicates). We say that an arbitrary pair of elements in this array, (A[i], A[j]), matches the 2-reversal pattern if i < j and A[i] > A[j].

Using Divide & Conquer, design an O(n lg n) time algorithm that will tell you how many pairs of elements in A match the 2-reversal pattern. Justify its correctness and running time.

Hint: Note that in the the worst case, this could be as many as O(n^2) pairs, so you will need to figure out some way to count the pairs that match this pattern without actually enumerating them. Since you know divide & conquer is the design technique, think inductively like you did with Merge Sort. So start by assuming you have an algorithm that could recusively solve the problem for smaller sub-arrays, and then figure out what additional cases you need to consider to solve the problem for the whole array.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

=+ 2. What is the opportunity cost of seeing a movie?

Answered: 1 week ago

Question

=+ what roles should government play in them ?

Answered: 1 week ago

Question

=+ Why do we have markets and, according to economists,

Answered: 1 week ago