Question
Let A[1..n] be an array of n distinct real numbers. A pair (A[i],A[j]) is said to be an inversion if i < j but A[i]
Let A[1..n] be an array of n distinct real numbers. A pair (A[i],A[j]) is said to be an inversion if i < j but A[i] > A[j].
(a) Suppose we exchange elements A[i] and A[i+k] in an array, which were originally out of order. Find out how many inversions can be removed. You need to give a lower bound and an upper bound and show why;
(b) Design an O(n logn) algorithm for counting the number of inversions in A[1..n]. This means that you need to design an algorithm and show why it takes the specied time.
PLEASE SHOW FULL STEPS SHOW THINKING PLEASE AND THANK YOU! AND ANSWER A AND B SEPERATELY!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started