Algorithms and Complexity: Quickselect, Strassen's Algorithm, and Skyline Problem, Study notes of Computer Science

Lecture notes from cot 5405, a course on the design and analysis of algorithms. The notes cover three topics: quickselect (a selection algorithm), strassen's algorithm (for matrix multiplication), and the skyline problem (a divide-and-conquer algorithm application). Explanations, examples, and analyses of the algorithms' time complexities.

Typology: Study notes

Pre 2010

Uploaded on 02/24/2010

koofers-user-l4g-1
koofers-user-l4g-1 🇺🇸

9 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COT 5405 Design and Analysis of Algorithms
Instructor Mr. Arup Guha
Fall 2003
Lecture 14 October 16, 2003
Note-Takers: Xingbo Gao, Yun Fan
Topics:
1. Quickselect (select kth smallest item out of n elements)
2. Strassen’s algorithm
3. Skyline problem
Quickselect
We are looking for the 7th smallest value from the following 9 numbers:
12, 3, 2, 15, 8, 9, 6, 11, 7 - 9 values
3, 2, 6, 7, 12, 15, 8, 9, 11 - partition
We first choose a random partition number 7 and do a partition, all elements
smaller than 7 are put at its left and all others having larger values are put at
its right. From the partition result, we can see the number 7 is at the position
of 4th smallest value. Our problem that is looking for the 7th smallest value
now becomes a new one ––– looking for the 3rd smallest value from the
remaining list at the right of the number 7.
Here is more formal description of Quickselect algorithm:
Quickselect ( A, K, low, high )
A: the elements to be chosen from
K: the Kth smallest value we are looking for from A
low: the lower bound of A
high: the higher bound of A
1
pf3
pf4
pf5

Partial preview of the text

Download Algorithms and Complexity: Quickselect, Strassen's Algorithm, and Skyline Problem and more Study notes Computer Science in PDF only on Docsity!

COT 5405 Design and Analysis of Algorithms

Instructor Mr. Arup Guha

Fall 2003

Lecture 14 October 16, 2003

Note-Takers: Xingbo Gao, Yun Fan

Topics:

  1. Quickselect (select kth^ smallest item out of n elements)
  2. Strassen’s algorithm
  3. Skyline problem

Quickselect

We are looking for the 7th^ smallest value from the following 9 numbers: 12, 3, 2, 15, 8, 9, 6, 11, 7 - 9 values 3, 2, 6, 7 , 12, 15, 8, 9, 11 - partition We first choose a random partition number 7 and do a partition, all elements smaller than 7 are put at its left and all others having larger values are put at its right. From the partition result, we can see the number 7 is at the position of 4th^ smallest value. Our problem that is looking for the 7th^ smallest value now becomes a new one ––– looking for the 3rd^ smallest value from the remaining list at the right of the number 7. Here is more formal description of Quickselect algorithm: Quickselect ( A, K, low, high ) A: the elements to be chosen from K: the Kth smallest value we are looking for from A low: the lower bound of A high: the higher bound of A

int part = Partition ( A, low, high ) if ( K <= part ) Quickselect ( A, K, low, part-1 ); if ( K == part ) return A[part]; if ( K > part + 1 ) Quickselect ( A, k-part-1, part+1, high ); } Homework#9 : Do Average Case Executing Time Analysis for Quickselect

- O(n). Best case analysis: partition in the middle of the array T(n) = T(n/2) + O(n) Plug in a=1, b=2, k= logb a = 0, k=1 → T(n) = O(n) Worst case analysis: T( n ) = T(n-1) + O(n) O(c(1+2+3+…+n)) T(n-1) = T(n-2) + O(n-1) ║ T(n-2) = T(n-3) + O(n-2) O(c ·n(n+1)/2) … ║ O(n 2 ) T(2) = T( 1 ) + O(2) ↓↓↓ T(n) = T(1) + O(n^2 ) → T(n) = O(n^2 )

Strassen’s algorithm▬▬▬Matrix multiplication

The standard method of matrix multiplication of two n x n matrices takes T(n) = O(n 3 ).

T(n) = 7T(n/2) + O(n^2 ) ↓ 6 times as much as in the other algorithm

Skyline problem ——Divide-and-Conquer algorithm application

You are to design a program to assist an architect in drawing the skyline of a city given the locations of the buildings in the city. To make the problem tractable, all buildings are rectangular in shape and they share a common bottom (the city they are built in is very flat). The city is also viewed as two- dimensional. A building is specified by an ordered triple where and are left and right coordinates, respectively, of building i and is the height of the building. In the diagram below buildings are shown on the left with triples (1,11,5), (2,6,7), (3,13,9), (12,7,16), (14,3,25), (19,18,22), (23,13,29), (24,4,28) the skyline, shown on the right, is represented by the sequence: (1, 11, 3, 13, 9, 0, 12, 7, 16, 3, 19, 18, 22, 3, 23, 13, 29, 0) You need to Merge two skylines——similar to the merge sort

For instance: there are two skylines, Skyline A: a 1 , h 11 , a 2 , h 12 , a 3 , h 13 , …, an, 0 Skyline B: b 1 , h 21 , b 2 , h 22 , b 3 , h 23 , …, bm, 0 merge ( list of a’s, list of b’s) form into (c 1 , h 11 , c 2 , h 21 , c 3 , …, cn+m, 0) Skyline problem algorithm should take a time of T(n) = 2T(n/2) + O(n)