Docsity

CS1510 HW7: Counting Inversions & Finding Median in Sorted Lists, Assignments of Computer Science

Toggle sidebar
bg1
CS1510 Design and Analysis of Algorithms, Fall 2006
Homework 7. Assigned on Wed Oct 25th, 2006. Due in class on Wed Nov 1st, 2006.
1. Consider the following counting-significant-inversions problem. The input to this problem
is a sequence of n positive numbers a1, a2, …,an, which we assume are all distinct. A pair is a
significant inversion if i<j and ai > 2aj. The goal is to count the number of significant
inversions. Give an O(n log n) algorithm to solve this problem. Explain why it is correct and
explain why its running time is O(n log n).
2. Consider the following finding-median-of-2-sorted-lists problem. The input to this
problem are 2 sorted lists of length n: a1 < a2 < … < an and b1 < b2 < … < bn, which we
assume are all distinct. The goal is to find the median of these 2n values, which we define to
be the n’th smallest value. Give and O(log n) algorithm to solve this problem. Explain why
it is correct and why its running time is O(log n).
1

Partial preview of the text

Download CS1510 HW7: Counting Inversions & Finding Median in Sorted Lists and more Assignments Computer Science in PDF only on Docsity!

CS1510 Design and Analysis of Algorithms, Fall 2006 Homework 7. Assigned on Wed Oct 25th, 2006. Due in class on Wed Nov 1st, 2006.

  1. Consider the following counting-significant-inversions problem. The input to this problem is a sequence of n positive numbers a 1 , a 2 , …, an , which we assume are all distinct. A pair is a significant inversion if i < j and ai > 2 aj. The goal is to count the number of significant inversions. Give an O(n log n) algorithm to solve this problem. Explain why it is correct and explain why its running time is O(n log n).
  2. Consider the following finding-median-of-2-sorted-lists problem. The input to this problem are 2 sorted lists of length n : a 1 < a 2 < … < an and b 1 < b 2 < … < bn , which we assume are all distinct. The goal is to find the median of these 2 n values, which we define to be the n ’th smallest value. Give and O(log n) algorithm to solve this problem. Explain why it is correct and why its running time is O(log n). 1