Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3. There are some situations where we are asked to sort data that is almost sorted. A k- sorted array contains no element that is
3. There are some situations where we are asked to sort data that is almost sorted. A k- sorted array contains no element that is more than k positions from its position in the properly sorted array. For the questions below, A is a k-sorted array with k A[j], then the pair (i,j) is called an inversion of A. What permutation of the array {1, 2, ..., n} has the most inversions? How many does it have? b. Give the list of [2,5, 1, 6, 3, 4], what is its number of inversions? What is the number of inversions in its reverse? c. Show that, if A is k-sorted, Insertion-Sort runs in time O(nk). Hint: First, show that INSERTION-SORT(A) runs in time O(n+I), where I is the number of inversions in A. d. What are the runtimes of Merge-Sort and Quicksort on a k-sorted array A? Explain your answers. e. (extra credit) Devise an algorithm that performs better than the above algorithms for sorting a k-sorted array
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