1 / 8

QuickSort

QuickSort. Divide : A [ p…r ] bos olmayan iki alt diziye bolunur, A [ p…q ] ve A [ q+1…r ] s.t. oyleki A [ p…q ] nin her bir elemani A [ q+1…r ] . Nin herbir elemanindan kucuk veya kucuk esit. Conquer : iki alt dizi quicksort e recursive cagrimla siralanir

baldwin
Download Presentation

QuickSort

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. QuickSort • Divide: A[p…r] bos olmayan iki alt diziye bolunur, A[p…q] ve A[q+1…r] s.t. oyleki A[p…q] nin her bir elemani A[q+1…r]. Nin herbir elemanindan kucuk veya kucuk esit. • Conquer: iki alt dizi quicksort e recursive cagrimla siralanir • Combine: herhangi bir islem yapilmaz cunku alt diziler kendi aralarinda zaten sirali Algoritma Analizi

  2. Quicksort (A, p, r) 1. if p < r 2. then qPartition(A, p, r) 3. Quicksort(A, p, q) 4. Quicksort(A, q+1, r) * In place, not stable Algoritma Analizi

  3. Partition(A, p, r) 1. x  A[p] 2. i  p - 1 3. j  r + 1 4. while TRUE do 5. repeat j  j - 1 6. untilA[j]  x 7.repeat i i + 1 8. untilA[i]  x 9. if i < j 10. then exchange A[i]  A[j] 11. else return j Algoritma Analizi

  4. Example: Partitioning Array Algoritma Analizi

  5. Algorithm Analysis Quicksort un calisma zamani partition (bolumleme) nin balanced (dengeli) olup olmadigina baglidir • Worst-Case Performance (unbalanced): T(n) = T(1) + T(n-1) + (n)  partitioning takes (n) = k = 1 to n(k)  T(1) takes (1) time & reiterate =  (  k = 1 to nk ) = (n2) * This occurs when the input is completely sorted. Algoritma Analizi

  6. Worst Case Partitioning Algoritma Analizi

  7. Best Case Partitioning Algoritma Analizi

  8. Analysis for Best Case Partition • Eger her tefasinda balanced partition elde edersek (alt diziler n/2 boyunda), en iyi performansi elde etmis oluruz. T(n) = 2T(n/2) + (n) T(n) = (nlog n) Algoritma Analizi

More Related