1. Trang chủ
  2. » Giáo án - Bài giảng

24 1 quick sort proof tủ tài liệu training pdf

16 48 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 16
Dung lượng 1,88 MB

Nội dung

QuickSort Analysis I: A Decomposition Principle Design and Analysis of Algorithms I Nextcore AI Gopal Shangari Preliminaries Fix input array A of length n Sample Space = all possible outcomes of random choices in QuickSort (i.e., pivot sequencesti Key Random Variable : for = # of comparisons between two input elements made by QuickSort (given random choices ti Lemma: running 8me of QuickSort dominated by comparisons Remaining goal : E[C] = O(nlog(ntiti There exist constant c s.t for all , (see Nextcore AI Gopal Shangari notesti Nextcore AI Gopal Shangari Te ve Fix two elements of the input array How many 8mes can these two elements get compared with each other during the execu8on of QuickSort? Reason : two elements compared only when one is the pivot, which is excluded from future recursive calls or 0, 1, or Thus : each Xij is an “indicator” (i.e., 0-‐1ti random variable So : = # of comparisons between input elements = # of comparisons between zi and zj Thus : By Linearity of Expecta8on : Since Thus : Nextcore AI Gopal Shangari Iden8fy random variable Y that you really care about Express Y as sum of indicator random variables : Apply Linearity of expecta8on : “just” need to understand these! Nextcore AI Gopal Shangari QuickSort Design and Analysis of Algorithms I Analysis II: The Key Insight Nextcore AI Gopal Shangari Nextcore AI Gopal Shangari Fix zi, zj with i < j Consider the set zi,zi+1,…,zj-‐1,zj Nextcore AI Gopal Shangari zi or zj gets chosen first => they get compared one of zi+1,…,zj-‐1 gets chosen first => zi , zj never compared Note : Since pivots always chosen uniformly at random, each of zi,zi+1,…,zj-‐1,zj is equally likely to be the first Pr[zi,zj get compared ] So : = 2/(j-‐i+1ti Choices that lead to case (1ti Total # of choices [S@ll need to show this is O(nlog(ntiti Nextcore AI Gopal Shangari QuickSort Design and Analysis of Algorithms I Analysis III: Final Calculations Nextcore AI Gopal Shangari How big can this be ?

Ngày đăng: 17/11/2019, 07:34